Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Data type mismatch warning using DBI

20 views
Skip to first unread message

Peter Jamieson

unread,
Sep 4, 2008, 11:38:52 PM9/4/08
to
I am using Perl 5.8 with the DBI module to routinely send parsed data to an
Access db.
Sometimes the incoming files may have errors so that numeric data appears as
text.
This causes my script to throw a warning:

DBD::ODBC::st execute failed: [Microsoft][ODBC Microsoft Access Driver] Data
type
mismatch in criteria expression. (SQL-22018) at C:\myscript.pl line 422.

When this happens the script contiues to run and on looking at the db the
particular
record is absent.
What I would like to happen is for my script to die when the above warning
occurs so that
I can examine the input file to see what was causing the data type mismatch
and rectify
the error.

I have checked some DBI tutorials but cannot locate any way of doing this.
Any suggestions or help appreciated!

smallpond

unread,
Sep 5, 2008, 9:43:21 AM9/5/08
to
On Sep 4, 11:38 pm, "Peter Jamieson"


"DBD::ODBC::st execute failed" is not a warning. Are you checking
that
the call at line 422 succeeded?

--S

Peter Jamieson

unread,
Sep 5, 2008, 11:09:34 AM9/5/08
to

"smallpond" <smal...@juno.com> wrote in message
news:94fd545e-25d2-4452...@y38g2000hsy.googlegroups.com...

Thanks for your input smallpond!

Line 422 is simply the: $input->execute($field1,$field2....etc) line in my
script.
Printing out the values of each field can be done of course to detect the
errant
data in the file (usually a typo) but as the script runs unattended to
process thousands of files it
is not practical since the file with the error is not known in advance.
What I seek is for my code to stop or pause thus warning me that a data-type
error was encountered. Hope this makes sense?


smallpond

unread,
Sep 5, 2008, 11:50:57 AM9/5/08
to
On Sep 5, 11:09 am, "Peter Jamieson"
<ldo...@thinkinghatbigpond.net.au> wrote:
> "smallpond" <smallp...@juno.com> wrote in message

execute returns a value which you have to check to see whether it
succeeded
or failed. One way to do that might be:

$input->execute($field1,$field2....etc) or
myprint_the_error_and_die_sub($input->errstr, $thisfilename, $NR,
$field1, $field2, ...);

--S

J. Gleixner

unread,
Sep 5, 2008, 11:54:01 AM9/5/08
to

As 'smallpond' asked, "Are you checking that the call at line 422
succeeded?"

Check the documentation ( perldoc DBI ) for RaiseError or do what
'smallpond' is suggesting and check that the call succeeded. You
may print out something and wait for input, send you E-Mail, or die
if it fails. Examples of doing this also is conveniently included
in the documentation and on thousands of Web sites.

$sth->execute($product_code, $qty, $price) or die $dbh->errstr;

perldoc -f die

Paul Lalli

unread,
Sep 5, 2008, 12:43:31 PM9/5/08
to
On Sep 4, 11:38 pm, "Peter Jamieson"
<ldo...@thinkinghatbigpond.net.au> wrote:
> I am using Perl 5.8 with the DBI module to routinely send parsed data to an
> Access db. Sometimes the incoming files may have errors so that numeric data
> appears as text. This causes my script to throw a warning:
>
> DBD::ODBC::st execute failed: [Microsoft][ODBC Microsoft Access Driver] Data
> type mismatch in criteria expression. (SQL-22018) at C:\myscript.pl line 422.
>
> When this happens the script contiues to run and on looking at the db the
> particular record is absent.
> What I would like to happen is for my script to die when the above warning
> occurs so that I can examine the input file to see what was causing the data
> type mismatch and rectify the error.

It sounds to me like you have PrintError turned on, but want
RaiseError turned on instead.

You can read the docs for DBI, but basically:

$dbh->{RaiseError} = 1;

near the beginning of your db work, after the $dbh is created.

Paul Lalli

Eric Pozharski

unread,
Sep 5, 2008, 3:14:46 PM9/5/08
to
Peter Jamieson <ldo...@thinkinghatbigpond.net.au> wrote:
*SKIP*

> When this happens the script contiues to run and on looking at the db
> the particular record is absent. What I would like to happen is for
> my script to die when the above warning occurs so that I can examine
> the input file to see what was causing the data type mismatch and
> rectify the error.

Look through C<perldoc DBI> for word I<RaiseError> (description is in
L<ATTRIBUTES COMMON TO ALL HANDLES> section).

BTW, consider validating your input.

*CUT*

--
Torvalds' goal for Linux is very simple: World Domination

Peter Jamieson

unread,
Sep 9, 2008, 10:56:43 PM9/9/08
to
Thank you to smallpond, J. Gleixner, Paul Lalli and Eric Pozharski
for assistance. I am working through your suggestions which have all
proved quite helpful.
Your comments are very much appreciated!


0 new messages