Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: DBD::ODBC not support

by mje (Curate)
on May 12, 2010 at 10:08 UTC ( [id://839587]=note: print w/replies, xml ) Need Help??


in reply to DBD::ODBC not support

You are interpolating scalars containing ':' into your SQL and ':' is the introducer for named parameters. As a result DBD::ODBC thinks your SQL contains some named parameters and obviously some of those :xxx strings occur more than once. If you are not using named parameters (which you do not appear to be) and for some strange reason cannot use placeholders for the parameters you need to look at setting odbc_ignore_named_placeholders. However, I would just use bound parameters if I were you - much safer.

Replies are listed 'Best First'.
Re^2: DBD::ODBC not support
by Bheema_Tyco (Novice) on May 12, 2010 at 10:47 UTC

    i am running query like this

    my $SQL = "UPDATE kcrei_batch_job_history SET rows_added = ?, status = 'C', stop_datetime = getdate(), stop_tran_seq_nbr = ?, elapsed_time_hh = datediff(hh, convert(dat +etime,?), getdate()), elapsed_time_mm = datediff(mi, convert(dat +etime,?), getdate()), elapsed_time_ss = datediff(ss, convert(dat +etime,?), getdate()) WHERE master_job_no = ? AND master_job_sub_no = ?";
    my $sth = $dbh->prepare( $SQL ) or die "Couldn't prepare statement: " . $dbh->errstr; eval{ $sth->execute($_[1], $hdr_tran_seq_nbr, $loader_start_time, $loader_start_time, $loader_start_time, $master_job_no, $_[0] ); $sth->finish(); }; if( $@ ) { outputErrorMessage( "$@" ); outputErrorMessage( "$sth->{Statement}" ); }

    hi mje in this way i am running my query

      But what are the values of the parameters passed to execute?

Re^2: DBD::ODBC not support
by wjw (Priest) on Dec 03, 2010 at 17:48 UTC

    I have been trying to understand this for some time now. The ':' in the strings I was using for time parameters was in fact the problem.

    my $stime = '2010-01-01 00:00:00' my $qstring = qq{select * from mytable where start > $stime return};

    which returned the error "DBD::ODBC does not yet support binding a named parameter more than once". After reading this, I made things work by (abbreviatedj example)...

    my $stime = '2010-01-01 00:00:00' my $qstring = qq{select * from mytable where start > '$stime' return};

    ..which made all work just fine. Apparently those ':' create the problem.

    Thanks for pointing that out!

    Just goes to show; elephants don't bite, mosquitoes do!

    • ...the majority is always wrong, and always the last to know about it...
    • The Spice must flow...
    • ..by my will, and by will alone.. I set my mind in motion

      In DBI, the : introduces a named parameter into the SQL. The convention in the ODBC world is ? introduces a parameter but as DBI dictates :my_param is also valid DBD::ODBC has to parse the SQL to check for named parameters. If you create SQL containing an unquoted : it looks like a parameter. In your first example this is exactly what you did and because it was 00:00:00 it looks like you have 2 named parameters called "00". DBD::ODBC does not support binding the same named parameter more than once (Using the same placeholder more than once) and hence the message you got.

      If you absolutely have to include a string in your SQL instead of using a parameter marker (?) and binding the parameter you need to quote it and DBI has a quote method for just that (don't just use single quotes as it can differ between SQL engines).

      You can stop DBD::ODBC looking for named parameters by setting odbc_ignore_named_placeholders. In fact, I only wish the default could be this as it wastes time parsing the SQL if you are not using named parameters but DBI says it has to support them.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://839587]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 19:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found