VSarkiss has asked for the wisdom of the Perl Monks concerning the following question:
I ran into this problem this morning, and talked about a little in CB. Although I now have a workaround, I'm still wondering if anyone has had similar experiences, or has any insight into why the problem is occurring.
I'm using DBD::ADO against a SQL Server 2000 database. One of my tables has two varchar(50) columns (among others), and when I would try to insert into them, the strings were getting truncated. Here are the details.
Here's the table in question.
And the statement I was using to insert data looked like this:create table db_column ( tab_id int not null , col_num int not null , col_name varchar(50) not null , col_data_type int not null , col_data_type_name varchar(50) not null , col_charlength int , col_precision int , col_scale int , col_nullity char(1) not null , constraint db_column0 primary key ( tab_id , col_num ) )
The program inserts around 4000 rows into this table in a typical run. The col_name column consistently had no more than four characters, and col_data_type_name had no more than seven. Similar truncation was happening in other tables as well.my $addcol = $dbh->prepare( "insert into db_column ( tab_id , col_num , col_name , col_data_type , col_data_type_name , col_charlength , col_precision , col_scale , col_nullity ) values (?, ?, ?, ?, ?, ?, ?, ?, ?)"); # later.... $addcol->execute( $tabid, $ck->{order}, $colname, $ck->{type}, $dbh->sql_typename($ck->{type}), $ck->{charlength}, $ck->{precision}, $ck->{scale}, ($ck->{nullity}? 'Y' : 'N')) or warn "Couldn't insert into db_column: $DBI::errstr" +;
For debugging, I printed the values just before calling execute to insert them, so I know they were correct at the time of the call. I could also insert the strings using a interactive SQL tool, so I know the table itself wasn't a problem. I ran with DBI->trace(5) so I could see the intact strings being passed down, and that there were no error messages. I poked around the http://dbi.perl.org archives but didn't find anything that seemed related to this.
The truncation went away when I stopped using placeholders. That is, when I interpolate the strings directly into the SQL statement (using $dbh->quote and friends), they make it to the database intact. I'm at a complete loss to explain it.
At this point, the modified code runs, so I'm not stuck, but I'm more curious than ever. Are there any "known issues" with DBD::ADO that I couldn't find? Does anyone see some numbskull error in my code??? As one monk pointed out, I could probably switch to DBD::ODBC and fix it also, but this smells like a bug in the ADO driver. I'll send a bug report to the author if it looks a bug to others as well.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: String truncation when using DBD::ADO and placeholders
by Anonymous Monk on Sep 14, 2004 at 02:15 UTC | |
by VSarkiss (Monsignor) on Sep 14, 2004 at 15:36 UTC |