/********************** 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 UpLogin
You must be logged in to post a comment.
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!