Ovid has asked for the wisdom of the Perl Monks concerning the following question:
My script reads the data from a text file into %data. I then build the SQL in the insertData sub and execute it (raiseError has previously been set). The script processes several files until I get to one particular file. All of the data in this file is fine, except for one field which has about 23,000 characters! I am attempting to stuff it into a field defined as text, which should have no problem holding it. I get the following error message:
Line 101 is $sth->execute(@data). Here's the sub that's generating the problem:DBD::ODBC::st execute failed: [Microsoft][ODBC SQL Server Driver]Strin +g data, right truncation (SQL-22001)(DBD: st_execute/SQLExecute err=-1) at userDataConv.pl line + 101.
I've never worked with MS SQL Server (or ODBC) before, so I am completely at a loss. Searching the documentation has so far turned up nothing. Is it SQL Server, ODBC, or DBI which is choking? I have no idea. Any suggestions would be greatly appreciated. I can supply more data if necessary.sub insertData { my (@columns, @data); # Only insert fields with values # @fields contains the names of the columns in the database # @textFields containst the names of the columns in the text files for (0 .. $#textFields) { if (exists $data{$textFields[$_]} && $data{$textFields[$_]} !~ + /^\s*$/) { push @columns, $fields[$_]; # Database fieldnames push @data, $data{$textFields[$_]}; # Corresponding hash v +alues } } my $fields = join ',', @columns; my $placeHolders = ('?,' x ($#columns)) . '?'; my $sql = "INSERT INTO userData ($fields) VALUES ($placeHolders)"; my $sth = $dbh->prepare($sql); $sth->execute(@data); $sth->finish; }
Cheers,
Ovid
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI Problem?
by ColtsFoot (Chaplain) on Sep 07, 2000 at 10:38 UTC | |
|
(Ovid) Re: DBI Problem Solved
by Ovid (Cardinal) on Sep 07, 2000 at 19:33 UTC | |
by Fastolfe (Vicar) on Sep 07, 2000 at 19:50 UTC | |
by PsychoSpunk (Hermit) on Sep 07, 2000 at 20:40 UTC | |
|
Re: DBI Problem?
by nop (Hermit) on Sep 07, 2000 at 04:36 UTC | |
|
Re: DBI Problem?
by Fastolfe (Vicar) on Sep 07, 2000 at 00:41 UTC | |
|
Re (tilly) 1: DBI Problem?
by tilly (Archbishop) on Sep 07, 2000 at 00:35 UTC |