List:General Discussion« Previous MessageNext Message »
From:Ken Williams Date:March 23 1999 4:32am
Subject:Bug with placeholders & select
View as plain text  
   Placeholders seem to retain their "knowledge" of whether they're strings
	or numbers, from one execute() to the next.  This causes mysterious
	errors when the string can't be interpreted as a number.  Since Perl
	treats 0 and "0" as pretty much the same thing (with loose typing), this
	was most unexpected.

   It seems like one solution could be to use the table information to set
   the binding type, not the internal perl data typing (which is loose
	anyway).  So if I bind to a varchar column, the value is always bound as
	a string, regardless of whether I'm binding a number or a string or

   my $sth = $dbh->prepare("SELECT 1 FROM messages WHERE thread=? AND message=?");

   DBD::mysql::st execute failed: Unknown column '01m' in 'where clause'
   at line 11.

   mysql> show columns from messages;
   | Field   | Type                  | Null | Key | Default | Extra |
   | thread  | mediumint(8) unsigned |      | PRI | 0       |       |
   | message | varchar(4)            |      | PRI |         |       |

   (a) Make sure you coerce all bound values into being the correct internal
	Perl type, or

   (b) Don't use bindings, use statements which aren't prepared in advance,
	and quoted values in the SQL.

>Submitter-Id:	<submitter ID>
>Originator:	Ken Williams
 The Math Forum (
>MySQL support: none
>Synopsis:	Some execute() statements fail when query has placeholders
>Severity:	serious
>Priority:	medium
>Category:	mysql
>Class:		sw-bug
>Release:	mysql-3.22.20a (TCX binary)
System: OSF1 V4.0 564 alpha
Machine: alpha
Some paths:  /usr/local/bin/perl /usr/local/bin/make /usr/local/bin/gcc /usr/bin/cc
GCC: Reading specs from /usr/local/lib/gcc-lib/alpha-dec-osf4.0b/2.8.1/specs
gcc version 2.8.1
Compilation info: CC='cc -std1'  CFLAGS='-O3'  CXX='gcc'  CXXFLAGS='-O3
-fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti'  LDFLAGS=''
Configure command: ./configure  --prefix=/usr/local/mysql '--with-comment=TCX binary'
--with-low-memory --disable-shared
Perl: This is perl, version 5.004_04 built for alpha-dec_osf
Bug with placeholders & selectKen Williams23 Mar