Skip to content

Commit

Permalink
db/drivers/mysql: print debug info for setting MySQL ANSI SQL mode (#…
Browse files Browse the repository at this point in the history
…3638)

* Free DB SQL string

* Release DB connection
  • Loading branch information
tmszi authored and neteler committed Apr 23, 2024
1 parent 23cfdf9 commit de3d65c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion db/drivers/mysql/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ int db__driver_open_database(dbHandle *handle)
const char *name;
dbConnection default_connection;
MYSQL *res;
dbString sql;

db_get_connection(&default_connection);
name = db_get_handle_dbname(handle);
Expand Down Expand Up @@ -62,14 +63,25 @@ int db__driver_open_database(dbHandle *handle)
db_d_report_error();
return DB_FAILED;
}

db_init_string(&sql);
db_set_string(&sql, "SET SQL_MODE=ANSI_QUOTES;");

/* Set SQL ANSI_QUOTES MODE which allow to use double quotes instead of
* backticks */
if (mysql_query(connection, "SET SQL_MODE=ANSI_QUOTES") != 0) {
if (mysql_query(connection, db_get_string(&sql)) != 0) {
db_d_append_error("%s %s", _("Unable to set SQL ANSI_QUOTES mode:"),
mysql_error(connection));
db_d_report_error();
db_free_string(&sql);
mysql_close(connection);

return DB_FAILED;
}
G_debug(3, "db__driver_open_database(): Set ODBC MySQL DB %s",
db_get_string(&sql));

db_free_string(&sql);
}

return DB_OK;
Expand Down

0 comments on commit de3d65c

Please sign in to comment.