diff --git a/gb.db.postgresql/src/main.c b/gb.db.postgresql/src/main.c index 8370e8445..5481f01ff 100644 --- a/gb.db.postgresql/src/main.c +++ b/gb.db.postgresql/src/main.c @@ -177,8 +177,8 @@ static char *get_quoted_table(const char *table) } else { - res = GB.TempString(NULL, len + 2); - sprintf(res, "%.*s.\"%s\"", (int)(point - table), table, point + 1); + res = GB.TempString(NULL, len + 4); + sprintf(res, "\"%.*s\".\"%s\"", (int)(point - table), table, point + 1); } return res; @@ -187,6 +187,7 @@ static char *get_quoted_table(const char *table) static bool get_table_schema(const char **table, char **schema) { char *point; + int len; //fprintf(stderr, "get_table_schema: %s\n", *table); @@ -201,14 +202,19 @@ static bool get_table_schema(const char **table, char **schema) point = strchr(*table, '.'); if (!point) { - //fprintf(stderr, "get_table_schema: -> No point\n"); *schema = "public"; - return FALSE; } - - *schema = GB.TempString(*table, point - *table); - *table = point + 1; - //fprintf(stderr, "get_table_schema: -> %s / %s\n", *schema, *table); + else + { + len = point - *table; + if (len >= 3 && **table == '"' && (*table)[len - 1] == '"') + *schema = GB.TempString(*table + 1, len - 2); + else + *schema = GB.TempString(*table, len); + + *table = point + 1; + } + return FALSE; } diff --git a/main/lib/db/main.c b/main/lib/db/main.c index 84287b351..1d071b570 100644 --- a/main/lib/db/main.c +++ b/main/lib/db/main.c @@ -613,14 +613,17 @@ char *DB_GetQuotedTable(DB_DRIVER *driver, DB_DATABASE *db, const char *table, i quote = (*driver->GetQuote)(); - res = GB.TempString(NULL, len + 2); if (!point) + { + res = GB.TempString(NULL, len + 2); sprintf(res, "%s%.*s%s", quote, len, table, quote); + } else { int len_schema = (int)(point - table); - sprintf(res, "%.*s.%s%.*s%s", len_schema, table, quote, len - len_schema - 1, point + 1, quote); + res = GB.TempString(NULL, len + 4); + sprintf(res, "%s%.*s%s.%s%.*s%s", quote, len_schema, table, quote, quote, len - len_schema - 1, point + 1, quote); } return res;