(Re-)Create settings table if missing.
This commit is contained in:
parent
f4357b87db
commit
da24fc6b20
@ -2,20 +2,6 @@
|
||||
if {![exists -command class]} { package require oo }
|
||||
if {![exists -command sqlite3.open]} { package require sqlite3 }
|
||||
|
||||
if {![file exists /mod/etc/webif.db]} {
|
||||
set ::settingsdb [sqlite3.open /mod/etc/webif.db]
|
||||
catch {
|
||||
$::settingsdb query {
|
||||
CREATE TABLE settings(name text, nval int, tval text);
|
||||
}
|
||||
$::settingsdb query {
|
||||
CREATE UNIQUE INDEX key on settings(name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
set ::settingsdb [sqlite3.open /mod/etc/webif.db]
|
||||
}
|
||||
|
||||
class settings {
|
||||
hostname ""
|
||||
channel_group 0
|
||||
@ -55,6 +41,18 @@ class settings {
|
||||
noautoremove 0
|
||||
}
|
||||
|
||||
proc {settings _create} {} {
|
||||
global settingsdb
|
||||
catch {
|
||||
$settingsdb query {
|
||||
CREATE TABLE settings(name text, nval int, tval text);
|
||||
}
|
||||
$settingsdb query {
|
||||
CREATE UNIQUE INDEX key on settings(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
proc {settings _safer_query} { queryText args } {
|
||||
global settingsdb
|
||||
|
||||
@ -456,3 +454,19 @@ settings method dedup_template {{pattern -1}} {
|
||||
return $val
|
||||
}
|
||||
|
||||
|
||||
set dbname /mod/etc/webif.db
|
||||
if {![file exists $dbname]} {
|
||||
set ::settingsdb [sqlite3.open $dbname]
|
||||
settings _create
|
||||
} else {
|
||||
set ::settingsdb [sqlite3.open $dbname]
|
||||
try {
|
||||
# force use of index (SQLite3 extension) for validation
|
||||
$::settingsdb query {
|
||||
select name, nval, tval from settings indexed by key where name = '';
|
||||
}
|
||||
} on error {msg opts} {
|
||||
settings _create
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user