Dear list,
I am having a silly problem, and need your expertise. I just want to
initiate a SQLite database using a schema file, but I just get an
empty database whatever I do. Loading from the "sqlite3" command line
client is no problem though..
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 ]
}
What am I doing wrong?
/Fredrik
|
|
0
|
|
|
|
Reply
|
Fredrik
|
11/18/2010 9:23:00 PM |
|
On 11/18/2010 3:23 PM, Fredrik Karlsson 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, but I just get an
> empty database whatever I do. Loading from the "sqlite3" command line
> client is no problem though..
>
> 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 ]
> }
>
> What am I doing wrong?
>
> /Fredrik
I didn't analyze your code closely, but this is almost certainly wrong:
db eval {$sql}
I'd guess that should be:
db eval $sql
That's assuming that your "sql" variable really contains the SQL you expect.
Jeff
|
|
0
|
|
|
|
Reply
|
Jeff
|
11/18/2010 9:40:28 PM
|
|
Hi,
Yes, the string is a valid SQLite SQL string, so I'm now thinking that
this may be an issue with differences in the command line client and
the Tcl interface. Anyway, db eval $sql does not work.
Will post on the SQLite list to make sure.
Thanks!
/Fredrik
On 18 Nov, 22:40, Jeff Godfrey <jeff_godf...@pobox.com> wrote:
> On 11/18/2010 3:23 PM, Fredrik Karlsson 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, but I just get an
> > empty database whatever I do. Loading from the "sqlite3" command line
> > client is no problem though..
>
> > Here is what I am doing:
>
> > proc init_db {dbDir {dbFile db.sqlite3} {force 1} } {
>
> > =A0 =A0set dbFile [file join [file normalize $dbDir] $dbFile ]
> > =A0 =A0if { $force =3D=3D 1&& =A0[file exists $dbFile]} {
> > =A0 =A0 =A0 =A0 =A0 =A0file delete $dbFile
> > =A0 =A0}
> > =A0 =A0sqlite3 db $dbFile
> > =A0 =A0set schemaFile [file normalize [file join =A0.. setup 1_schema.s=
ql] ]
>
> > =A0 =A0if {! [file exists $schemaFile] } {
> > =A0 =A0 =A0 =A0 =A0 =A0return -code error "Unable to open schema file $=
schemaFile"
> > =A0 =A0}
> > =A0 =A0set inf [open $schemaFile r]
> > =A0 =A0set sql [read $inf]
> > =A0 =A0close $inf
>
> > =A0 =A0db eval {$sql}
>
> > =A0 =A0db close
> > =A0 =A0return [file normalize $dbFile ]
> > }
>
> > What am I doing wrong?
>
> > /Fredrik
>
> I didn't analyze your code closely, but this is almost certainly wrong:
>
> db eval {$sql}
>
> I'd guess that should be:
>
> db eval $sql
>
> That's assuming that your "sql" variable really contains the SQL you expe=
ct.
>
> Jeff
|
|
0
|
|
|
|
Reply
|
Fredrik
|
11/20/2010 1:06:04 PM
|
|
|
2 Replies
466 Views
(page loaded in 0.044 seconds)
Similiar Articles: Read schema from a file into SQLite database - comp.lang.tcl ...Dear list, I am having a silly problem, and need your expertise. I just want to initiate a SQLite database using a schema file, but I just get an ... Newbie question: Importing .csv data into Java DB tables - comp ...I am trying to import five simple .csv files into ... standardized" way of importing in such a way into a database ... only once, but iterating it for each line you read ... Importing with TransferDatabase from ODBC and including Indexes ...RESTORE DATABASE FFDBA FROM DISK =3D 'C:\FFDBA.BAK' Read ... about the ODBC database schema > and translating it into Jet ... import the data into an MDB file and ... custom XML schema in Acrobat forms - comp.text.pdf... in the above-mentioned FAQ), we can read a ... Importing data into Adobe XML (Designer 6) or ... Text boxes to an already existing pdf file - comp.text.pdf ... custom XML schema ... Looking for a C/C++ DB SQL library - comp.databases.mysql ...... remote. 1 library, 1 commandline tool, 1 file per database. http://www.sqlite ... From looking into the google it seems this ... -- ( Kees ) c[_] Read a library, write a shelf ... importing to 11Gr2 from 9i - full import or schema's only? - comp ...... this, importing from full exp files on the current production database ... at first I tried having it read the dmp file so I ... OTN Discussion Forums : 9i export file into ... Serialization in Matlab - comp.soft-sys.matlab... interfaces (the network, stored in a database, read aloud ... to get only certain data structures into XML, but ... about sending an object to be stored in a SQLite database? Getting some xml contents in a gif file - comp.compression ...How to Read PDF file from database - comp.lang.java ... basics of reading an XML file into a dataset, as well as creating a schema based on the contents of the XML file. The nightmare begins... - comp.databases.filemakerSo, if you've read this far (and aren't on ... > > Introducing working data into a solution in ... when backups run while I'm editing schema. Of course this works for files ... SAS and large datasets? - comp.soft-sys.sas... their is away to directly read from the database ... XXXXXXXXXX Path="XXXX" Schema= XXX ; Proc <WhatEver> Data ... reading mainframe files and turning them into SAS ... Read schema from a file into SQLite database - comp.lang.tcl ...Dear list, I am having a silly problem, and need your expertise. I just want to initiate a SQLite database using a schema file, but I just get an ... The SQLite Database File Format - SQLite Home Page... in order that database files created by newer versions of SQLite can be read by ... The SQL Database Schema. Page 1 of a database file ... the journal back into the database file ... 7/24/2012 4:54:46 AM
|