From cf2abcd76a50f6d0a1a928b9632b733d35aad3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Fri, 8 Jan 2016 14:41:23 +0000 Subject: [PATCH] [GB.DB] * BUG: Take case-sensitive databases like postgresql into account in index fields. git-svn-id: svn://localhost/gambas/trunk@7564 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/lib/db/CField.c | 12 ++++++++++-- main/lib/db/CIndex.c | 20 +++++++++++++------- main/lib/db/main.h | 1 + 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/main/lib/db/CField.c b/main/lib/db/CField.c index 252f06bea..2c60e5b7c 100644 --- a/main/lib/db/CField.c +++ b/main/lib/db/CField.c @@ -44,8 +44,16 @@ static bool exist_field(CTABLE *table, const char *name) { for (fp = table->new_fields; fp; fp = fp->next) { - if (!strcmp(fp->name, name)) - return TRUE; + if (table->conn->db.flags.no_case) + { + if (!strcasecmp(fp->name, name)) + return TRUE; + } + else + { + if (!strcmp(fp->name, name)) + return TRUE; + } } return FALSE; diff --git a/main/lib/db/CIndex.c b/main/lib/db/CIndex.c index 46c88e1d3..cec2e2d3c 100644 --- a/main/lib/db/CIndex.c +++ b/main/lib/db/CIndex.c @@ -141,10 +141,10 @@ BEGIN_PROPERTY(CINDEX_fields) GB_ARRAY array; char *fields; char *name; - + fields = GB.NewZeroString(THIS->info.fields); GB.Array.New(&array, GB_T_STRING, 0); - + name = strtok(fields, ","); while (name) { @@ -214,6 +214,7 @@ BEGIN_METHOD(CINDEX_add, GB_STRING name; GB_OBJECT fields; GB_BOOLEAN unique) DB_INDEX info; int i; GB_ARRAY fields; + char *field; if (DB_CheckNameWith(name, "index", ".")) return; @@ -222,24 +223,29 @@ BEGIN_METHOD(CINDEX_add, GB_STRING name; GB_OBJECT fields; GB_BOOLEAN unique) return; info.name = name; - + fields = (GB_ARRAY)VARG(fields); q_init(); for (i = 0; i < GB.Array.Count(fields); i++) { + field = *(char **)GB.Array.Get(fields, i); + if (i > 0) q_add(","); - + q_add(table->driver->GetQuote()); - q_add(*(char **)GB.Array.Get(fields, i)); + if (table->conn->db.flags.no_case) + q_add_lower(field); + else + q_add(field); q_add(table->driver->GetQuote()); } - + info.fields = q_steal(); info.unique = VARGOPT(unique, FALSE); table->driver->Index.Create(&table->conn->db, table->name, name, &info); - + GB.FreeString(&info.fields); END_METHOD diff --git a/main/lib/db/main.h b/main/lib/db/main.h index 9b1c7b78d..e394cf564 100644 --- a/main/lib/db/main.h +++ b/main/lib/db/main.h @@ -55,6 +55,7 @@ void DB_TryAnother(const char *); void q_init(void); void q_add(const char *str); +void q_add_lower(const char *str); void q_add_length(const char *str, int len); char *q_get(void); char *q_steal(void);