[sqlite] Command line client and Tcl interface behaves differently?

2010-11-20 Thread Fredrik Karlsson
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

db eval $sql

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


Re: [sqlite] Command line client and Tcl interface behaves differently?

2010-11-20 Thread Richard Hipp
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


Re: [sqlite] Command line client and Tcl interface behaves differently?

2010-11-20 Thread Fredrik Karlsson
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] 

Re: [sqlite] Command line client and Tcl interface behaves differently?

2010-11-20 Thread Fredrik Karlsson
Hi,

Sorry, never mind this post. I haven't found the problem actually yet,
but a bare minimum example fed directly to the interpreter through
the command line works correctly:

% package require sqlite3
3.7.2
% set inf [open 1_schema.sql r]
file6
% set sql [read $inf]
[... the contents of the read file is dumped ..]
% close $inf
% sqlite3 db :memory:
% db eval $sql
% puts [db eval {SELECT sqlite_version(), sqlite_source_id()}]
3.7.2 {2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3}
% db eval {select * from SQLITE_MASTER} values {parray values}
[... data concerning all tables are dumped... ]

So, the error is somewhere else in the code. Sorry about that. :-/

/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