浏览代码

db_mysql: set back tick as quoting char for table and column names

Daniel-Constantin Mierla 10 年之前
父节点
当前提交
cf1d885ae8
共有 1 个文件被更改,包括 8 次插入4 次删除
  1. 8 4
      modules/db_mysql/km_dbase.c

+ 8 - 4
modules/db_mysql/km_dbase.c

@@ -183,7 +183,7 @@ int db_mysql_submit_query_async(const db1_con_t* _h, const str* _s)
 	return 0;
 }
 
-
+static char *db_mysql_tquote = "`";
 /**
  * Initialize the database module.
  * No function should be called before this
@@ -192,7 +192,10 @@ int db_mysql_submit_query_async(const db1_con_t* _h, const str* _s)
  */
 db1_con_t* db_mysql_init(const str* _url)
 {
-	return db_do_init(_url, (void *)db_mysql_new_connection);
+	db1_con_t *c;
+	c = db_do_init(_url, (void *)db_mysql_new_connection);
+	if(c) CON_TQUOTE(c) = db_mysql_tquote;
+	return c;
 }
 
 
@@ -781,11 +784,12 @@ done:
 		return -1;
 	}
  
-	ret = snprintf(mysql_sql_buf, sql_buffer_size, "insert into %.*s (", CON_TABLE(_h)->len, CON_TABLE(_h)->s);
+	ret = snprintf(mysql_sql_buf, sql_buffer_size, "insert into %s%.*s%s (",
+			CON_TQUOTESZ(_h), CON_TABLE(_h)->len, CON_TABLE(_h)->s, CON_TQUOTESZ(_h));
 	if (ret < 0 || ret >= sql_buffer_size) goto error;
 	off = ret;
 
-	ret = db_print_columns(mysql_sql_buf + off, sql_buffer_size - off, _k, _n);
+	ret = db_print_columns(mysql_sql_buf + off, sql_buffer_size - off, _k, _n, CON_TQUOTESZ(_h));
 	if (ret < 0) return -1;
 	off += ret;