2 messages in com.mysql.lists.perlStrange error inserting string with "...| From | Sent On | Attachments |
|---|---|---|
| Andrew K Smith | 15 Jul 1999 03:09 | |
| Jochen Wiedmann | 15 Jul 1999 05:08 |
| Subject: | Strange error inserting string with "%" characters.![]() |
|---|---|
| From: | Andrew K Smith (asm...@flyswat.com) |
| Date: | 07/15/1999 03:09:45 AM |
| List: | com.mysql.lists.perl |
Hi,
I'm having a strange error using DBD::mysql when trying to insert a row into a table with one of its fields having a value with "%" characters in it. I am running the latest mysql on windows NT, and am accessing it through ActiveState Perl, and DBI through DBD::mysql.
In particular, I do something like this:
my $tsth = $dbh->prepare_cached(q{INSERT INTO TEST (VAL) VALUES (?)}); $tsth->bind_param(1,$val);
$tsth->execute() || die "Execute failed"; $tsth->finish;
The code above is in a function where $val is passed in. The function is called from a loop and the values for $val are all different, but are all of the form: "Doe%2C%20John" (i.e., they all are "LastName%2C%20FirstName"). When I run it I get errors like this:
DBD::mysql::st execute failed: Unknown column 'Doe' in 'field list' at ....
I tried the same code using ODBC to access mysql and there were no problems.
I played around with the code a lot to see what would happen. One thing I did was to just set one of the bad values as a constant:
my $tsth = $dbh->prepare_cached(q{INSERT INTO TEST (VAL) VALUES (?)}); $val = "Doe%2C%20John"; $tsth->bind_param(1,$val);
$tsth->execute() || die "Execute failed"; $tsth->finish;
and when I ran this, it worked fine.
Also, if I do this:
my $_val = $dbh->quote($val); my $stmt = "INSERT INTO TEST (VAL) VALUES ($_val)"; my $tsth = $dbh->prepare_cached($stmt); $tsth->execute() || die "Execute failed"; $tsth->finish;
it works fine.
So I don't know why the first example wouldn't work. Is there something
about special characters like "%" and bind_param that is causing the problem
here?
Thanks for any help you can give.




