digdoug has asked for the wisdom of the Perl Monks concerning the following question:
I really need the help of the Perl/Oracle gurus out there :( I have this program that is trying to do an insert on a table that has two TIMESTAMP fields. Here's the consolidated code:
use strict; use DBI; $ENV{'ORACLE_HOME'} = '/pkg/oracle/client10g'; my $sid = 'mysid'; my $user = 'joe'; my $pass = 'joespw'; my $dbh = DBI->connect( "dbi:Oracle:$sid", "$user", "$pass" ) || die( $DBI::errstr . "\n" ); $dbh->{AutoCommit} = 0; $dbh->{RaiseError} = 1; $dbh->{ora_check_sql} = 0; $dbh->{RowCacheSize} = 16; my $sql = qq{insert into reservation (machinename,reservationida,begin +reserve,endreserve,description,reservationid) values (?,?,TO_TIMESTAM +P(?,'DD/MON/YYYY HH:MI:SS'), TO_TIMESTAMP(?,'DD/MON/YYYY HH.MI.SS'),?,?)}; my $sth = $dbh->prepare($sql); $sth->bind_param(1, 'volcano'); $sth->bind_param(2, 666); $sth->bind_param(3, '12/MAR/2010 7:20:00'); $sth->bind_param(4, '12/MAR/2010 8:20:00'); $sth->bind_param(5, 'This machine tends to explode!'); $sth->bind_param(6, 666); #print "$sql\n"; $sth->execute; $sth->finish; $dbh->disconnect;
The database table:
SQL> Name Null? Type ----------------------------------------- -------- ------------------ +---------- RESERVERNAME VARCHAR2(200) RESERVATIONIDA NOT NULL NUMBER(38) BEGINRESERVE NOT NULL TIMESTAMP(6) ENDRESERVE TIMESTAMP(6) DESCRIPTION VARCHAR2(400) MACHINENAME NOT NULL VARCHAR2(20) RESERVATIONID NOT NULL CHAR(50) SQL> Disconnected from Oracle Database 11g Enterprise Edition Release +11.1.0.6.0 - 64bit Production
Here are 2 normal rows from a select statement:
CARRIE,123454,24-NOV-09 06.00.00.000000 PM,24-NOV-09 08.00.00.000000 P +M,For Carrie test,pipe,123454 box1,56789,25-JUL-09 07.00.00.000000 AM,25-JUL-09 08.00.00.000000 AM,, +ector,56789
When I run my script, I get:
DBD::Oracle::st execute failed: ORA-02291: integrity constraint (LRRS. +RESERVATION_MACHINE_FK1) violated - parent key not found (DBD ERROR: +OCIStmtExecute) [for Statement "insert into reservation (machinename, +reservationida,beginreserve,endreserve,description,reservationid) val +ues (?,?,TO_TIMESTAMP(?,'DD/MON/YYYY HH:MI:SS'),TO_TIMESTAMP(?,'DD/MO +N/YYYY HH.MI.SS'),?,?)" with ParamValues: :p1='volcano', :p2=666, :p3 +='12/MAR/2010 7:20:00', :p4='12/MAR/2010 8:20:00', :p5='This is explo +sive fun!', :p6=666] at ./liltest.pl line 23.
This error actually appears twice.
I can connect using sqlplus and insert manually, kind of like this: http://use.perl.org/~jdavidb/journal/29951, so it seems TO_TIMESTAMP should work - actually I'm not even sure if that's the problem. Can't seem to figure this one out... thanks for the help!
DW
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBD::Oracle foreign key problem
by keszler (Priest) on Feb 03, 2010 at 15:22 UTC | |
|
Re: DBD::Oracle foreign key problem
by Corion (Patriarch) on Feb 03, 2010 at 15:27 UTC | |
by digdoug (Initiate) on Feb 03, 2010 at 18:11 UTC | |
|
Re: DBD::Oracle foreign key problem
by roboticus (Chancellor) on Feb 03, 2010 at 15:37 UTC |