[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
This commit is contained in:
parent
770042a260
commit
0fd0ff44fe
2 changed files with 29 additions and 36 deletions
|
@ -455,16 +455,19 @@ const field_value & Dataset::get_field_value(const char *f_name)
|
||||||
for (uint i = 0; i < edit_object->size(); i++)
|
for (uint i = 0; i < edit_object->size(); i++)
|
||||||
if ((*edit_object)[i].props.name == f_name)
|
if ((*edit_object)[i].props.name == f_name)
|
||||||
return (*edit_object)[i].val;
|
return (*edit_object)[i].val;
|
||||||
GB.Error("Field not found: %s", f_name);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
for (uint i = 0; i < fields_object->size(); i++)
|
for (uint i = 0; i < fields_object->size(); i++)
|
||||||
if ((*fields_object)[i].props.name == f_name)
|
if ((*fields_object)[i].props.name == f_name)
|
||||||
return (*fields_object)[i].val;
|
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;
|
return fv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -325,10 +325,12 @@ static int callback(void *res_ptr, int ncol, char **reslt, char **cols, sqlite3_
|
||||||
//Tables tables;
|
//Tables tables;
|
||||||
//Tables::iterator it;
|
//Tables::iterator it;
|
||||||
char *item;
|
char *item;
|
||||||
|
char *last_table;
|
||||||
char *table;
|
char *table;
|
||||||
const char *type;
|
const char *type;
|
||||||
bool has_table = false;
|
bool need_table = false;
|
||||||
|
|
||||||
|
last_table = NULL;
|
||||||
result_set *r = (result_set *) res_ptr; //dynamic_cast<result_set*>(res_ptr);
|
result_set *r = (result_set *) res_ptr; //dynamic_cast<result_set*>(res_ptr);
|
||||||
int sz = r->records.size();
|
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));*/
|
fprintf(stderr, "--> %s\n", sqlite3_column_decltype(stmt, i));*/
|
||||||
|
|
||||||
item = strchr(cols[i], (int) '.');
|
item = strchr(cols[i], (int) '.');
|
||||||
if (!item)
|
if (!item) // No table info in field name
|
||||||
{ /* Field does not include table info */
|
{
|
||||||
item = cols[i];
|
table = (char *)"";
|
||||||
r->record_header[i].name = item; //NG
|
r->record_header[i].name = cols[i];
|
||||||
table = NULL;
|
|
||||||
r->record_header[i].field_table = "";
|
r->record_header[i].field_table = "";
|
||||||
}
|
}
|
||||||
else
|
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]);
|
table = GB.NewString(cols[i], strchr(cols[i], (int) '.') - cols[i]);
|
||||||
r->record_header[i].name = item + 1;
|
r->record_header[i].name = item + 1;
|
||||||
r->record_header[i].field_table = table;
|
r->record_header[i].field_table = table;
|
||||||
has_table = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
if (!need_table)
|
||||||
if (!table)
|
|
||||||
{
|
{
|
||||||
/* Field does not contain table info,
|
if (!last_table)
|
||||||
* 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 (strcmp((*it).data(), table) == 0)
|
last_table = table;
|
||||||
TableRegistered = true;
|
table = NULL;
|
||||||
}
|
|
||||||
if (TableRegistered == false)
|
|
||||||
{
|
|
||||||
tables.push_back(table);
|
|
||||||
}
|
}
|
||||||
|
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++)
|
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;
|
r->record_header[i].type = type ? GetFieldType(type, &r->record_header[i].field_len) : ft_String;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Should table name be included in field name */
|
/* Should table name be included in field name (at least two different tables) */
|
||||||
if (has_table)
|
if (need_table)
|
||||||
r->record_header[i].name = cols[i];
|
r->record_header[i].name = cols[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -794,16 +782,18 @@ void SqliteDataset::make_deletion()
|
||||||
|
|
||||||
void SqliteDataset::fill_fields()
|
void SqliteDataset::fill_fields()
|
||||||
{
|
{
|
||||||
//cout <<"rr "<<result.records.size()<<"|" << frecno <<"\n";
|
|
||||||
if ((db == NULL) || (result.record_header.size() == 0)
|
if ((db == NULL) || (result.record_header.size() == 0)
|
||||||
|| (result.records.size() < (uint) frecno))
|
|| (result.records.size() < (uint) frecno))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (fields_object->size() == 0) // Filling columns name
|
if (fields_object->size() == 0) // Filling columns name
|
||||||
|
{
|
||||||
for (uint i = 0; i < result.record_header.size(); i++)
|
for (uint i = 0; i < result.record_header.size(); i++)
|
||||||
{
|
{
|
||||||
(*fields_object)[i].props = result.record_header[i];
|
(*fields_object)[i].props = result.record_header[i];
|
||||||
//(*edit_object)[i].props = result.record_header[i];
|
//(*edit_object)[i].props = result.record_header[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Filling result
|
//Filling result
|
||||||
if (result.records.size() != 0)
|
if (result.records.size() != 0)
|
||||||
|
|
Loading…
Reference in a new issue