user2040158
user2040158

Reputation:

MySQL C API fails to error on subquery returns more than 1 row

From the mysql terminal:

SELECT 1, (SELECT user_id FROM users);

ERROR 1242 (21000): Subquery returns more than 1 row

In C code:

ret = mysql_query("SELECT 1, (SELECT user_id FROM users)");
printf("Ret is %d\n", ret); // -->  "Ret is 0"

Is this a bug in the mysql C api? I cannot get any error information from this query. Both mysql_errno() and mysql_error() return nothing. As far as the API is concerned the query ran successfully.

Upvotes: 0

Views: 60

Answers (1)

Barmar
Barmar

Reputation: 781068

This error isn't reported until you call mysql_store_result.

ret = mysql_query(con, "SELECT 1, (SELECT user_id FROM users)");
printf("Ret is %d\n", ret); // -->  "Ret is 0"
MYSQL_RES *result = mysql_store_result(con);
if (result == NULL) {
    printf("Error is %s", mysql_error(con); // prints "Subquery returns more than 1 row"
}

Upvotes: 1

Related Questions