My organization uses batch files to perform queries on our database, and I am presented with a situation in which I need to perform a query which would be much too large to do all at once. So what I've done is modified a batch file to loop through a text file and query each line individually and append the results to the output file.
The problem is when I echo the query variable it reads exactly as expected, but when I pass it to ogr in place of the sql string it seems to be blank. I'm not sure if I'm doing something wrong, or if what I'm trying to do just isn't possible. Can anyone clarify what's going on here?
SET Path=\\my\path\blah\gdal\bin
SET GDAL_DATA=\\my\path\blah\gdal\data
@echo off
SET "file=C:\filepath.txt"
SET /A i=0
REM put file into array line by line
for /F "usebackq delims=" %%a in ("%file%") DO (
set /A i+=1
call set array[%%i%%]=%%a
call set n=%%i%%
)
REM Loop through array entries
for /L %%i in (1,1, %n%) DO (
REM Create SQL String
call set "queryStart="SELECT * FROM _tablename WHERE _fieldname IN ('"
call set uid=%%array[%%i]%%
call set "queryEnd=')""
call set call set "fullQuery=%%queryStart%%%%uid%%%%queryEnd%%"
REM Database Request
ogr2ogr -skipfailures -update -append -s_srs EPSG:4326 -t_srs EPSG:4326 -f "FileGDB" C:\blah\MyExport.gdb PG:"dbname=instagram host=hostservername user=username password=password" -sql %fullquery% -nln "LayerName" -nlt POINT --config FGDB_BULK_LOAD yes
)
pause;