commit 24/09/2025
This commit is contained in:
@@ -36,6 +36,8 @@ class MariaDB(
|
||||
var SchedulebankList: ArrayList<ScheduleBank> = ArrayList()
|
||||
var BroadcastZoneList: ArrayList<BroadcastZones> = ArrayList()
|
||||
var SoundChannelList: ArrayList<SoundChannel> = ArrayList()
|
||||
var QueuePagingList: ArrayList<QueuePaging> = ArrayList()
|
||||
var QueueTableList: ArrayList<QueueTable> = ArrayList()
|
||||
|
||||
companion object {
|
||||
fun ValidDate(date: String): Boolean {
|
||||
@@ -1578,6 +1580,7 @@ class MariaDB(
|
||||
* @return A list of QueueTable entries.
|
||||
*/
|
||||
fun Read_Queue_Table(): ArrayList<QueueTable> {
|
||||
QueueTableList.clear()
|
||||
val queueList = ArrayList<QueueTable>()
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
@@ -1595,6 +1598,7 @@ class MariaDB(
|
||||
resultSet.getString("Language")
|
||||
)
|
||||
queueList.add(queueTable)
|
||||
QueueTableList.add(queueTable)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error fetching queue table: ${e.message}" as Any)
|
||||
@@ -1614,6 +1618,7 @@ class MariaDB(
|
||||
val rowsAffected = statement?.executeUpdate()
|
||||
if (rowsAffected != null && rowsAffected > 0) {
|
||||
Logger.info("Deleted $rowsAffected row(s) from queue_table with index $index" as Any)
|
||||
Resort_Queue_Table_by_Index()
|
||||
return true
|
||||
} else {
|
||||
Logger.warn("No rows deleted from queue_table with index $index" as Any)
|
||||
@@ -1624,10 +1629,34 @@ class MariaDB(
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Resort the queue_table table, in order to reorder the index after deletions, and sort ascending by index.
|
||||
* @return True if the resorting was successful, false otherwise.
|
||||
*/
|
||||
fun Resort_Queue_Table_by_Index(): Boolean {
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
// use a temporary table to reorder the index
|
||||
statement?.executeUpdate("CREATE TABLE IF NOT EXISTS temp_queue_table LIKE queue_table")
|
||||
statement?.executeUpdate("INSERT INTO temp_queue_table (Date_Time, Source, Type, Message, SB_TAGS, BroadcastZones, Repeat, Language) SELECT Date_Time, Source, Type, Message, SB_TAGS, BroadcastZones, Repeat, Language FROM queue_table ORDER BY `index` ASC")
|
||||
statement?.executeUpdate("TRUNCATE TABLE queue_table")
|
||||
statement?.executeUpdate("INSERT INTO queue_table (Date_Time, Source, Type, Message, SB_TAGS, BroadcastZones, Repeat, Language) SELECT Date_Time, Source, Type, Message, SB_TAGS, BroadcastZones, Repeat, Language FROM temp_queue_table")
|
||||
statement?.executeUpdate("DROP TABLE temp_queue_table")
|
||||
Logger.info("queue_table table resorted by index" as Any)
|
||||
// reload the local list
|
||||
Read_Queue_Table()
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error resorting queue_table table by index: ${e.message}" as Any)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all entries from the queue_table in the database.
|
||||
*/
|
||||
fun Clear_Queue_Table(): Boolean {
|
||||
QueueTableList.clear()
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
// use TRUNCATE to reset auto increment index
|
||||
@@ -1645,6 +1674,7 @@ class MariaDB(
|
||||
* @return A list of QueuePaging entries.
|
||||
*/
|
||||
fun Read_Queue_Paging(): ArrayList<QueuePaging> {
|
||||
QueuePagingList.clear()
|
||||
val queueList = ArrayList<QueuePaging>()
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
@@ -1659,6 +1689,7 @@ class MariaDB(
|
||||
resultSet.getString("SB_TAGS"),
|
||||
)
|
||||
queueList.add(queuePaging)
|
||||
QueuePagingList.add(queuePaging)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error fetching queue paging: ${e.message}" as Any)
|
||||
@@ -1678,6 +1709,7 @@ class MariaDB(
|
||||
val rowsAffected = statement?.executeUpdate()
|
||||
if (rowsAffected != null && rowsAffected > 0) {
|
||||
Logger.info("Deleted $rowsAffected row(s) from queue_paging with index $index" as Any)
|
||||
Resort_Queue_Paging_by_Index()
|
||||
return true
|
||||
} else {
|
||||
Logger.warn("No rows deleted from queue_paging with index $index" as Any)
|
||||
@@ -1688,10 +1720,34 @@ class MariaDB(
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Resort the queue_paging table, in order to reorder the index after deletions, and sort ascending by index.
|
||||
* @return True if the resorting was successful, false otherwise.
|
||||
*/
|
||||
fun Resort_Queue_Paging_by_Index(): Boolean {
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
// use a temporary table to reorder the index
|
||||
statement?.executeUpdate("CREATE TABLE IF NOT EXISTS temp_queue_paging LIKE queue_paging")
|
||||
statement?.executeUpdate("INSERT INTO temp_queue_paging (Date_Time, Source, Type, Message, SB_TAGS) SELECT Date_Time, Source, Type, Message, SB_TAGS FROM queue_paging ORDER BY `index` ASC")
|
||||
statement?.executeUpdate("TRUNCATE TABLE queue_paging")
|
||||
statement?.executeUpdate("INSERT INTO queue_paging (Date_Time, Source, Type, Message, SB_TAGS) SELECT Date_Time, Source, Type, Message, SB_TAGS FROM temp_queue_paging")
|
||||
statement?.executeUpdate("DROP TABLE temp_queue_paging")
|
||||
Logger.info("queue_paging table resorted by index" as Any)
|
||||
// reload the local list
|
||||
Read_Queue_Paging()
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error resorting queue_paging table by index: ${e.message}" as Any)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all entries from the queue_paging in the database.
|
||||
*/
|
||||
fun Clear_Queue_Paging(): Boolean {
|
||||
QueuePagingList.clear()
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
// use TRUNCATE to reset auto increment index
|
||||
|
||||
Reference in New Issue
Block a user