From 0fd0ff44fea7f6df87f9785d1479763ea59bc04e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Tue, 3 Dec 2013 01:01:14 +0000 Subject: [PATCH] [GB.DB.SQLITE3] * BUG: Correctly handle requests returning only one table name inside field names. git-svn-id: svn://localhost/gambas/trunk@5976 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- gb.db.sqlite3/src/dataset.cpp | 11 +++--- gb.db.sqlite3/src/sqlitedataset.cpp | 54 ++++++++++++----------------- 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/gb.db.sqlite3/src/dataset.cpp b/gb.db.sqlite3/src/dataset.cpp index 8d20dfe0b..538c4fda7 100644 --- a/gb.db.sqlite3/src/dataset.cpp +++ b/gb.db.sqlite3/src/dataset.cpp @@ -455,16 +455,19 @@ const field_value & Dataset::get_field_value(const char *f_name) for (uint i = 0; i < edit_object->size(); i++) if ((*edit_object)[i].props.name == f_name) return (*edit_object)[i].val; - GB.Error("Field not found: %s", f_name); } else + { for (uint i = 0; i < fields_object->size(); i++) if ((*fields_object)[i].props.name == f_name) return (*fields_object)[i].val; - GB.Error("Field not found: %s", f_name); - } + } + + GB.Error("Field not found: &1", f_name); + } + else + GB.Error("Dataset state is Inactive"); - GB.Error("Dataset state is Inactive"); return fv; } diff --git a/gb.db.sqlite3/src/sqlitedataset.cpp b/gb.db.sqlite3/src/sqlitedataset.cpp index 8daab6094..bf99f244d 100644 --- a/gb.db.sqlite3/src/sqlitedataset.cpp +++ b/gb.db.sqlite3/src/sqlitedataset.cpp @@ -325,10 +325,12 @@ static int callback(void *res_ptr, int ncol, char **reslt, char **cols, sqlite3_ //Tables tables; //Tables::iterator it; char *item; + char *last_table; char *table; const char *type; - bool has_table = false; + bool need_table = false; + last_table = NULL; result_set *r = (result_set *) res_ptr; //dynamic_cast(res_ptr); int sz = r->records.size(); @@ -343,11 +345,10 @@ static int callback(void *res_ptr, int ncol, char **reslt, char **cols, sqlite3_ fprintf(stderr, "--> %s\n", sqlite3_column_decltype(stmt, i));*/ item = strchr(cols[i], (int) '.'); - if (!item) - { /* Field does not include table info */ - item = cols[i]; - r->record_header[i].name = item; //NG - table = NULL; + if (!item) // No table info in field name + { + table = (char *)""; + r->record_header[i].name = cols[i]; r->record_header[i].field_table = ""; } else @@ -355,38 +356,25 @@ static int callback(void *res_ptr, int ncol, char **reslt, char **cols, sqlite3_ table = GB.NewString(cols[i], strchr(cols[i], (int) '.') - cols[i]); r->record_header[i].name = item + 1; r->record_header[i].field_table = table; - has_table = true; } - #if 0 - if (!table) + if (!need_table) { - /* Field does not contain table info, - * so let's default to string. This - * has probably happened because aliases - * are being used */ - } - else - { - /* Check Table Name and add to list */ - bool TableRegistered = false; - - for (it = tables.begin(); it != tables.end(); it++) + if (!last_table) { - if (strcmp((*it).data(), table) == 0) - TableRegistered = true; - } - if (TableRegistered == false) - { - tables.push_back(table); + last_table = table; + table = NULL; } + else if (strcmp(last_table, table)) + need_table = true; } - #endif - GB.FreeString(&table); //from strdup + if (table && *table) + GB.FreeString(&table); } - //SetFieldType(r, tables); // Set all the field types + if (*last_table) + GB.FreeString(&last_table); for (int i = 0; i < ncol; i++) { @@ -396,8 +384,8 @@ static int callback(void *res_ptr, int ncol, char **reslt, char **cols, sqlite3_ r->record_header[i].type = type ? GetFieldType(type, &r->record_header[i].field_len) : ft_String; } - /* Should table name be included in field name */ - if (has_table) + /* Should table name be included in field name (at least two different tables) */ + if (need_table) r->record_header[i].name = cols[i]; } } @@ -794,16 +782,18 @@ void SqliteDataset::make_deletion() void SqliteDataset::fill_fields() { - //cout <<"rr "<size() == 0) // Filling columns name + { for (uint i = 0; i < result.record_header.size(); i++) { (*fields_object)[i].props = result.record_header[i]; //(*edit_object)[i].props = result.record_header[i]; } + } //Filling result if (result.records.size() != 0)