php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59837 db2_stmt_error(msg) after db2_prepare do not report error
Submitted: 2011-06-30 20:27 UTC Modified: 2018-08-27 09:40 UTC
From: fsteegmans at sugarcrm dot com Assigned: vnkbabu (profile)
Status: Closed Package: ibm_db2 (PECL)
PHP Version: 5.3.5 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
47 - 27 = ?
Subscribe to this entry?

 
 [2011-06-30 20:27 UTC] fsteegmans at sugarcrm dot com
Description:
------------
When checking for errors on a prepared statement which has 
problems no errors are being reported back unless the check is 
done after an execute.

See code below. When checking the return value of db2_execute 
and checking for errors without the statement as a parameter 
we get the correct error report.

However checking for errors with the prepared statement should 
produce consistent results. Either report the error directly 
after the prepare, after the execute, or after both.


Reproduce code:
---------------
var_dump("Starting prepare...<br>");
$stmt = db2_prepare($db, "select wha"); 
var_dump("Prepare done<br>");

if($stmt) { 
		var_dump("Prepare ok, executing query...<br>");
		var_dump($stmt);
		var_dump(db2_stmt_error($stmt)); 
		var_dump(db2_stmt_errormsg($stmt)); 
		db2_execute($stmt); 
		var_dump("<br>Query executed checking error<br>");
		var_dump(db2_stmt_error($stmt)); 
		var_dump(db2_stmt_errormsg($stmt)); 
} else { 
		var_dump("Problem with prepare dumping error without stmt<br>");
		var_dump(db2_stmt_error()); // note no reference to $stmt, as $stmt is not valid 
		var_dump(db2_stmt_errormsg()); 
} 

Expected result:
----------------
resource(193) of type (DB2 Persistent Connection) string(23) 
"Starting prepare...
" string(16) "Prepare done
" string(46) "Problem with prepare dumping error without 
stmt
" string(5) "42601" string(174) "[IBM][CLI Driver]
[DB2/LINUX] SQL0104N An unexpected token "END-OF-STATEMENT" 
was found following "select wha". Expected tokens may 
include: "". SQLSTATE=42601"

OR something to this effect...


resource(193) of type (DB2 Persistent Connection) string(23) 
"Starting prepare...
" string(16) "Prepare done
" string(34) "Prepare ok, executing query...
" resource(463) of type (DB2 Statement) string(37) " 
string(5) "42601" string(174) "[IBM][CLI Driver][DB2/LINUX] 
SQL0104N An unexpected token "END-OF-STATEMENT" was found 
following "select wha". Expected tokens may include: "". 
SQLSTATE=42601"
" Query executed checking error
" string(5) "42601" string(174) "[IBM][CLI Driver]
[DB2/LINUX] SQL0104N An unexpected token "END-OF-STATEMENT" 
was found following "select wha". Expected tokens may 
include: "". SQLSTATE=42601"


Actual result:
--------------
resource(193) of type (DB2 Persistent Connection) string(23) 
"Starting prepare...
" string(16) "Prepare done
" string(34) "Prepare ok, executing query...
" resource(463) of type (DB2 Statement) string(0) "" string(0) 
"" string(37) "
Query executed checking error
" string(0) "" string(0) ""

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-01 03:26 UTC] abhargav at in dot ibm dot com
Hi,

The syntax validation will happen only when db2_execute() will get called. It is actually delayed prepare. 

In the functions db2_stmt_error() and db2_stmt_errormsg(), do not pass $stmt parameter anywhere. 

When I removed $stmt from the above functions, I got following output:

string(23) "Starting prepare...<br>"
string(16) "Prepare done<br>"
string(34) "Prepare ok, executing query...<br>"
resource(5) of type (DB2 Statement)
string(0) ""
string(0) ""
string(37) "<br>Query executed checking error<br>"
string(5) "42601"
string(184) "[IBM][CLI Driver][DB2/NT] SQL0104N  An unexpected token "END-OF-STATEMENT" was found following "select wha".  Expected tokens may include: "<table_expr>".  SQLSTATE=42601 SQLCODE=-104"

I hope this will help..

Regards,
Ambrish Bhargava
 [2011-07-12 19:40 UTC] fsteegmans at sugarcrm dot com
Hi Ambrish,

Thanks for the input. I switched to only checking the return 
value and not passing in the stmt which allows me to work 
around the problem.

However it still seems like an issue as it should be 
possible to pass the statement in as per the documentation 
http://php.net/manual/en/function.db2-stmt-error.php

Thanks for your help,

Frank.
 [2018-08-27 09:40 UTC] vnkbabu@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: vnkbabu
 [2018-08-27 09:40 UTC] vnkbabu@php.net
As this issue is very old Closing it.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 18:01:28 2024 UTC