How to display the warning message if mysql_warning_count() returns a value
Posted by:
Ding
Date: November 16, 2005 04:40AM
Ok here is how we can use
mysql_error()
mysql_errno()
mysql_warning_count()
Make sense to these function by knowing each querry results.
This is a running example, assuming that you already set your mysql references and lib.
//----------------------------------------
// C/C++ language
//----------------------------------------
void main(){
char szSqlStmt[] = "DROP TABLE IF EXISTS no_such_table";//replace your own querry here
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!