Home » Database » DB » Bug #31
Ampersand in WHERE clause of Autoexecute statement causes error
Details
| Submitted | 2003-09-23 12:36 UTC |
|---|---|
| From | craiglarmer at hotmail dot com |
| Assigned | danielc |
| Status | Closed |
| Package | DB |
| PHP Version | 4.3.2 |
| OS | Win NT4 |
| Roadmaps | (Not assigned) |
Comments
[2003-09-23 12:36 UTC] craiglarmer at hotmail dot com
Description:
------------
Including an Ampersand (&) in the WHERE clause of an Autoexecute statement causes error.
Suggested solution is to build the WHERE clause after the prepare statement to avoid any special characters (&,?,!) in the WHERE clause being tokenised into extra array entries
Reproduce code:
---------------
assuming a table called WEB_CODES of structure NARR CHAR(10),MAIN_CD CHAR(3), SUB_CD CHAR(3), TYP CHAR(1)
$db = DB::connect(DB_DSN);
$field_list = array('narr' => 'test');
$query = $db->autoExecute('WEB_CODES',$field_list,DB_AUTOQUERY_UPDATE,"typ = '1' AND main_cd = 'B&W' AND sub_cd = 'AF4'");
Expected result:
----------------
Table to be correctly updated
Actual result:
--------------
DB Error: insufficient data supplied
tracing thru common.php we get intermediary results as follows:
in the autoPrepare function after BuildManipSQL call $query is:
UPDATE WEB_CODES SET narr = ?,typ = ? WHERE typ = '1' AND main_cd = 'B&W' AND sub_cd = 'AF4'
which is correct after call to prepare (as part of the return the prepare_tokens variable is:
Array ( [0] => Array ( [0] => UPDATE WEB_CODES SET narr = [1] => ,typ = [2] => WHERE typ = '1' AND main_cd = 'B [3] => W' AND sub_cd = 'AF4' ) )
Where you can see that the extra [3] has been created by splitting the WHERE clause into two (at the ampersand point)