开发者

Corrupted mysql table, cause crash in mysql.h (c++)

i've created a very simple mysql class in c+, but when happen that mysql crash , indexes of tables become corrupted, and all my c++ programs crash too because seems that are unable to recognize corrupted table and allowing me to handle the issue ..

Q_RES = mysql_real_query(MY_mysql, tmp_query.c_str(), (unsigned int) tmp_query.size());

if (Q_RES != 0) {
    if (Q_RES == CR_COMMANDS_OUT_OF_SYNC) cout << "errorquery : CR_COMMANDS_OUT_OF_SYNC " << endl;
    if (Q_RES == CR_SERVER_GONE_ERROR) cout << "errorquery : CR_SERVER_GONE_ERROR " << endl;
    if (Q_RES == CR_SERVER_LOST) cout << "errorquery : CR_SERVER_LOST 开发者_如何学运维" << endl;

    LAST_ERROR = mysql_error(MY_mysql);

    if (n_retrycount < n_retry_limit) { // RETRY!
        n_retrycount++;
        sleep(1);
        cout << "SLEEP - query retry! " << endl;
        ping();
        return select_sql(tmp_query);
    }
    return false;
}
MY_result = mysql_store_result(MY_mysql);
B_stored_results = true;

cout << "b8" << endl;
LAST_affected_rows = (mysql_num_rows(MY_result) + 1); // coult return -1
cout << "b8-1" << endl;

the program terminate with a "segmentation fault" after doing the "b8" and before the "b8-1" , Q_RES have no issue even if the table is corrupted.. i would like to know if there is a way to recognize that the table have problems and so then i can run a mysql repair or mysql check ..

thanks, Francesco


You need to check the return value of mysql_store_result() - it might be NULL.

http://dev.mysql.com/doc/refman/5.0/en/mysql-store-result.html

mysql_store_result() returns a null pointer if the statement didn't return a result set (for example, if it was an INSERT statement).

mysql_store_result() also returns a null pointer if reading of the result set failed. You can check whether an error occurred by checking whether mysql_error() returns a nonempty string, mysql_errno() returns nonzero, or mysql_field_count() returns zero.

It's probably not a problem with the database being corrupted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜