freddo411 has asked for the wisdom of the Perl Monks concerning the following question:
I've run into a problem reading data with DBI.
In short, I'm trying to match a field in the database (varchar2) containing a string that ends in a space.
When I use sql placeholders in the DBI query string and I pass in a string variable to the execute method that contains the exact match of the database field date for substitution by the dbi placeholder (including the trailing space) I do not get the matching row returned. I am certain the data is in the DB.$lastname = "Smith "; $qs = "select * from table where lastname = ? " $sth = $dbh->prepare($qs) or die "db_error"; $sth->execute($lastname) or die "db error " . DBI->errstr; @data = $sth->fetchrow_array; print "@data";
When I perform the identical SQL (without placeholders) with identical field data in my sql gui I get a match returned.
My running theory is that placeholders in DBI strip off trailing whitespace. Is this true? If not, does anyone have an alternate explaination?
I am running an Oracle DB
I have working example code if anyone is inclined to try this out ...
#!/usr/local/bin/perl ########################################### my $lastname = "AVCO Financial Services India "; print qq/Trying: "$lastname"\n/; use DBI; use Data::Dumper; use strict; my $name = "*****"; my $pw = "*****"; my $dbname = "gonzodb"; my $dbh = DBI->connect( $dbname, $name, $pw,'Oracle') or die DBI->errstr ; my ( $qs, $sth); $qs = "select * from CTemp where lastname like ? "; $sth = $dbh->prepare($qs) or die "db_error"; $sth->execute($lastname) or die "db error " . DBI->errstr; my @data = $sth->fetchrow_array; print "like result: @data \n"; ######## $qs = "select * from CTemp where lastname = ? "; $sth = $dbh->prepare($qs) or die "db_error"; $sth->execute($lastname) or die "db error " . DBI->errstr; my @data = $sth->fetchrow_array; print "equal result: @data \n"; # Clean up $sth->finish; $dbh->commit; $dbh->disconnect;
-------------------------------------
Nothing is too wonderful to be true
-- Michael Faraday
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Problem with DBI placeholders
by etcshadow (Priest) on Jan 28, 2004 at 04:02 UTC | |
|
Re: Problem with DBI placeholders
by graff (Chancellor) on Jan 28, 2004 at 02:26 UTC | |
|
Re: Problem with DBI placeholders
by Roger (Parson) on Jan 28, 2004 at 02:25 UTC | |
|
Re: Problem with DBI placeholders
by PodMaster (Abbot) on Jan 28, 2004 at 02:15 UTC | |
|
Re: Problem with DBI placeholders
by dragonchild (Archbishop) on Jan 28, 2004 at 13:15 UTC | |
by mpeppler (Vicar) on Jan 28, 2004 at 16:06 UTC | |
|
Re: Problem with DBI placeholders
by CountZero (Bishop) on Jan 28, 2004 at 11:13 UTC | |
|
Re: Problem with DBI placeholders
by freddo411 (Chaplain) on Jan 28, 2004 at 21:46 UTC | |
by etcshadow (Priest) on Jan 28, 2004 at 22:34 UTC |