Tim,

I have a fix to the emulated code that throws an error if you try to bind a non-numeric value as a numeric - is this the desired behaviour? I tested my fix, and it works fine, but perhaps you have pointers to make it even more elegant:

This is what I did:

dbdimp.c :: dbd_bind_ph()


if (! looks_like_number(value)) if (sql_type == SQL_NUMERIC || sql_type == SQL_DECIMAL || sql_type == SQL_INTEGER || sql_type == SQL_SMALLINT || sql_type == SQL_FLOAT || sql_type == SQL_REAL || sql_type == SQL_DOUBLE) do_error(sth, JW_ERR_ILLEGAL_PARAM_NUM, "Non-numeric value bound as numeric!");

perl code to test:

$sth= $dbh->prepare("UPDATE bind SET string = ?, num = ? WHERE id = ?");
$sth->bind_param(1, 'one', SQL_VARCHAR());
$sth->bind_param(2, '1.#INF', SQL_DOUBLE());
$sth->bind_param(3, 1, SQL_INTEGER());
$sth->execute();

error message:

DBD::mysql::st bind_param failed: Non-numeric value bound as numeric! at ./test_bind.pl line 44.

Maybe there's a better way to do the equivalent to checking the SQL type with the or's. Also, I couldn't find an error to pass to do_error (which just calls DBIh_EVENT2) (I need a ERROR_event for this particular error perhaps?)

Kind regards,

Patrick

On Apr 5, 2005, at 3:01 PM, Tim Bunce wrote:

On Tue, Apr 05, 2005 at 11:46:21AM -0700, Patrick Galbraith wrote:
Steve,

There is a version of DBD::mysql (2.9015) that does support
placeholders in the server, via CVS (or I can package it  and send it
to you). I would be glad to give you a version of it to try out, and I
think it may deal with your problem better than the current driver
(which emulates it) the new driver uses the database to handle
placeholders. I have tested this code on numerous SQL statements with
placeholders, and it works great.

That's great. But the behavior when placeholders are emulated[1] still could be easily improved with a one-line code change.

Tim.

[1] I'm presuming that the latest version still lets you use
emulated placeholders either optionally or when talking to old
servers. Is that right?

Patrick Galbraith Senior Software Developer
[EMAIL PROTECTED] http://www.mysql.com

"Whatever action a great man performs, common men follow. Whatever standards he sets by exemplary acts, all the world pursues" -- Bhagavad Gita



Reply via email to