[EMAIL PROTECTED] wrote:
....
It would probably not require more than a few lines of TCL code to
implement a "dump" command as a TCL proc.
I know that copying from one database to another is not the same as
dumping, but the following might be a useful starting point. It gets the
filenames of an existing version 2 SQLite file and a desired version 3
file, and does the copy.
I am placing it in the public domain, if anyone wants to use it. It has
had a little testing on small files, but it seems to work. I hope it is
small enough that posting here is not a problem for anyone.
Gerry Snyder
# ***********************************************************
# Convert an SQLite data-base file from V2 to V3
# ***********************************************************
proc two2three {} {
global mainlabel
if {[set dbfilein [tk_getOpenFile]] == {} } {
return
}
if {[set dbfileout [tk_getSaveFile]] == {} } {
return
}
sqlite sqin $dbfilein
sqlite3 sqout $dbfileout
sqout eval begin
# Duplicate schema
sqin eval {SELECT sql FROM sqlite_master WHERE sql NOT NULL} {} {
sqout eval $sql
}
# Copy data
# For each table...
sqin eval {SELECT name FROM sqlite_master WHERE type='table'} {} {
set fieldnamescomma {}
# get field names and values
sqin eval "SELECT * FROM $name" fieldnames {
# but use them only if table is non-empty
if {[llength $fieldnames(*)] > 0} {
# Now $fieldnames(*) is a list of the field names
# and the rest of the $fieldnames array is values
# --set up params for insert (first time thru)
if {[string length $fieldnamescomma] == 0} {
set fieldnamescomma [join $fieldnames(*) ,]
set valuevarscomma "\$fieldnames([join $fieldnames(*)
),\$fieldnames(])"
set sqlstmnt "insert into $name\($fieldnamescomma)
values($valuevarscomma)"
}
# Now sqltrmnt is something like "insert into
table1(field1,field2) values($fieldnames(field1),$fieldnames(field2))"
sqout eval $sqlstmnt
}
}
}
sqout eval commit
}
-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------