perlquestion
sowais
<p>Needd help figuring out why last_insert_id() is giving an error. I am using an INSERT statement via interpolating values (an issue asked in another post), but get "Inappropiate I/O control operation" on the last_insert_id line. I ran trace as well but didnt get much out of it.
<br><br>Trace:
<br> <- execute= ( 1 ) [1 items] at C:\IMS_db.pl line 59 via at C:\IMS_db.pl line 43
<br> -> last_insert_id for DBD::ODBC::db (DBI::db=HASH(0x2985304)~0x2985274 undef undef 'table' undef) thr#b52bac
<br> <- last_insert_id= ( ) [0 items] (not implemented) at C:\IMS_db.pl line 68 via at C:\IMS_db.pl line 43
<br><> DESTROY(DBI::st=HASH(0x2985534)) ignored for outer handle (inner DBI::st=HASH(0x29854f4) has ref cnt 1)
<br> -> DESTROY for DBD::ODBC::st (DBI::st=HASH(0x29854f4)~INNER) thr#b52bac
<br> <- DESTROY= ( undef ) [1 items] at C:\IMS_db.pl line 43 via at C:\IMS_db.pl line 43
dbih_clearcom 0x29854f4 (com 0x27ffbe4, type 3) done.
</p>
<code>
use strict;
use warnings;
use DBI;
use Time::HiRes qw/gettimeofday/;
use Win32::ODBC;
my @timedata = localtime();
my $sec = $timedata[0];
$sec = '0'.$sec if $sec < 10;
my $min = $timedata[1];
$min = '0'.$min if $min < 10; #check I put in place for the single digits
my $hour = $timedata[2];
$hour = '0'.$hour if $hour < 10;
my $day = $timedata[3];
$day = '0'.$day if $day < 10;
my $month = $timedata[4]+1;
$month = '0'.$month if $month < 10;
my $year = $timedata[5]+1900;
(my $seconds, my $ms) = gettimeofday();
$ms = ($ms-($ms%1000))/1000;
my $time = $hour.":".$min.":".$sec.".".$ms;
my $date = $year."-".$month."-".$day;
my $temp_date = $date.' '.$time;
my $server_name = 'SMOKE-SERVER';
my $database_name = 'TESTDB';
my $database_user = '';
my $database_pass = '';
my $filename = 'test_file';
my $file_date = '2011-01-01 00:00:00.000';
my $record_count = 20;
my $sheet_count = 400;
my $doc_ID = 12;
my $client_ID = 2;
my $dbh;
my $DSN = "driver={SQL Server};server=$server_name;database=$database_name;uid=$database_user;pwd=$database_pass;";
eval {
$dbh = DBI->connect("dbi:ODBC:$DSN");
DBI->trace(4,'C:\db_test_log88.txt');
my $sql = "INSERT INTO table VALUES ('$filename','$file_date','$record_count','$sheet_count','$doc_ID','$client_ID','$temp_date')";
my $sth = $dbh->prepare($sql);
$sth->execute() or die "Execute Failed: $!";
my $last_ID = $dbh->last_insert_id(undef,undef,'table',undef) or die "No Last ID: $!";
print "Last ID inserted: $last_ID";
$dbh->disconnect();
};
if($@) {
print "DB Failure: $@";
}
exit 0;
</code>