karlgoethebier has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
Why do i get an SQL-22018 error when doing a simple insert using DBIx::Simple but the same thing works, when i use DBI? And i'm getting the same error when I'm using DBI with bind_params.
The datatypes
int, nvarchar(255), nvarchar(5),nvarchar(255),nvarchar(10), datetime, int, int, datetime,time(7),intThe data
1234567;11/111111111111111111;B;111111111111111111111111;A11;22.10.2012 00:00:00;7;4142;15.10.2012 00:00:00;13:22This one fails
#!c:/perl/bin/perl use strict; use warnings; use IO::All; use DBIx::Simple; my $file = q(data.csv); my @lines = io($file)->slurp; my $table = qq(table); my $db = DBIx::Simple->connect( 'DBI:ODBC:myDSN', 'user', 'password', { RaiseError => 1 } ); foreach my $line (@lines) { my @row = (); @row = split( ";", $line ); chomp(@row); $row[3] =~ m/\d{12}(\d{12})/; my $some_ID = $1; $some_ID = int $some_ID; foreach my $item ( 1, 2, 3, 4, 5, 8, 9 ) { $row[$item] = qq('$row[$item]'); } $db->insert($table, \@row); }
The error
DBD::ODBC::st execute failed: [Microsoft][SQL Server Native Client 10. +0]Ungültiger Zeichenwert für Konvertierungsangabe (SQL-22018)
N.B.: This means something like Invalid character value for cast specification
This one works
#!c:/perl/bin/perl use strict; use warnings; use DBI; use IO::All; my $file = q(data.csv); my @lines = io($file)->slurp; my $dbh = DBI->connect( "dbi:ODBC:myDSN", "user", "password" ) || die +$!; my $table = qq(table); my $sth; my $sql; foreach my $line (@lines) { my @row = (); @row = split( ";", $line ); chomp(@row); $row[3] =~ m/\d{12}(\d{12})/; my $some_ID = $1; $some_ID = int $some_ID; foreach my $item ( 1, 2, 3, 4, 5, 8, 9 ) { $row[$item] = qq('$row[$item]'); } $sql .= qq(INSERT INTO $table VALUES($row[0],$row[1],$row[2],$row[ +3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$some_ID );); } $sth = $dbh->prepare($sql); $sth->execute(); $sth->finish(); $dbh->disconnect();
Thank you very much for help and best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Why does my insert work with DBI but fails with DBIx::Simple?
by tobyink (Canon) on Feb 18, 2013 at 10:14 UTC | |
by karlgoethebier (Abbot) on Feb 18, 2013 at 10:46 UTC | |
Re: Why does my insert work with DBI but fails with DBIx::Simple?
by Tux (Canon) on Feb 18, 2013 at 13:19 UTC | |
by karlgoethebier (Abbot) on Feb 18, 2013 at 14:10 UTC |
Back to
Seekers of Perl Wisdom