Correctly quote table names when using schemas.
[GB.DB] * BUG: Correctly quote table names when using schemas.
This commit is contained in:
parent
f0ad78cb1f
commit
87f546bb81
@ -531,9 +531,7 @@ static char *get_query(char *prefix, CCONNECTION *_object, char *table, int len_
|
||||
|
||||
q_add(prefix);
|
||||
q_add(" ");
|
||||
q_add(THIS->driver->GetQuote());
|
||||
q_add_length(table, len_table);
|
||||
q_add(THIS->driver->GetQuote());
|
||||
q_add(DB_GetQuotedTable(THIS->driver, &THIS->db, table, len_table));
|
||||
|
||||
if (query && len_query > 0)
|
||||
{
|
||||
@ -630,7 +628,7 @@ BEGIN_METHOD(CCONNECTION_quote, GB_STRING name; GB_BOOLEAN is_table)
|
||||
CHECK_OPEN();
|
||||
|
||||
if (VARGOPT(is_table, FALSE)) // && THIS->db.flags.schema)
|
||||
GB.ReturnNewZeroString(DB_GetQuotedTable(THIS->driver, &THIS->db, GB.ToZeroString(ARG(name))));
|
||||
GB.ReturnNewZeroString(DB_GetQuotedTable(THIS->driver, &THIS->db, STRING(name), LENGTH(name)));
|
||||
else
|
||||
{
|
||||
q_init();
|
||||
|
@ -668,7 +668,7 @@ BEGIN_METHOD_VOID(Result_Update)
|
||||
break;
|
||||
|
||||
q_add("INSERT INTO ");
|
||||
q_add(DB_GetQuotedTable(THIS->driver, DB_CurrentDatabase, info->table));
|
||||
q_add(DB_GetQuotedTable(THIS->driver, DB_CurrentDatabase, info->table, -1));
|
||||
q_add(" ( ");
|
||||
|
||||
comma = FALSE;
|
||||
@ -724,7 +724,7 @@ BEGIN_METHOD_VOID(Result_Update)
|
||||
break;
|
||||
|
||||
q_add("UPDATE ");
|
||||
q_add(DB_GetQuotedTable(THIS->driver, DB_CurrentDatabase, info->table));
|
||||
q_add(DB_GetQuotedTable(THIS->driver, DB_CurrentDatabase, info->table, -1));
|
||||
q_add(" SET ");
|
||||
|
||||
comma = FALSE;
|
||||
@ -780,7 +780,7 @@ BEGIN_METHOD(Result_Delete, GB_BOOLEAN keep)
|
||||
case RESULT_EDIT:
|
||||
|
||||
q_add("DELETE FROM ");
|
||||
q_add(DB_GetQuotedTable(THIS->driver, DB_CurrentDatabase, info->table));
|
||||
q_add(DB_GetQuotedTable(THIS->driver, DB_CurrentDatabase, info->table, -1));
|
||||
q_add(" WHERE ");
|
||||
q_add(THIS->edit);
|
||||
|
||||
|
@ -23,7 +23,7 @@ Active=4
|
||||
File[2]=".src/Connections.class:40.71"
|
||||
Count=4
|
||||
File[3]=".src/Connection.class:21.25"
|
||||
File[4]=".src/SQLRequest.class:11.73"
|
||||
File[4]=".src/SQLRequest.class:26.156"
|
||||
|
||||
[Watches]
|
||||
Count=0
|
||||
|
@ -593,31 +593,34 @@ DB_DATABASE *DB_GetCurrent()
|
||||
return DB_CurrentDatabase;
|
||||
}
|
||||
|
||||
char *DB_GetQuotedTable(DB_DRIVER *driver, DB_DATABASE *db, const char *table)
|
||||
char *DB_GetQuotedTable(DB_DRIVER *driver, DB_DATABASE *db, const char *table, int len)
|
||||
{
|
||||
int len;
|
||||
char *point = NULL;
|
||||
char *res;
|
||||
const char *quote;
|
||||
|
||||
if (!table || !*table)
|
||||
if (!table)
|
||||
return "";
|
||||
|
||||
if (len < 0)
|
||||
len = strlen(table);
|
||||
|
||||
if (len == 0)
|
||||
return "";
|
||||
|
||||
len = strlen(table);
|
||||
if (db->flags.schema)
|
||||
point = index(table, '.');
|
||||
|
||||
quote = (*driver->GetQuote)();
|
||||
|
||||
res = GB.TempString(NULL, len + 2);
|
||||
|
||||
if (!point)
|
||||
{
|
||||
res = GB.TempString(NULL, len + 2);
|
||||
sprintf(res, "%s%s%s", quote, table, quote);
|
||||
}
|
||||
sprintf(res, "%s%.*s%s", quote, len, table, quote);
|
||||
else
|
||||
{
|
||||
res = GB.TempString(NULL, len + 2);
|
||||
sprintf(res, "%.*s.%s%s%s", (int)(point - table), table, quote, point + 1, quote);
|
||||
int len_schema = (int)(point - table);
|
||||
sprintf(res, "%.*s.%s%.*s%s", len_schema, table, quote, len - len_schema - 1, point + 1, quote);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -41,7 +41,7 @@ bool DB_Open(DB_DESC *desc, DB_DRIVER **driver, DB_DATABASE *db);
|
||||
char *DB_MakeQuery(DB_DRIVER *driver, const char *pattern, int len, int narg, GB_VALUE *arg);
|
||||
void DB_Format(DB_DRIVER *driver, GB_VALUE *arg, DB_FORMAT_CALLBACK func);
|
||||
void DB_FormatVariant(DB_DRIVER *driver, GB_VARIANT_VALUE *arg, DB_FORMAT_CALLBACK func);
|
||||
char *DB_GetQuotedTable(DB_DRIVER *driver, DB_DATABASE *db, const char *table);
|
||||
char *DB_GetQuotedTable(DB_DRIVER *driver, DB_DATABASE *db, const char *table, int len_table);
|
||||
|
||||
void DB_LowerString(char *s);
|
||||
int DB_CheckNameWith(const char *name, const char *msg, const char *more);
|
||||
|
Loading…
x
Reference in New Issue
Block a user