in reply to Need help with inserting images to excel from db

Hi Monks, What Poj suggested did not work, I tried everything including adding absolute path for the images dir, now I want to try a different approach i.e. to get the images first to a folder and pass that to the insert_image() method, for which I have to use COPY command using DBI which again giving errors this command works fine when executed on the command line but DBD::Pg is giving syntax error, here is my script :
#!/usr/bin/perl use strict; use warnings; use DBI; my $dbh = DBI->connect("DBI:Pg:dbname=northwind;host=localhost", "post +gres", "postgres", {'RaiseError' => 1}); my $empid = $dbh->prepare('SELECT DISTINCT("EmployeeID") as empid FROM + "Employees" ORDER BY 1'); $dbh->do("SET search_path to northwind") or die; $empid->execute(); while(my $ref = $empid->fetchrow_hashref()) { $dbh->do("SET search_path to nortwind") or die; $dbh->do("COPY (SELECT encode(\"Photo\", 'hex') FROM \"Employees\" WHERE \"EmployeeID\"='$ref->{'empid'}') TO '/home/postgres/scripts/images/'$ref->{'empid'}.hex'") o +r die; system("/usr/bin/xxd -p -r /home/postgres/scripts/images/'$ref->{'empi +d'}.jpg'"); } $dbh->disconnect(); exit;
Here is the error :
DBD::Pg::db do failed: ERROR: syntax error at or near "1." LINE 8: '/home/postgres/scripts/images/'1.hex' ^ at photo.pl li +ne 17. DBD::Pg::db do failed: ERROR: syntax error at or near "1." LINE 8: '/home/postgres/scripts/images/'1.hex' ^ at photo.pl li +ne 17.
Please do help. Thanks Terry

Replies are listed 'Best First'.
Re^2: Need help with inserting images to excel from db
by poj (Abbot) on Jun 29, 2014 at 14:14 UTC
    '/home/postgres/scripts/images/'$ref->{'empid'}.hex' ^ remove
    poj
      Hi Poj, I removed it and it works, many thanks !! it created all the images in images folder then I ran your script and it removed all the images and threw an error :
      Couldn't import /home/postgres/scripts/images/1.jpg: No such file or d +irectory at emp2.pl line 131.
      Which is the last line of the script ! Rgds Terry
        Is the line causing the error $workbook->close(); ?
        I suspect the images are embedded in the spreadsheet when the spreadsheet is closed, in which case you will have to delete the images after this.
        poj