Commit 25/09/2025
This commit is contained in:
@@ -82,6 +82,16 @@ class MariaDB(
|
||||
|
||||
runBlocking {
|
||||
withContext(Dispatchers.IO) {
|
||||
Create_Log_Table()
|
||||
Create_SoundChannel_Table()
|
||||
Create_Schedulebank_Table()
|
||||
Create_BroadcastZones_Table()
|
||||
Create_Messagebank_Table()
|
||||
Create_Soundbank_Table()
|
||||
Create_LanguageLink_Table()
|
||||
Create_Queue_Table()
|
||||
Create_Queue_Paging_Table()
|
||||
|
||||
Reload_Messagebank()
|
||||
Reload_Soundbank()
|
||||
Reload_LanguageLink()
|
||||
@@ -121,6 +131,27 @@ class MariaDB(
|
||||
connected = false
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Log table if not exists
|
||||
*/
|
||||
fun Create_Log_Table() {
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
statement?.executeUpdate(
|
||||
"CREATE TABLE IF NOT EXISTS logs (" +
|
||||
"`index` INT AUTO_INCREMENT PRIMARY KEY," +
|
||||
"datenya VARCHAR(20) NOT NULL," + // format DD/MM/YYYY
|
||||
"timenya VARCHAR(20) NOT NULL," + // format HH:MM:SS
|
||||
"machine VARCHAR(45) NOT NULL," +
|
||||
"description TEXT NOT NULL" +
|
||||
")"
|
||||
)
|
||||
Logger.info("Log table ensured to exist" as Any)
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error creating log table: ${e.message}" as Any)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Log to database
|
||||
* @param machine The machine name or identifier.
|
||||
@@ -198,6 +229,34 @@ class MariaDB(
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Create SoundChannel table if not exists
|
||||
*/
|
||||
fun Create_SoundChannel_Table() {
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
statement?.executeUpdate(
|
||||
"CREATE TABLE IF NOT EXISTS soundchannel (" +
|
||||
"`index` INT AUTO_INCREMENT PRIMARY KEY," +
|
||||
"channel VARCHAR(45) NOT NULL," + // Channel 01 to Channel 64
|
||||
"ip VARCHAR(45) NOT NULL" + // IP address or empty string
|
||||
")"
|
||||
)
|
||||
Logger.info("SoundChannel table ensured to exist" as Any)
|
||||
// Check if table is empty, if so, populate with 64 channels
|
||||
val countResult = statement?.executeQuery("SELECT COUNT(*) AS count FROM soundchannel")
|
||||
if (countResult?.next() == true) {
|
||||
val count = countResult.getInt("count")
|
||||
if (count == 0) {
|
||||
Logger.info("SoundChannel table is empty, populating with default channels" as Any)
|
||||
Clear_SoundChannel()
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error creating SoundChannel table: ${e.message}" as Any)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all entries from the soundchannel table in the database and the local list.
|
||||
*/
|
||||
@@ -509,6 +568,31 @@ class MariaDB(
|
||||
consumer.accept(logList)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Schedulebank table if not exists
|
||||
*/
|
||||
fun Create_Schedulebank_Table() {
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
statement?.executeUpdate(
|
||||
"CREATE TABLE IF NOT EXISTS schedulebank (" +
|
||||
"`index` INT AUTO_INCREMENT PRIMARY KEY," +
|
||||
"Description VARCHAR(128) NOT NULL," + // Description of the schedule
|
||||
"Day VARCHAR(255) NOT NULL," + // Day in format DD/MM/YYYY
|
||||
"Time VARCHAR(20) NOT NULL," + // Time in format HH:MM:SS
|
||||
"Soundpath VARCHAR(512) NOT NULL," + // Path to the sound file
|
||||
"Repeat TINYINT UNSIGNED NOT NULL," + // Repeat type (0=Once, 1=Daily, 2=Weekly, 3=Monthly, 4=Yearly)
|
||||
"Enable BOOLEAN NOT NULL," + // Enable or disable the schedule
|
||||
"BroadcastZones TEXT NOT NULL," + // Comma-separated list of broadcast zones
|
||||
"Language VARCHAR(45) NOT NULL" + // Language code (e.g., EN, FR)
|
||||
")"
|
||||
)
|
||||
Logger.info("Schedulebank table ensured to exist" as Any)
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error creating Schedulebank table: ${e.message}" as Any)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the ScheduleBank list from the database.
|
||||
*/
|
||||
@@ -815,6 +899,25 @@ class MariaDB(
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Create LanguageLink table if not exists
|
||||
*/
|
||||
fun Create_LanguageLink_Table() {
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
statement?.executeUpdate(
|
||||
"CREATE TABLE IF NOT EXISTS languagelinking (" +
|
||||
"`index` INT AUTO_INCREMENT PRIMARY KEY," +
|
||||
"TAG VARCHAR(45) NOT NULL," + // Language tag (e.g., EN, FR)
|
||||
"Language VARCHAR(128) NOT NULL" + // Full language name (e.g., English, French)
|
||||
")"
|
||||
)
|
||||
Logger.info("LanguageLink table ensured to exist" as Any)
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error creating LanguageLink table: ${e.message}" as Any)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the language link list from the database.
|
||||
*/
|
||||
@@ -1043,6 +1146,29 @@ class MariaDB(
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Soundbank table if not exists
|
||||
*/
|
||||
fun Create_Soundbank_Table() {
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
statement?.executeUpdate(
|
||||
"CREATE TABLE IF NOT EXISTS soundbank (" +
|
||||
"`index` INT AUTO_INCREMENT PRIMARY KEY," +
|
||||
"Description VARCHAR(1024) NOT NULL," + // Description of the soundbank
|
||||
"TAG VARCHAR(45) NOT NULL," + // TAG of the soundbank
|
||||
"Category VARCHAR(45) NOT NULL," + // Category of the soundbank
|
||||
"Language VARCHAR(45) NOT NULL," + // Language of the soundbank
|
||||
"VoiceType VARCHAR(45) NOT NULL," + // VoiceType of the soundbank
|
||||
"Path VARCHAR(1024) NOT NULL" + // Path to the sound file
|
||||
")"
|
||||
)
|
||||
Logger.info("Soundbank table ensured to exist" as Any)
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error creating Soundbank table: ${e.message}" as Any)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the soundbank list from the database.
|
||||
*/
|
||||
@@ -1321,6 +1447,29 @@ class MariaDB(
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Messagebank table if not exists
|
||||
*/
|
||||
fun Create_Messagebank_Table() {
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
statement?.executeUpdate(
|
||||
"CREATE TABLE IF NOT EXISTS messagebank (" +
|
||||
"`index` INT AUTO_INCREMENT PRIMARY KEY," +
|
||||
"Description VARCHAR(512) NOT NULL," + // Description of the message
|
||||
"Language VARCHAR(45) NOT NULL," + // Language of the message
|
||||
"ANN_ID INT NOT NULL," + // ANN ID of the message
|
||||
"Voice_Type VARCHAR(45) NOT NULL," + // Voice type of the message
|
||||
"Message_Detail VARCHAR(1024) NOT NULL," + // Full message text
|
||||
"Message_TAGS VARCHAR(1024)" + // Comma-separated tags for the message
|
||||
")"
|
||||
)
|
||||
Logger.info("Messagebank table ensured to exist" as Any)
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error creating Messagebank table: ${e.message}" as Any)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the messagebank list from the database.
|
||||
*/
|
||||
@@ -1575,6 +1724,31 @@ class MariaDB(
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Queue table if not exists
|
||||
*/
|
||||
fun Create_Queue_Table() {
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
statement?.executeUpdate(
|
||||
"CREATE TABLE IF NOT EXISTS queue_table (" +
|
||||
"`index` INT AUTO_INCREMENT PRIMARY KEY," +
|
||||
"Date_Time VARCHAR(45) NOT NULL," + // Date and time of the entry
|
||||
"Source VARCHAR(45) NOT NULL," + // Source of the entry
|
||||
"Type VARCHAR(45) NOT NULL," + // Type of the entry
|
||||
"Message VARCHAR(1024) NOT NULL," + // Message content
|
||||
"SB_TAGS VARCHAR(1024)," + // Comma-separated soundbank tags
|
||||
"BroadcastZones VARCHAR(1024) NOT NULL," + // Comma-separated broadcast zones
|
||||
"Repeat INT NOT NULL," + // Number of repeats
|
||||
"Language VARCHAR(45) NOT NULL" + // Language of the message
|
||||
")"
|
||||
)
|
||||
Logger.info("Queue table ensured to exist" as Any)
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error creating Queue table: ${e.message}" as Any)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads all entries from the queue_table in the database.
|
||||
* @return A list of QueueTable entries.
|
||||
@@ -1669,6 +1843,28 @@ class MariaDB(
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Queue paging table if not exists
|
||||
*/
|
||||
fun Create_Queue_Paging_Table() {
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
statement?.executeUpdate(
|
||||
"CREATE TABLE IF NOT EXISTS queue_paging (" +
|
||||
"`index` INT AUTO_INCREMENT PRIMARY KEY," +
|
||||
"Date_Time VARCHAR(45) NOT NULL," + // Date and time of the entry
|
||||
"Source VARCHAR(45) NOT NULL," + // Source of the entry
|
||||
"Type VARCHAR(45) NOT NULL," + // Type of the entry
|
||||
"Message VARCHAR(512) NOT NULL," + // Message content
|
||||
"BroadcastZones VARCHAR(1024)" + // Comma-separated soundbank tags
|
||||
")"
|
||||
)
|
||||
Logger.info("Queue paging table ensured to exist" as Any)
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error creating Queue paging table: ${e.message}" as Any)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads all entries from the queue_paging in the database.
|
||||
* @return A list of QueuePaging entries.
|
||||
@@ -1784,6 +1980,27 @@ class MariaDB(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create BroadcastZones table if not exists
|
||||
*/
|
||||
fun Create_BroadcastZones_Table() {
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
statement?.executeUpdate(
|
||||
"CREATE TABLE IF NOT EXISTS broadcastzones (" +
|
||||
"`index` INT AUTO_INCREMENT PRIMARY KEY," +
|
||||
"description VARCHAR(512) NOT NULL," + // Description of the broadcast zone
|
||||
"SoundChannel VARCHAR(45) NOT NULL," + // Sound channel of the broadcast zone
|
||||
"Box VARCHAR(45) NOT NULL," + // Box of the broadcast zone
|
||||
"Relay VARCHAR(45) NOT NULL" + // Relay of the broadcast zone
|
||||
")"
|
||||
)
|
||||
Logger.info("Broadcast zones table ensured to exist" as Any)
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error creating broadcast zones table: ${e.message}" as Any)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new broadcast_zones entry to the database.
|
||||
* @param broadcastZones The BroadcastZones object to add.
|
||||
|
||||
Reference in New Issue
Block a user