Skip to content

Commit

Permalink
db/drivers/odbc: set ODBC MySQL DB backend SQL ANSI_QUOTES MODE (OSGe…
Browse files Browse the repository at this point in the history
…o#3635)

Which allow to use SQL standard double quotes instead of backticks for
escaping column name.
  • Loading branch information
tmszi authored Apr 20, 2024
1 parent ef730b9 commit 5f6977e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions db/drivers/odbc/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ int db__driver_open_database(dbHandle *handle)
SQLRETURN ret;
SQLINTEGER err;
dbConnection connection;
SQLCHAR dbms_name[256];

/* Open connection */
if (open_connection() != DB_OK)
Expand All @@ -39,6 +40,30 @@ int db__driver_open_database(dbHandle *handle)
return DB_FAILED;
}

/* Find ODBC DB driver */
SQLGetInfo(ODconn, SQL_DBMS_NAME, (SQLPOINTER)dbms_name, sizeof(dbms_name),
NULL);

if (strcmp((CHAR *)dbms_name, "MySQL") == 0 ||
strcmp((CHAR *)dbms_name, "MariaDB") == 0) {
cursor *c;

c = alloc_cursor();
if (c == NULL)
return DB_FAILED;

/* Set SQL ANSI_QUOTES MODE which allow to use double quotes instead of
* backticks */
SQLExecDirect(c->stmt, (SQLCHAR *)"SET SQL_MODE=ANSI_QUOTES", SQL_NTS);

G_debug(
3,
"db__driver_open_database(): Set ODBC %s DB SQL ANSI_QUOTES MODE",
dbms_name);

free_cursor(c);
}

return DB_OK;
}

Expand Down

0 comments on commit 5f6977e

Please sign in to comment.