ckbbkc has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I have some code that I have run against MS SQL Server and Sybase ASE successfully. When I try to run it against a Sybase IQ server, there is a problem.
A temp table is created with a single varchar(25) field. Then a list of numbers are read from a file, leading zero's are pre-pended and I attempt to insert them one by one into the temp table.
The error returned is:
DBD::Sybase::st execute failed: Server message number=21 severity=14 state=0 line=0 text=SQL Anywhere Error -1000187: Unable to implicitly convert column 'PAT_MRN_ID' to datatype (varchar) from datatype (integer).The code is:
my $crTmpMRN = qq{create table #mrns (PAT_MRN_ID varchar(25))}; $dbh->do($crTmpMRN); my $mrn; my $name; my $fileRowCount=0; my $dbRowCount=0; my $distinctMRNCount = 0; #for some reason SybaseIQ is trying to insert $mrn as an integer my $insertMRNQuery = qq{insert #mrns (PAT_MRN_ID) values (?)}; my $sth=$dbh->prepare($insertMRNQuery); open (MRNFILE,"$baseDir$mrn_file") or die "Can't read file $baseDir$mr +n_file [$!]\n"; while (<MRNFILE>) { chomp ($_); ($mrn,$name)=split('\t',$_); #uses 10 character MRNs $mrn = substr '0000000000'.$mrn, -10; $sth->execute($mrn); $fileRowCount ++; print qq{'$mrn'\n}; } close (MRNFILE); print '$fileRowCount: '.$fileRowCount."\n";
I don't know much about the odbc drivers - I think it is odd that the error says "SQL Anywhere", but I am using the connection information that I was given. I have figured out a workaround - creating two columns in the temp table, inserting the numbers converted to varchar, then updating the values to the second column in the temp table. But really, I want to understand why it is attempting to insert $mrn as a numeric rather than a string.
Any help would be greatly appreciated!!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Using perl dbi and Sybase IQ doing insert with placeholder getting datatype error
by runrig (Abbot) on Sep 10, 2015 at 17:12 UTC | |
by ckbbkc (Novice) on Sep 10, 2015 at 18:11 UTC | |
Re: Using perl dbi and Sybase IQ doing insert with placeholder getting datatype error
by poj (Abbot) on Sep 10, 2015 at 19:48 UTC | |
by ckbbkc (Novice) on Sep 10, 2015 at 22:03 UTC | |
Re: Using perl dbi and Sybase IQ doing insert with placeholder getting datatype error
by herveus (Prior) on Sep 10, 2015 at 17:19 UTC | |
by ckbbkc (Novice) on Sep 10, 2015 at 18:13 UTC | |
Re: Using perl dbi and Sybase IQ doing insert with placeholder getting datatype error
by ww (Archbishop) on Sep 10, 2015 at 17:31 UTC |