Bug #24899 Comment for C function mysql_stmt_error() is wrong
Submitted: 8 Dec 2006 8:46 Modified: 19 Dec 2006 17:28
Reporter: Xavier GUIBERT Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.0.27 OS:Any (*)
Assigned to: Paul DuBois CPU Architecture:Any
Tags: API, C, documentation

[8 Dec 2006 8:46] Xavier GUIBERT
Description:
In C language, if 'p' is of type "const char *" and points to an empty strings (""), I am not really sure that the 2 statements below are equivalent :

if (p)         // may be true if p == ""
{ ...

and

if (p[0])      // false if p == ""

or perhaps the function return NULL ??

How to repeat:
Not Applicable

Suggested fix:
An empty string ("") is returned if no error occurred. This means returned value is never NULL and thus, must be tested as following:

if (mysql_stmt_error(stmt)[0])
{
// an error occurred
}
[8 Dec 2006 9:48] Hartmut Holzgraefe
the first part of the example checks for mysql_stmt_errno()!=0
mysql_stmt_errno(), not mysql_stmt_error(), so it is returning
the error code (or 0 for "no error"), not the error message string

there is another problem in the example though: 

  if (mysql_stmt_error(stmt)[0])

doesn't seem to be valid C code. I'd suggest to rewrite this
part of the example as:

  char *message = mysql_stmt_error(stmt);

  if (*message) { ...

One needs to assign the result to some variable anyway,
if one was not interested in the actual message returned
one could as well use the ...errno() function to check.

And "*message" is equivalent to "message[0]", but the
former is the more typical way to check for in C code
[19 Dec 2006 17:29] Paul DuBois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products.

The first "if" statement is missing a "*" in front of the function name.
This was also true for the example given in the mysql_error() section.
I've corrected both sections.