δΊ 2011-3-8 23:37, Gary_Gabriel ει:
> Hi mweiguo,
>> hi all:
>> i am writing a tcl script, it will create a empty database and read a
>> schema file into database ...
>> in command line, it works when i use
>>
>>>> .read schema.sql
>>>>
>> but in tcl script enviroment, how can i do that ?
>>
> This script reads the *.sql file as a transaction and executes it in
> Tcl. It reliably works and has been tested with a > 500 line .sql
> transaction.
>
> proc tssScript { } {
> variable tssfile ; # database defined schema in sql file
>
> set fid [open $tssfile]
> set tsscontent [read $fid]
> close $fid
>
> # Open process db1 connection
> sqlite3 db1 $dbfile
>
> # Read the SQLExe file contents to exec the SQL in the file.
> Write the SQL statements to the file delimited by semicolon
> sqlite3 db $dbfile
> db1 eval [subst {$tsscontent}] {
> }
> # test reading the file
> set tempq [db1 eval {SELECT * FROM SearchIndex_temp;}]
> puts "tempq $tempq"
>
> db1 eval {INSERT INTO TABLE (VALUES);}
> db1 eval {INSERT INTO TABLE (VALUES_2);}
>
> set tempq1 [db1 eval {SELECT * FROM TABLE;}]
> puts "tempq1 $tempq"
>
> db1 close
> }
>
> A Tcl equivalent to .read schema.sql.
>
> Good luck- Gary
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
thanks, it works for me.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users