Question about DBI::Informix
Posted in 2000
\
Ralf Heydenreich wrote:
>
> Hi,
> How can I get some docs about using the DBI-Interface? My question
> aims to error messages from this library. Everytime I call
> "$dbh->do(q{UNLOAD TO 'myfile' SELECT * from mytable});" I get the
> error message "DBD::Informix::db do failed: SQL: -201: A syntax error
> has occurred. at ./test.pl line 17.". Where can I get any explanation
> of the error codes?
> Or it is not possible to make such a statement? Is there a list which
> command I can use and which not?
man DBI for general DBI info
man DBD::Informix for Informix specifics
There's also a very useful page (with a difficult name) :
man DBD::DBD::Informix::Summary
(all this, assuming you have been adding the manpages to the MANPATH).
You can write an unload format file as follows :
$sth=$dbh->prepare("select * from mytable");
$sth->execute();
$"='|';
while (($ref=$sth->fetch)) {
print "@{$ref}|\\n";
}
I believe that UNLOAD is a keyword of the dbaccess or sqlcmd or dbunload
tools, not of the server, so you can't send unload to the engine.
Note that the above is unload format (note the '|' before the newline).
Also you'll notice the trailing spaces for char() fields ...
There is a DBI option "ChopBlanks" for that.
$sth->{ChopBlanks}=1;
if you want to get rid of the spaces.
--
David Stes Molenstraat 5 B-2018 Antwerpen, Vlaanderen, Belgie
Tel +32 3 237 43 54 Fax +32 3 237 40 76 Email stes@pandora.be
Thanks for an accurate response, David.
David Stes wrote:
> Ralf Heydenreich wrote:
> > How can I get some docs about using the DBI-Interface? My question
> > aims to error messages from this library. Everytime I call
> > "$dbh->do(q{UNLOAD TO 'myfile' SELECT * from mytable});" I get the
> > error message "DBD::Informix::db do failed: SQL: -201: A syntax error
> > has occurred. at ./test.pl line 17.". Where can I get any explanation
> > of the error codes?
> > Or it is not possible to make such a statement? Is there a list which
> > command I can use and which not?
>
> man DBI for general DBI info
> man DBD::Informix for Informix specifics
Also 'perldoc DBI', 'perldoc DBD::Informix', etc.
> There's also a very useful page (with a difficult name) :
>
> man DBD::DBD::Informix::Summary
Should only be 'perldoc DBD::Informix::Summary'.
> (all this, assuming you have been adding the manpages to the MANPATH).
>
> You can write an unload format file as follows :
>
> $sth=$dbh->prepare("select * from mytable");
> $sth->execute();
> $"='|';
> while (($ref=$sth->fetch)) {
> print "@{$ref}|\\n";
> }
That works until the delimiter appears in one of the fields. Then you
have to deal with escaping it. That's painful, I can assure you.
> I believe that UNLOAD is a keyword of the dbaccess or sqlcmd or dbunload
> tools, not of the server, so you can't send unload to the engine.
That's correct; the same for LOAD.
> [...]
Also, don't forget the Cheetah book - 'Programming the Perl DBI' from
O'Reilly.
--
Yours,
Jonathan Leffler (Jonathan.Leffler@Informix.com) #include <disclaimer.h>
Guardian of DBD::Informix v1.00.PC1 -- http://www.perl.com/CPAN
"I don't suffer from insanity; I enjoy every minute of it!"