[GB.DB.SQLITE3]

* BUG: Handle double quotes in table schemas, when detecting auto-increment
  fields.


git-svn-id: svn://localhost/gambas/trunk@7534 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2015-12-22 00:39:47 +00:00
parent c2fb96c345
commit bf3b070c70

View file

@ -180,7 +180,7 @@ static void conv_data(const char *data, GB_VARIANT_VALUE * val, int type)
break; break;
default: default:
val->type = GB_T_CSTRING; val->type = GB_T_CSTRING;
val->value._string = (char *)data; val->value._string = (char *)data;
} }
@ -274,13 +274,13 @@ static int do_query(DB_DATABASE *db, const char *error, SQLITE_RESULT **pres, co
max_retry = 600; // 120 s max max_retry = 600; // 120 s max
else else
max_retry = 0; max_retry = 0;
for(;;) for(;;)
{ {
err = 0; err = 0;
res = sqlite_query_exec(conn, query, _need_field_type); res = sqlite_query_exec(conn, query, _need_field_type);
if (res) if (res)
{ {
if (pres) if (pres)
@ -289,19 +289,19 @@ static int do_query(DB_DATABASE *db, const char *error, SQLITE_RESULT **pres, co
sqlite_query_free(res); sqlite_query_free(res);
break; break;
} }
err = conn->error; err = conn->error;
if (err != SQLITE_BUSY || retry >= max_retry) if (err != SQLITE_BUSY || retry >= max_retry)
{ {
GB.Error(error, sqlite_get_error_message(conn)); GB.Error(error, sqlite_get_error_message(conn));
break; break;
} }
retry++; retry++;
usleep(200000); usleep(200000);
} }
db->error = err; db->error = err;
_need_field_type = FALSE; _need_field_type = FALSE;
return err != 0; return err != 0;
@ -479,11 +479,11 @@ static int walk_directory(const char *dir, char ***databases)
return -1; return -1;
} }
while ((entry = readdir(dp)) != NULL) while ((entry = readdir(dp)) != NULL)
{ {
stat(entry->d_name, &statbuf); stat(entry->d_name, &statbuf);
if (S_ISREG(statbuf.st_mode)) if (S_ISREG(statbuf.st_mode))
{ {
if (is_database_file(entry->d_name)) if (is_database_file(entry->d_name))
*(char **)GB.Add(databases) = GB.NewZeroString(entry->d_name); *(char **)GB.Add(databases) = GB.NewZeroString(entry->d_name);
@ -492,10 +492,10 @@ static int walk_directory(const char *dir, char ***databases)
// BM: you must call closedir() // BM: you must call closedir()
closedir(dp); closedir(dp);
if (chdir(cwd)) if (chdir(cwd))
fprintf(stderr, "gb.db.sqlite3: warning: chdir: %s\n", strerror(errno)); fprintf(stderr, "gb.db.sqlite3: warning: chdir: %s\n", strerror(errno));
return GB.Count(databases); return GB.Count(databases);
} }
@ -839,7 +839,7 @@ static void query_release(DB_RESULT result, DB_INFO * info)
<next> is a boolean telling if we want the next row. <next> is a boolean telling if we want the next row.
This function must return DB_OK, DB_ERROR or DB_NO_DATA This function must return DB_OK, DB_ERROR or DB_NO_DATA
This function must use GB.StoreVariant() to store the value in the This function must use GB.StoreVariant() to store the value in the
buffer. buffer.
@ -857,7 +857,7 @@ static int query_fill(DB_DATABASE *db, DB_RESULT result, int pos, GB_VARIANT_VAL
for (i = 0; i < res->ncol; i++) for (i = 0; i < res->ncol; i++)
{ {
type = res->types[i]; type = res->types[i];
if (type == DB_T_BLOB) if (type == DB_T_BLOB)
data = NULL; data = NULL;
else else
@ -1135,7 +1135,7 @@ static int table_index(DB_DATABASE * db, const char *table, DB_INFO * info)
/* Index primaire */ /* Index primaire */
info->nindex = 0; info->nindex = 0;
if (do_query(db, "Unable to get primary index: &1", &res, qindex1, 1, table)) if (do_query(db, "Unable to get primary index: &1", &res, qindex1, 1, table))
return TRUE; return TRUE;
@ -1468,7 +1468,7 @@ static int table_is_system(DB_DATABASE * db, const char *table)
/***************************************************************************** /*****************************************************************************
table_type() table_type()
Not Valid in Sqlite Not Valid in Sqlite
<handle> is the database handle. <handle> is the database handle.
@ -1786,7 +1786,7 @@ static int field_info(DB_DATABASE *db, const char *table, const char *field, DB_
fprintf(stderr, "_fieldType = %s\n", _fieldType); fprintf(stderr, "_fieldType = %s\n", _fieldType);
autoinc = strstr(_fieldType, "INTEGER") && strstr(_fieldType, "AUTOINCREMENT"); autoinc = strstr(_fieldType, "INTEGER") && strstr(_fieldType, "AUTOINCREMENT");
}*/ }*/
autoinc = FALSE; autoinc = FALSE;
info->collation = NULL; info->collation = NULL;
@ -1814,7 +1814,7 @@ static int field_info(DB_DATABASE *db, const char *table, const char *field, DB_
while (p < p2 && *p == ' ') while (p < p2 && *p == ' ')
p++; p++;
if (*p == '\'') if (*p == '\'' || *p == '"')
p++; p++;
len = strlen(_fieldName); len = strlen(_fieldName);
@ -1831,7 +1831,7 @@ static int field_info(DB_DATABASE *db, const char *table, const char *field, DB_
len = p2 - p; len = p2 - p;
if (len <= 0) if (len <= 0)
break; break;
field_desc = GB.NewString(p, len); field_desc = GB.NewString(p, len);
if (strstr(_fieldType, "INTEGER")) if (strstr(_fieldType, "INTEGER"))
@ -1859,7 +1859,7 @@ static int field_info(DB_DATABASE *db, const char *table, const char *field, DB_
} }
} }
if (!_table_schema) if (!_table_schema)
GB.FreeString(&schema); GB.FreeString(&schema);
@ -2313,7 +2313,7 @@ _CREATE_DATABASE:
sqlite_close_database(conn); sqlite_close_database(conn);
db->handle = save; db->handle = save;
return FALSE; return FALSE;
} }