PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB » Bug #1355

DB/odbc::quote fails with numeric data stored as strings

Details

Submitted2004-05-06 20:38 UTC
Fromaaron-public at 100-acre dot com
Assigneddanielc
StatusBogus
PackageDB
PHP Version4.3.4
OSWinXP
Roadmaps(Not assigned)

Comments

[2004-05-06 20:38 UTC] aaron-public at 100-acre dot com

Description:
------------
See also Bug #234...

odbc quote starts by checking if the value is_numeric. If so it returns it as is and doesnt quote it.

<code>
function quote($str = null)
{
if (is_numeric($str)) {
return $str;
}
.....
}
</code>

This is an produces a SQL error

<code>
Unexpected Database Error:delete from Questions where questionName=1 [nativecode=22005 [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the varchar value '3.1' to a column of data type int.]
</code>

with the following included code.

Reproduce code:
---------------
/* Database looks like this
CRREATE TABLE Questions (
questionName varchar(50),
someOtherFiled int
)

INSERT INTO Questions (questionName, 1) VALUES ('1', 1);
INSERT INTO Questions (questionName, 1) VALUES ('1.1', 1);
INSERT INTO Questions (questionName, 1) VALUES ('2.1', 1);
INSERT INTO Questions (questionName, 1) VALUES ('3.1', 2);
*/

$db->query('delete from Questions where questionName=?', array('3.1'));

Expected result:
----------------
odbc::quote should trust the actual datatype of the variable. This may result in numbers being quoted more often then necesary but MSSQL and other have no problem converting things fron char data to numeric type but something like questionName=3.1 is ambigious at best.

The solution used in Bug #234 for DB_mssql seems like a good one here.