On Sat, Nov 20, 2010 at 2:43 PM, Richard Hipp d...@sqlite.org wrote:
On Sat, Nov 20, 2010 at 8:25 AM, Fredrik Karlsson dargo...@gmail.comwrote:
Dear list,
I am having a silly problem, and need your expertise. I just want to
initiate a SQLite database using a schema file in Tcl, but I just get
an empty database whatever I do. I asked this question on the Tcl
list, and got a reply which I interpret to mean that this is not a
problem in my Tcl knowledge - but in my SQLite implementation.
Anyway, loading from the same SQL file within the sqlite3 command
line client is no problem
Here is what I am doing:
proc init_db {dbDir {dbFile db.sqlite3} {force 1} } {
set dbFile [file join [file normalize $dbDir] $dbFile ]
if { $force == 1 [file exists $dbFile]} {
file delete $dbFile
}
sqlite3 db $dbFile
set schemaFile [file normalize [file join .. setup 1_schema.sql] ]
if {! [file exists $schemaFile] } {
return -code error Unable to open schema file $schemaFile
}
set inf [open $schemaFile r]
set sql [read $inf]
close $inf
Add here: puts $sql
Let's see what file you are really loading
db eval $sql
And here: puts [db eval {SELECT sqlite_version(), sqlite_source_id()}]
db close
return [file normalize $dbFile ]
}
Does the Tcl interface and the sqlite3 binary behave differently
when parsing instructions from a file?
The SQL code in the 1_schema.sql file is just table definitions and
comments using the /* */ syntax which loads ok in the command like
client, so what could be wrong?
Thankful for all the help I could get on this.
/Fredrik
--
Life is like a trumpet - if you don't put anything into it, you don't
get anything out of it.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
--
D. Richard Hipp
d...@sqlite.org
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Thank you Rickard for the quick response. This is really code that is
part of a benchmarking framework (which used to work, oddly enough) so
the output is a bit verbose.
-
$ tclsh8.6 run_all_benchmarks.tcl
[Sat Nov 20 14:50:09 CET 2010] [bench] [debug] '::bench::run -errors 1
-iters 10 -match Emu*simple*one* /usr/local/bin/tclsh8.6
./emuquery.benchmark'
[Sat Nov 20 14:50:09 CET 2010] [bench] [info] 'Benchmark
/usr/local/bin/tclsh8.6'
[Sat Nov 20 14:50:09 CET 2010] [bench] [info] 'emuquery.benchmark'
[Sat Nov 20 14:50:09 CET 2010] [bench] [info] 'Sourcing ./emuquery.benchmark'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'Running EmuQuery: Test
simple query {John=fourth} in one file'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'Copied 1 files to
/private/var/folders/N8/N8aqQyE1FE8Bb0ONohLfsk+++TM/-Tmp-'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info]
'/private/var/folders/N8/N8aqQyE1FE8Bb0ONohLfsk+++TM/-Tmp-'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'CREATE TABLE utterances ('
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'id INTEGER PRIMARY KEY
AUTOINCREMENT,'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'name TEXT,'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'filelength REAL,'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'updated_at TEXT,'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'checksum_algorithm TEXT,'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'checksum TEXT,'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'UNIQUE(name) ON CONFLICT FAIL'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] ');'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'CREATE TABLE levels ('
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'id INTEGER PRIMARY KEY
AUTOINCREMENT,'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'name TEXT UNIQUE ON
CONFLICT FAIL'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] ',weight FLOAT UNIQUE'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] ');'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'CREATE TABLE level_level ('
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'parent_id INTEGER
REFERENCES levels(id),'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'child_id INTEGER
REFERENCES levels(id),'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'PRIMARY KEY(parent_id,child_id)'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] ');'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'CREATE TABLE tc_level_level ('
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'ancestor_id INTEGER
REFERENCES levels(id),'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'descendant_id INTEGER
REFERENCES levels(id),'
[Sat Nov 20 14:50:10 CET 2010] [bench] [info] 'depth INTEGER,'
[Sat Nov 20 14:50:10 CET 2010] [bench]