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),int

The data

1234567;11/111111111111111111;B;111111111111111111111111;A11;22.10.2012 00:00:00;7;4142;15.10.2012 00:00:00;13:22

This 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»


In reply to Why does my insert work with DBI but fails with DBIx::Simple? by karlgoethebier

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.