Mercurial > hg > egg-tcls
diff create_quotedb.tcl @ 502:1255d524a919
Fix create_*.tcl database creation scripts after long period of being broken.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 23 Jan 2020 08:01:40 +0200 |
parents | 416642f28d1e |
children |
line wrap: on
line diff
--- a/create_quotedb.tcl Thu Jan 23 06:14:06 2020 +0200 +++ b/create_quotedb.tcl Thu Jan 23 08:01:40 2020 +0200 @@ -7,47 +7,23 @@ package require sqlite3 source [file dirname [info script]]/utillib.tcl -set db_list {quotedb} +set db_create_desc "Creates tables for QuoteDB in target SQLite3 file" +set db_table_list {quotedb} + -### Check commandline arguments -set db_str [join $db_list ", "] -if {$argc < 1} { - puts "Creates tables for QuoteDB in target SQLite3 file" - puts "Usage: $argv0 <output_sqlite3_db_file> \[-drop\]" - puts "" - puts "-drop option will drop any existing '$db_str' table of same name." - exit 0 -} - -set db_drop 0 -set db_output [lindex $argv 0] -if {$argc >= 2 && [lindex $argv 1] == "-drop"} { - set db_drop 1 +proc db_create_table { dbh utable } { + utl_create_table_or_fail dbh "$utable" "id INTEGER PRIMARY KEY AUTOINCREMENT, utime INT, utext VARCHAR(2048), user VARCHAR(32), host VARCHAR(256), chan VARCHAR(32)" + utl_create_table_or_fail dbh "${utable}_votes" "id INTEGER PRIMARY KEY AUTOINCREMENT, user VARCHAR(32), urlid INTEGER, vote INTEGER" } -### Open database -open_db $db_output - -if {$db_drop} { - puts "WARNING! Dropping of old table(s) '$db_str' requested!" - puts "All data in those tables will be permanently lost!" - - if {![confirm_yesno "Proceed"]} { - puts "Aborting procedure." - dbh close - exit 0 - } - - foreach i $db_list { - drop_table $i - } +proc db_drop_table { dbh utable } { + utl_drop_table dbh "$utable" + utl_drop_table dbh "${utable}_votes" } -puts "Creating tables $db_str ..." -foreach i $db_list { - create_table_quotes_votes $i 0 +proc db_get_table_list { utable } { + return [list "$utable" "${utable}_votes"] } -dbh close -puts "DONE." +source [file dirname [info script]]/utilcreate.tcl