On Sat, Nov 20, 2010 at 8:25 AM, Fredrik Karlsson <[email protected]>wrote:
> 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
> [email protected]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
--
D. Richard Hipp
[email protected]
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users