Documentation Home
MySQL 5.6 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 31.2Mb
PDF (A4) - 31.2Mb
PDF (RPM) - 30.4Mb
EPUB - 7.7Mb
HTML Download (TGZ) - 7.5Mb
HTML Download (Zip) - 7.6Mb
HTML Download (RPM) - 6.5Mb
Eclipse Doc Plugin (TGZ) - 8.3Mb
Eclipse Doc Plugin (Zip) - 10.1Mb
Man Pages (TGZ) - 183.8Kb
Man Pages (Zip) - 295.2Kb
Info (Gzip) - 2.9Mb
Info (Zip) - 2.9Mb
Excerpts from this Manual

MySQL 5.6 Reference Manual  /  ...  /  mysql_warning_count()

23.8.7.73 mysql_warning_count()

unsigned int mysql_warning_count(MYSQL *mysql)

Description

Returns the number of errors, warnings, and notes generated during execution of the previous SQL statement.

Return Values

The warning count.

Errors

None.


User Comments
  Posted by Ding on November 16, 2005
Here is how we can use this function.

But we cant do anything else beside knowing that there warnings.

Here is a code in detecting errors and warnings in C.
My target here is to display error and warning count based on the query given in the variable.

You can just replace the value of szSqlStmt string to any querry you would like. Well we need to trap the error & warnings so just made it wrong.

//----------------------------------------------
//C language code
//----------------------------------------------

void main(){
char szSqlStmt[] = "DROP TABLE IF EXISTS no_such_table";
MYSQL *conn = mysql_init(NULL);
MYSQL_RES *res_set;

mysql_real_connect(conn,"localhost","root","","mysql",0,NULL,0);

if (strlen(mysql_error(conn))) {//using strlen
fprintf (stderr,"%s",mysql_error(conn));
}else{
mysql_query(conn,szSqlStmt);
res_set = mysql_store_result(conn);

/**********************
display the query info
***********************/
fprintf(stdout,"\nQry nfo:%s",(char*)mysql_info(conn));

if (mysql_errno(conn)) {
/**********************
Display the error message if any
***********************/
fprintf (stderr,"\nError: %s",mysql_error(conn));
}

/**********************
Display the Warning message if Any -- well in this case we have generated a warning...
***********************/
if (mysql_warning_count(conn)) {
fprintf (stdout,"\nTHERE ARE '%d' WARNING FOUND!",mysql_warning_count(conn));
/***********************
When it comes here we already know that there are warning.
It should be better if we have mysql_warning() to display the warning message.
***********************/
}

mysql_close(conn);
}
}
//----------------------------------------------
//END OF THE CODE
//----------------------------------------------

OUTPUT:

Qry nfo:(null)
THERE ARE '1' WARNING FOUND!
  Posted by Martin von Gagern on October 2, 2009
To get at the actual warning messages, the SHOW WARNINGS command can be used. See section 12.5.5.37. of this manual.
Sign Up Login You must be logged in to post a comment.