Hi
I am currently enhancing the script below that I use to access a sqlite database.
One of the things i often do in my SQL queries is modulo math operations. Unfortunately SQL (as used in sqlite) uses the percentage symbol "%" as the modulo operator.
Within sqlite I do this to get the result I want:
sqlite>
sqlite> select 123456789 % 1000000;
456789
sqlite>
At the TCC prompt I do this:
[C:\Documents and Settings\John\My Documents\Data\proj
16:31>sqlite3 locns.db3 "select 123456789 %% 1000000"
456789
However, at the command line for my script below, I need to do this:
[C:\Documents and Settings\John\My Documents\Data\projects\locations\data]
16:39>locns "select 123456789 %%%%%%%%%%%%%%%% 1000000"
inputline=: "select 123456789 %%%% 1000000"
arg=: "select 123456789 %% 1000000"
sql=: "select 123456789 % 1000000"
opt=:
outputline=: sqlite3 -cmd ".prompt 'locns> ' ' ... > '" locns.db3 "select 123456789 % 1000000"
Press any key when ready...
456789
ie. with 16 "%" symbols to get the result I want.
I know this is to do with how Windows/MSDos uses % to identify variables, but I was wondering if anyone knows how to work around this (if it can be done).
Thanks
John
[script]
@echo off
: locns.btm
: 2011nov11jmcm - open an sqlite shell on locns database from anywhere
: 2012jan03jmcm - or execute query immediately
: 2013nov14jmcm - added sqprompt
: 2014jan21jmcm - expand option processing
:
setlocal
pushd "C:\Documents and Settings\John\My Documents\Data\projects\locations\data\"
echo.
echo inputline=: %$
echo.
do while !%1! != !!
set arg=%1
echo.
echo arg=: %arg
echo.
iff %@lower[%arg] eq -tabs then
set tabs=-separator ^q^t^q
echo tabs=: %tabs
elseiff %@lower[%arg] eq -cmd then
set options=%options %arg
shift
set options=%options %1
echo opt=: %options
elseiff %@lower[%arg] eq -init then
set options=%options %arg
shift
set options=%options %1
echo opt=: %options
elseiff %@lower[%arg] eq -mmap then
set options=%options %arg
shift
set options=%options %1
echo opt=: %options
elseiff %@lower[%arg] eq -nullvalue then
set options=%options %arg
shift
set options=%options %1
echo opt=: %options
elseiff %@lower[%arg] eq -separator then
set options=%options %arg
shift
set options=%options %1
echo opt=: %options
elseiff %@lower[%arg] eq -vfs then
set options=%options %arg
shift
set options=%options %1
echo opt=: %options
elseiff %@left[1,%arg] == ^q then
set sql=%arg
echo sql=: %sql
else
set options=%options %arg
echo opt=: %options
endiff
shift
enddo
echo.
echo opt=: %options
echo.
set sqprompt=-cmd ".prompt 'locns> ' ' ... > '"
echo outputline=: sqlite3 %sqprompt %options %tabs locns.db3 %sql
echo.
pause
sqlite3 %sqprompt %options %tabs locns.db3 %sql
popd
endlocal
[/script]
I am currently enhancing the script below that I use to access a sqlite database.
One of the things i often do in my SQL queries is modulo math operations. Unfortunately SQL (as used in sqlite) uses the percentage symbol "%" as the modulo operator.
Within sqlite I do this to get the result I want:
sqlite>
sqlite> select 123456789 % 1000000;
456789
sqlite>
At the TCC prompt I do this:
[C:\Documents and Settings\John\My Documents\Data\proj
16:31>sqlite3 locns.db3 "select 123456789 %% 1000000"
456789
However, at the command line for my script below, I need to do this:
[C:\Documents and Settings\John\My Documents\Data\projects\locations\data]
16:39>locns "select 123456789 %%%%%%%%%%%%%%%% 1000000"
inputline=: "select 123456789 %%%% 1000000"
arg=: "select 123456789 %% 1000000"
sql=: "select 123456789 % 1000000"
opt=:
outputline=: sqlite3 -cmd ".prompt 'locns> ' ' ... > '" locns.db3 "select 123456789 % 1000000"
Press any key when ready...
456789
ie. with 16 "%" symbols to get the result I want.
I know this is to do with how Windows/MSDos uses % to identify variables, but I was wondering if anyone knows how to work around this (if it can be done).
Thanks
John
[script]
@echo off
: locns.btm
: 2011nov11jmcm - open an sqlite shell on locns database from anywhere
: 2012jan03jmcm - or execute query immediately
: 2013nov14jmcm - added sqprompt
: 2014jan21jmcm - expand option processing
:
setlocal
pushd "C:\Documents and Settings\John\My Documents\Data\projects\locations\data\"
echo.
echo inputline=: %$
echo.
do while !%1! != !!
set arg=%1
echo.
echo arg=: %arg
echo.
iff %@lower[%arg] eq -tabs then
set tabs=-separator ^q^t^q
echo tabs=: %tabs
elseiff %@lower[%arg] eq -cmd then
set options=%options %arg
shift
set options=%options %1
echo opt=: %options
elseiff %@lower[%arg] eq -init then
set options=%options %arg
shift
set options=%options %1
echo opt=: %options
elseiff %@lower[%arg] eq -mmap then
set options=%options %arg
shift
set options=%options %1
echo opt=: %options
elseiff %@lower[%arg] eq -nullvalue then
set options=%options %arg
shift
set options=%options %1
echo opt=: %options
elseiff %@lower[%arg] eq -separator then
set options=%options %arg
shift
set options=%options %1
echo opt=: %options
elseiff %@lower[%arg] eq -vfs then
set options=%options %arg
shift
set options=%options %1
echo opt=: %options
elseiff %@left[1,%arg] == ^q then
set sql=%arg
echo sql=: %sql
else
set options=%options %arg
echo opt=: %options
endiff
shift
enddo
echo.
echo opt=: %options
echo.
set sqprompt=-cmd ".prompt 'locns> ' ' ... > '"
echo outputline=: sqlite3 %sqprompt %options %tabs locns.db3 %sql
echo.
pause
sqlite3 %sqprompt %options %tabs locns.db3 %sql
popd
endlocal
[/script]