On Tue, 10 Apr 2012 19:14:59 -0400, Frank Chang
<[email protected]> 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%;"
> 
> 
>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?

By itself:
        sqlite3 databasefile "drop table table_name;"
is correct syntax. 

However, somehow your script does not expand the expression str:~0.17 to
the intended tablename t1_2011_78_cousub, probably because the %% around
it are dropped somehow. And
        sqlite3 databasefile "drop table str:~0.17;"
is not valid syntax. 
Conclusion: The root cause is in the cmd script.

By the way, the -line option is only relevant for the output format of
SELECT and PRAGMA statements.

Add a line
        echo %camster% 
to the sub.bat script to see what's happening.

Sidenote:
I would use the .cmd extension instead of .bat . Depending on versions,
a different shell interpreter might be invoked.
.bat is for COMMAND.COM
.cmd is for CMD.EXE

Another sidenote:
Although this doesn't explain the observed error, is
E:\users\marc\NJM\sqlite.exe actually sqlite3.exe?


-- 
Regards,

Kees Nuyt

_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to