Reputation: 3711
I am working on an application using delphi 7
as the front end and postgres 9.0
as the back end.
I have to upload images to the server so i use \lo_import
and \lo_export
for inserting images on the server and geting the images from the server.
I had come across a problem where is needed the LASTOID
after a \lo_import
so i can use the OID to update a row in my table but i cant set the syntax correct in windows
UPDATE fishes
SET fishesimages=17755; -- <--last OID
WHERE fishes='0A';
Here is my question on stackoverflow.com. I have got the answer but the script is a Linux shell script. I cannot run it in Windows
psql -h 192.168.1.12 -p 5432 -d myDB -U my_admin << EOF
\lo_import '/path/to/my/file/zzz4.jpg'
UPDATE species
SET fishesimages = :LASTOID
WHERE fishes = '04';
EOF
and
echo "\lo_import '/path/to/my/file/zzz4.jpg' \\\\ UPDATE species SET fishesimages = :LASTOID WHERE fishes = '04';" | \
psql -h 192.168.1.12 -p 5432 -d myDB -U my_admin
I have tried this in windows
"C:\Program Files\PostgreSQL\9.0\bin\psql.exe" -h 192.168.1.12 -p 5432 -d myDB -U my_admin -c "\lo_import 'C://im/zzz4.jpg'";
then immediately (programmatically) im doing
"C:\Program Files\PostgreSQL\9.0\bin\psql.exe" -h 192.168.1.12 -p 5432 -d myDB-U myDB_admin -c " update species SET fishesimages = :LASTOID WHERE fishes='24'"
But I get Syntax error at or near ":"
Can anyone tell tell me how to covert it to Windows commnad?
Upvotes: 0
Views: 445
Reputation: 20398
Just put the commands in a file (say import.psql)
-- contents of import.psql
\lo_import '/path/to/my/file/zzz4.jpg'
UPDATE species
SET speciesimages = :LASTOID
WHERE species = 'ACAAC04';
than issue command
"C:\Program Files\PostgreSQL\9.0\bin\psql.exe" -h 192.168.1.12 -p 5432 -d myDB -U my_admin -f import.psql
Upvotes: 2