Hi,
I am using a table which has a primary-key field which is defined as CHAR(3).
Selecting data from this table fails, when using placeholders for the key-field in the
where-clause of the select statement.
When using the primary-key as constant inside the sql-statement, everything works fine.
The key I am using in the example is "X7 ", two printable characters followed by one
space.
A short demo-program, its output and the table-definition follow.
I am using DBI-1.20, DBD-Oracle-1.12 now.
Furthermore I am quite shure, this was working in an earlier release.
Any help would be greatly appreciated.
Regards,
Leopold
#!/usr/bin/perl
#
use strict;
use DBI;
$ENV{'ORACLE_HOME'} = "/u01/app/oracle/product/8.1.5";
my $dbh = DBI->connect('dbi:Oracle:host=localhost;sid=AAAA', 'scott/tiger', '');
unless($dbh) {die "Unable to connect to Oracle: $! \n"; }
$dbh->{PrintError} = 1;
#---------------------------------------------------------------------------------
my $pk = 'X7 '; # primary key, two printable chars and a space
print "TEST 1: "; # value inside of sql-statement, works fine
my $sql = "SELECT c_stn_ken FROM t_stn where c_stn_ken = '$pk' ";
my $sth = $dbh->prepare($sql);
$sth->execute();
while ( my ( $result) = $sth->fetchrow_array() ) {;
print "Just got $result\n";
}
print "TEST 2: "; # using placeholders now, does not return any
data
my $sql = "SELECT c_stn_ken FROM t_stn where c_stn_ken = ? ";
my $sth = $dbh->prepare($sql);
$sth->execute($pk);
while ( my ( $result) = $sth->fetchrow_array() ) {;
print "Just got $result\n";
}
$dbh->disconnect();
print "\nBye\n";
#=================================================================================
#THE RESULTS OF RUNNING THIS PROGRAM:
#[leo@toy fspr]$ ./wwi
#TEST 1: Just got X7
#TEST 2:
#Bye
#[leo@toy fspr]$
#=================================================================================
#THE TABLE DESCRIPTION FOLLOWS HERE:
#
#SQL> desc t_stn;
# Name Null? Type
# ----------------------------------------- -------- ----------------------------
# C_STN_KEN NOT NULL CHAR(3)
# C_STN_KEN_AUF CHAR(3)
# C_STN_LFN_SND NOT NULL NUMBER(7)
# C_STN_LFN_RCV NOT NULL NUMBER(7)
# C_STN_STS NOT NULL CHAR(3)
# C_STN_TIM_RCV DATE
# C_STN_TIM_SND DATE
# C_STN_SOCKET_ID NOT NULL NUMBER(3)
#
#SQL>
#=================================================================================
#
#WHAT IS WRONG HERE ?