On Tuesday, April 10, 2012 07:14:59 PM Frank Chang wrote:
> Good evening, We are trying to generate automated SQLITE SQL scripts based
> on the names of SQLite tables derived by substring manipulation of Windows
> DOS batch file and/or Windows environment variables. For example:
>
> /* mary.bat */
> FOR /f %%a IN ('dir /b *.zip') DO CALL sub %%a
>
>
> /* sub.bat */
> set str=%1
> set camster=%str:~0.17%
> echo %str:~0,17%
> E:\users\marc\NJM\spatialite_tool.exe -i -shp %str:~0,17% -d
> e:\users\marc\NJM\mdMatchup.dat -t %str:~0,17% -g Geometry -c CP1252 -s
> 4269 E:\users\marc\NJM\sqlite.exe -line e:\users\marc\NJM\mdMatchup.dat
> "drop table %camster%;"
>
>
I think you are asking if you can use a variable
to represent your table name.
I use this in python and have used something
similar in DOS to create, delete, update tables on the fly.
vsqldb = 'SomeDB' ## DB named and related to a variable some place
else
vtablename = 'someTtablename' ## table named some place else
con = sqlite3.connect (vsqldb) # open DB
cursor = con.cursor()
cursor.execute("""DROP TABLE IF EXISTS """ + vtablename )
cursor.execute("""VACUUM""") #clean the DB
con.commit()
con.close()
Dropping the table is possible without hard coding the
table name into the Drop Table command.
jd
> Invoking mary.bat at the command line generates the following command
> script:
>
> E:\TIGER2011\COUSUB>CALL sub tl_2011_78_cousub.zip
> E:\TIGER2011\COUSUB>set str=tl_2011_78_cousub.zip
> E:\TIGER2011\COUSUB>set camster=str:~0.17
> E:\TIGER2011\COUSUB>echo tl_2011_78_cousub
> tl_2011_78_cousub
> E:\TIGER2011\COUSUB>E:\users\marc\NJM\spatialite_tool.exe -i -shp
> tl_2011_78_cou sub -d e:\users\marc\NJM\mdMatchup.dat -t tl_2011_78_cousub
> -g Geometry -c CP125 2 -s 4269
> SQLite version: 3.6.16
> SpatiaLite version: 2.3.1
> load shapefile error: table 'tl_2011_78_cousub' already exists
>
> E:\TIGER2011\COUSUB>E:\users\marc\NJM\sqlite.exe
> -line e:\users\marc\NJM\mdMatchup.dat "drop table str:~0.17;"
> SQL error: unrecognized token: ":"
>
> rather than drop table t1_2011_78_cousub.
>
> Is it possible that we using the wrong SQLite syntax in the sqlite3.exe
> -line database "sql_statement;"? If so, what might be the correct sqlite
> command string to drop the table t1_2011_78_cousub? Thank you very much.
>
> _______________________________________________
> sqlite-users mailing list
> [email protected]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users