S
S
samokiller2020-09-23 20:11:10
C++ / C#
samokiller, 2020-09-23 20:11:10

Why is the sql query actually executed, but according to the program logic it says that it was not executed?

In c++ I send "insert ignore" request.
It is fulfilled, i.e. data is added to the database.
But for some reason in the log it gives out "#2 error".
And event #3 does not occur. What's wrong?

void sql(string query, MYSQL *DB)
{
  MYSQL_RES *res;
  MYSQL_ROW row;

  mysql_ping(DB);//Проверяем живо ли соединение

    if (!mysql_query(DB, query.c_str())) {
      if (res = mysql_store_result(DB)) {
        log("#3");//#3
        while (row = mysql_fetch_row(res)) {
          for (int i = 0; i < mysql_num_fields(res); i++) {
          }
        }
      }
      else {
        log(query);
        log("#2 error");//#2
        log(mysql_errno(DB));
      }
    }
    else log("#1 error");//#1
    
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vilinyh, 2020-09-23
@samokiller

If query is an insert then mysql_store_result will return 0.
You need mysql_affected_rows() to check the inserted records.

R
Rsa97, 2020-09-23
@Rsa97

Why after successful returns of mysql_quer...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question