Strange Perl Result
Posted in 2000
Topics: SQL Development & Query Writing
Hi. I'm trying to get Perl DBI Informix to talk to a remote database and when I ask the database a simple select statement, I get a strange result. Here is my code, and the result should be a simple "1", as that is the only value in the table. #!/usr/bin/perl use DBI; $dbh = DBI->connect("dbi:Informix:database"); $st1 = $dbh->prepare('SELECT * FROM table'); print $st1->execute; print "\\n"; $dbh->disconnect; Instead the result is "0E0".... i'm confused! Thanks for any help Paul Cook
"LordNikon" <lordnikon@bigpond.com> wrote in message news:5y9J5.13020$Ab3.60747@news-server.bigpond.net.au... > Hi. > > I'm trying to get Perl DBI Informix to talk to a remote database > and when I ask the database a simple select statement, I get a strange > result. > > Here is my code, and the result should be a simple "1", as that is the only > value in the table. > > > #!/usr/bin/perl > > use DBI; > > $dbh = DBI->connect("dbi:Informix:database"); > > $st1 = $dbh->prepare('SELECT * FROM table'); > > print $st1->execute; > print "\\n"; > > $dbh->disconnect; > > > Instead the result is "0E0".... i'm confused! from the DBI doc: -------------------------- For SELECT statements, execute simply ``starts'' the query within the database engine. Use one of the fetch methods to retreive the data after calling execute. The execute method does not return the number of rows that will be returned by the query (because most databases can't tell in advance), it simply returns a true value. -------------------------- And at another part of the doc: -------------------------- The typical method call sequence for a SELECT statement is: prepare, execute, fetch, fetch, ... execute, fetch, fetch, ... execute, fetch, fetch, ... for example: $sth = $dbh->prepare("SELECT foo, bar FROM table WHERE baz=?"); $sth->execute( $baz ); while ( @row = $sth->fetchrow_array ) { print "@row\\n"; } -------------------------- > > Thanks for any help > > Paul Cook > -- Christian Knappke The opinions stated above are my own and not necessarily those of my employer.
Christian, Thanks for your help - that was the problem. Could you possibly pass me a URL to the DBI document that you referenced to help me with? Thanks. Paul "Christian Knappke" <christian.knappke@sap.com> wrote in message news:8t3c46$hg4$1@news1.wdf.sap-ag.de... > "LordNikon" <lordnikon@bigpond.com> wrote in message > news:5y9J5.13020$Ab3.60747@news-server.bigpond.net.au... > > Hi. > > > > I'm trying to get Perl DBI Informix to talk to a remote database > > and when I ask the database a simple select statement, I get a strange > > result. > > > > Here is my code, and the result should be a simple "1", as that is the > only > > value in the table. > > > > > > #!/usr/bin/perl > > > > use DBI; > > > > $dbh = DBI->connect("dbi:Informix:database"); > > > > $st1 = $dbh->prepare('SELECT * FROM table'); > > > > print $st1->execute; > > print "\\n"; > > > > $dbh->disconnect; > > > > > > Instead the result is "0E0".... i'm confused! > > from the DBI doc: > > -------------------------- > For SELECT statements, execute simply ``starts'' the query within the > database engine. Use one of the fetch methods to retreive the data after > calling execute. The execute method does not return the number of rows > that will be returned by the query (because most databases can't tell in > advance), it simply returns a true value. > -------------------------- > And at another part of the doc: > -------------------------- > The typical method call sequence for a SELECT statement is: > > prepare, > execute, fetch, fetch, ... > execute, fetch, fetch, ... > execute, fetch, fetch, ... > for example: > > $sth = $dbh->prepare("SELECT foo, bar FROM table WHERE baz=?"); > $sth->execute( $baz ); > while ( @row = $sth->fetchrow_array ) { > print "@row\\n"; > } > -------------------------- > > > > > Thanks for any help > > > > Paul Cook > > > > -- > Christian Knappke > The opinions stated above are my own and not necessarily those of my > employer. > >
"LordNikon" <lordnikon@bigpond.com> wrote in message news:7WpJ5.14080$Ab3.71198@news-server.bigpond.net.au... > Christian, > > Thanks for your help - that was the problem. > > Could you possibly pass me a URL to the DBI document > that you referenced to help me with? you find one at: http://www.activestate.com/Products/ActivePerl/docs/site/lib/DBI.html HTH -- Christian Knappke The opinions stated above are my own and not necessarily those of my employer.
On Wed, 25 Oct 2000 12:31:46 +0200, "Christian Knappke" <christian.knappke@sap.com> wrote: > >"LordNikon" <lordnikon@bigpond.com> wrote in message >news:7WpJ5.14080$Ab3.71198@news-server.bigpond.net.au... >> Christian, >> >> Thanks for your help - that was the problem. >> >> Could you possibly pass me a URL to the DBI document >> that you referenced to help me with? > >you find one at: > >http://www.activestate.com/Products/ActivePerl/docs/site/lib/DBI.html > or even better run the command 'perldoc DBI' or 'perldoc DBD::Informix'. The perldoc command works for most installed modules and the documentation is guaranteed to agree with your version of the module since it comes from the module itself. -- Rob Wilson rwilson@ntsource.com