Re: DBD::ODBC adding blob data error to Informix Db
Posted in 1998
andy_williams@my-dejanews.com wrote: > I have tried using > > $quotedblob = $dbh->quote($blobdata); > $sth = $dbh->do("insert into test (name,age,type,tblob) values ('Fred Bloggs', > '98', 'A', $quotedblob)"); > > and this seems to work for the TEXT data type, but I get a Syntax error for > the BYTE data type. > > Still need help You're going to have to bash the ODBC and DBD::ODBC manuals. DBD::Informix has to go through all sorts of contortions to handle blobs -- doesn't ODBC have to do the same? FWIW, there are no blob literals in Informix, so any solution which tries to insert blob literals (eg using $dbh->quote() on the data) is prett much guaranteed to fail. The only way to do it in DBD::Informix is with a ? placeholder in the query -- the code them automagically generates the necessary loc_t structure for the data. And, until 7.30 ESQL/C became available, it was not possible to determine which columns in an UPDATE statement were blob columns, meaning that you cannot (yet) use DBD::Informix to update blobs. > Thanks > > Andy > > In article <6tqkf9$dfv$1@nnrp1.dejanews.com>, > andy_williams@my-dejanews.com wrote: > > I get the following error when attempting to add blob data to my informix > > database via my perl script. This only happens using INTERSOLV 3.01 32bit ODBC > > driver. It works > > using version 2.80 (Unfortunately I have an other problem with this driver). > > > > "DBD::ODBC::st execute failed: [INTERSOLV][ODBC Informix > > driver][Informix]Illegal attempt to convert Text/Byte blob type." > > > > The code is listed below. > > > > Please help > > > > Andy > > > > print "Reading data...\\n"; > > open(FH, "test.txt") or die "$!\\n"; > > @lines = <FH>; > > close FH; > > $blobdata = join("",@lines); > > undef @lines; > > > > print "Create Table......."; > > $sth = $dbh->prepare("create table test \\(name CHAR\\(20\\) PRIMARY KEY, age > > INTEGER, type CHAR\\(1\\) DEFAULT 'A', tblob TEXT in TEXT1\\)"); > > die "Prepare failed " . $dbh->errstr . "\\n" if $dbh->errstr; > > $sth->execute; > > die "Execute failed " . $dbh->errstr . "\\n" if $dbh->errstr; > > print "Ok\\n\\n"; > > > > $sth = $dbh->prepare("insert into test \\(name,age,type,tblob\\) values \\('Fred > > Bloggs', '98', 'A', ?\\)"); die "Prepare failed " . $dbh->errstr . "\\n" if > > $dbh->errstr; $sth->execute($blobdata); die "Execute failed " . $dbh->errstr > > . "\\n" if $dbh->errstr; # The Error occurs # Here print "Ok\\n\\n"; -- Jonathan Leffler (jleffler@informix.com, jleffler@earthlink.net) Guardian of DBD::Informix v0.60 -- see http://www.perl.com/CPAN #include <disclaimer.h>