annotate utillib.tcl @ 295:141bb4a2b76f

utillib: utl_escape (which will be deprecated soon).
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 26 Jan 2015 14:07:16 +0200
parents cad1041b5bc4
children d56509a6f435
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
290
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
1 ##########################################################################
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
2 #
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
3 # TCL functions library by Matti 'ccr' Hamalainen <ccr@tnsp.org>
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
4 # (C) Copyright 2015 Tecnic Software productions (TNSP)
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
5 #
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
6 # This script is freely distributable under GNU GPL (version 2) license.
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
7 #
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
8 ##########################################################################
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
9
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
10 set utl_html_ent_str "&#45;|-|&#39;|'|—|-|&rlm;||&#8212;|-|&#8211;|--|&#x202a;||&#x202c;|"
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
11 append utl_html_ent_str "|&lrm;||&aring;|å|&Aring;|Å|&eacute;|é|&#58;|:|&nbsp;| "
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
12 append utl_html_ent_str "|&#8221;|\"|&#8220;|\"|&laquo;|<<|&raquo;|>>|&quot;|\""
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
13 append utl_html_ent_str "|&auml;|ä|&ouml;|ö|&Auml;|Ä|&Ouml;|Ö|&amp;|&|&lt;|<|&gt;|>"
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
14 append utl_html_ent_str "|&#228;|ä|&#229;|ö|&mdash;|-|&#039;|'|&ndash;|-|&#034;|\""
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
15 append utl_html_ent_str "|&#124;|-|&#8217;|'|&uuml;|ü|&Uuml;|Ü|&bull;|*|&euro;|€"
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
16 append utl_html_ent_str "|&rdquo;|\"|&#8216;|'"
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
17 set utl_html_ent_list [split [encoding convertfrom "utf-8" $utl_html_ent_str] "|"]
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
18
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
19
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
20 proc utl_convert_html_ent {udata} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
21 global utl_html_ent_list
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
22 return [string map -nocase $utl_html_ent_list [string map $utl_html_ent_list $udata]]
31
1ddfada536ff Add utility "library" for database conversion and creation scripts.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 }
1ddfada536ff Add utility "library" for database conversion and creation scripts.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
290
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
25
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
26 proc utl_str_split {str maxlen} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
27 set pos 0
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
28 set len [string length $str]
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
29 set ulen 0
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
30 set ustr ""
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
31 set result {}
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
32 while {$pos < $len} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
33 set end [string wordend $str $pos]
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
34 set new [expr $end - $pos + 1]
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
35 if {$ulen + $new < $maxlen} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
36 append ustr [string range $str $pos $end]
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
37 set ulen [expr $ulen + $new]
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
38 } else {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
39 append ustr [string range $str $pos $end]
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
40 lappend result $ustr
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
41 set ustr ""
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
42 set ulen 0
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
43 }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
44 set pos [expr $end + 1]
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
45 }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
46 if {$ustr != ""} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
47 lappend result $ustr
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
48 }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
49 return $result
31
1ddfada536ff Add utility "library" for database conversion and creation scripts.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 }
1ddfada536ff Add utility "library" for database conversion and creation scripts.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
1ddfada536ff Add utility "library" for database conversion and creation scripts.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
290
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
53 ###
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
54 ### SQL database handling
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
55 ###
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
56 proc utl_tdbc_sql_init {ndb_handle db_type db_name db_host db_port db_user db_pass} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
57 upvar $ndb_handle udb_handle
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
58
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
59 if {$db_type == "sqlite"} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
60 if {$db_name == ""} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
61 putlog " SQLite3 database file not set."
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
62 return 0
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
63 }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
64 if {![file exists $db_name]} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
65 putlog " URLLog SQLite3 database file '$db_name' not found, or not accessible!"
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
66 return 0
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
67 }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
68 package require tdbc::sqlite3 1.0
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
69 if {[catch {tdbc::sqlite3::connection create db_handle $db_name} db_errmsg]} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
70 putlog " Could not open SQLite3 database '$db_name': $db_errmsg"
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
71 return 0
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
72 }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
73 putlog " (Using SQLite3 database $db_name)"
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
74 } elseif {$db_type == "postgres" || $db_type == "mysql"} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
75 # Check parameters
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
76 set db_args {}
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
77 if {$db_user != ""} { lappend db_args -user $db_user }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
78 if {$db_pass != ""} { lappend db_args -passwd $db_pass }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
79 if {$db_host != ""} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
80 lappend db_args -host $db_pass
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
81 if {$db_posrt != 0} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
82 lappend db_args -port $db_port
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
83 set db_host "${db_host}:${db_port}"
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
84 }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
85 } else {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
86 set db_host "localhost"
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
87 }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
88 if {$db_name == ""} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
89 putlog " Database name not set."
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
90 return 0
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
91 }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
92 lappend db_args -database $db_name
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
93
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
94 if {$db_type == "postgres"} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
95 package require tdbc::postgres 1.0
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
96 if {[catch {tdbc::postgres::connection create db_handle {*}$db_args} db_errmsg]} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
97 putlog " Could not connect to PostgreSQL database '$db_name @ $db_host': $db_errmsg"
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
98 return 0
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
99 }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
100 putlog " (Using PostgreSQL database $db_name @ $db_host)"
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
101 } elseif {$db_type == "mysql"} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
102 package require tdbc::mysql 1.0
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
103 if {[catch {tdbc::mysql::connection create db_handle {*}$db_args} db_errmsg]} {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
104 putlog " Could not connect to MySQL database '$db_name @ $db_host': $db_errmsg"
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
105 return 0
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
106 }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
107 putlog " (Using MySQL database $db_name @ $db_host)"
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
108 }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
109 } else {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
110 putlog " Invalid or unsupported database type: '$db_type'."
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
111 return 0
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
112 }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
113 set udb_handle db_handle
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
114 return 1
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
115 }
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
116
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
117
295
141bb4a2b76f utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents: 290
diff changeset
118 proc utl_escape {str} {
141bb4a2b76f utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents: 290
diff changeset
119 return [string map {' ''} $str]
141bb4a2b76f utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents: 290
diff changeset
120 }
141bb4a2b76f utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents: 290
diff changeset
121
141bb4a2b76f utillib: utl_escape (which will be deprecated soon).
Matti Hamalainen <ccr@tnsp.org>
parents: 290
diff changeset
122
290
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
123 ###
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
124 ### Functions for certain scripts
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
125 ###
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
126 proc utl_confirm_yesno { uprompt } {
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
127 puts -nonewline "$uprompt \[y/N\]? "
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
128 flush stdout
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
129 set response [gets stdin]
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
130 if {[string tolower $response] == "y"} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
131 return 1
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
132 } else {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
133 return 0
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
134 }
31
1ddfada536ff Add utility "library" for database conversion and creation scripts.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 }
1ddfada536ff Add utility "library" for database conversion and creation scripts.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136
1ddfada536ff Add utility "library" for database conversion and creation scripts.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
290
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
138 proc utl_drop_table { dbh utable } {
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
139 puts "Dropping current table '$utable'."
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
140 if {[catch {dbh eval "DROP TABLE $utable"} uerrmsg]} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
141 puts "Dropping table resulted in error (ignored): $uerrmsg."
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
142 }
31
1ddfada536ff Add utility "library" for database conversion and creation scripts.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 }
1ddfada536ff Add utility "library" for database conversion and creation scripts.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144
290
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
145
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
146 proc utl_create_table { dbh utable usql } {
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
147 puts "Creating new table '$utable'."
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
148 if {[catch {dbh eval "CREATE TABLE $utable ($usql)"} uerrmsg]} {
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
149 puts "Error creating table: $uerrmsg."
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
150 return 0
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
151 }
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
152 return 1
31
1ddfada536ff Add utility "library" for database conversion and creation scripts.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 }
1ddfada536ff Add utility "library" for database conversion and creation scripts.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
290
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
155
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
156 proc utl_create_table_or_fail { dbh utable usql } {
cad1041b5bc4 Revamp the utility functions library.
Matti Hamalainen <ccr@tnsp.org>
parents: 262
diff changeset
157 if {![utl_create_table $dbh $utable $usql]} {
63
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
158 exit 3
7b03971c6d28 Remove tabs and reindent.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
159 }
31
1ddfada536ff Add utility "library" for database conversion and creation scripts.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 }