diff --git a/gb.db.mysql/src/main.c b/gb.db.mysql/src/main.c index 265dc1e07..d9590a555 100644 --- a/gb.db.mysql/src/main.c +++ b/gb.db.mysql/src/main.c @@ -591,25 +591,26 @@ static int do_query_cached(DB_DATABASE *db, const char *error, MYSQL_RES **pres, } -/* Internal function to return database version number as a XXYYZZ integer number*/ +// Internal function to get database version -static int db_version(DB_DATABASE *db) +static void init_version(DB_DATABASE *db) { - //Check db version - const char *vquery = "select left(version(),6)"; - long dbversion =0; + const char *query = "select version()"; + char *version; + uint verMain, verMajor, verMinor; MYSQL_RES *res; - MYSQL_ROW row; - if (!do_query(db, NULL, &res, vquery, 0)) + if (!do_query(db, NULL, &res, query, 0)) { - unsigned int verMain, verMajor, verMinor; - row = mysql_fetch_row(res); - sscanf(row[0],"%2u.%2u.%2u", &verMain, &verMajor, &verMinor); - dbversion = ((verMain * 10000) + (verMajor * 100) + verMinor); + version = mysql_fetch_row(res)[0]; + + db->full_version = GB.NewZeroString(version); + + sscanf(version, "%2u.%2u.%2u", &verMain, &verMajor, &verMinor); + db->version = ((verMain * 10000) + (verMajor * 100) + verMinor); + mysql_free_result(res); } - return dbversion; } /* Search in the first column a result for a specific name */ @@ -975,7 +976,7 @@ static int open_database(DB_DESC *desc, DB_DATABASE *db) } db->handle = conn; - db->version = db_version(db); + init_version(db); set_character_set(db); diff --git a/gb.db.odbc/src/main.c b/gb.db.odbc/src/main.c index a82b67979..f12570d44 100644 --- a/gb.db.odbc/src/main.c +++ b/gb.db.odbc/src/main.c @@ -858,7 +858,9 @@ fflush(stderr); odbc->user_name = malloc(sizeof(char) * strlen(user)); strcpy(odbc->user_name, user); + // TODO: Use SQLGetInfo() to retrieve the DBMS version string db->version = 3; + db->full_version = GB.NewZeroString("3"); retcode = SQLGetFunctions(odbc->odbcHandle, SQL_API_SQLFETCHSCROLL, &odbc->drvrCanFetchScroll); if (!SQL_SUCCEEDED(retcode)) diff --git a/gb.db.postgresql/src/main.c b/gb.db.postgresql/src/main.c index 2291b8052..d42795ac5 100644 --- a/gb.db.postgresql/src/main.c +++ b/gb.db.postgresql/src/main.c @@ -544,14 +544,13 @@ static int do_query(DB_DATABASE *db, const char *error, PGresult **pres, const c return ret; } -/* Internal function to check database version number */ +// Internal function to get database version -static int db_version(DB_DATABASE *db) +static void init_version(DB_DATABASE *db) { unsigned int verMain = 0, verMajor = 0, verMinor = 0; const char *query = "select version()"; const char *version; - int dbversion = 0; PGresult *res; if (!do_query(db, NULL, &res, query, 0)) @@ -563,14 +562,14 @@ static int db_version(DB_DATABASE *db) if (*version) { + db->full_version = GB.NewZeroString(version); + sscanf(version, "%2u.%2u.%2u", &verMain, &verMajor, &verMinor); - dbversion = ((verMain * 10000) + (verMajor * 100) + verMinor); + db->version = ((verMain * 10000) + (verMajor * 100) + verMinor); } PQclear(res); } - - return dbversion; } /* Internal function that fills field information from a schema request. @@ -785,7 +784,9 @@ static int open_database(DB_DESC *desc, DB_DATABASE *db) /* get version */ db->handle = conn; - db->version = db_version(db); + + init_version(db); + db->data = (void *)0; // transaction level if (db->version >= 90000) @@ -817,6 +818,7 @@ static int open_database(DB_DESC *desc, DB_DATABASE *db) //db->flags.no_case = TRUE; db->flags.schema = TRUE; db->flags.no_collation = db->version < 90100; + db->flags.no_returning = db->version < 80200; // It seems that RETURNING has been introduced in PostgreSQL 8.2 /* encoding */ diff --git a/gb.db.sqlite2/src/main.cpp b/gb.db.sqlite2/src/main.cpp index f53ecff8b..b2b5686b2 100644 --- a/gb.db.sqlite2/src/main.cpp +++ b/gb.db.sqlite2/src/main.cpp @@ -484,17 +484,22 @@ static int WalkDirectory(const char *dir, char ***databases) return GB.Count(databases); } -/* Internal function to check database version number */ -int db_version() +// Internal function to get database version + +static int init_version(DB_DATABASE *db) { - //Check db version - int dbversion =0; + char *version; + int dbversion = 0; unsigned int verMain, verMajor, verMinor; - sscanf(sqlite_version,"%2u.%2u.%2u", &verMain, &verMajor, &verMinor); - dbversion = ((verMain * 10000) + (verMajor * 100) + verMinor); - return dbversion; + + version = sqlite3_libversion(); + db->full_version = GB.NewZeroString(version); + + sscanf(version, "%2u.%2u.%2u", &verMain, &verMajor, &verMinor); + db->version = ((verMain * 10000) + (verMajor * 100) + verMinor); } + /***************************************************************************** get_quote() @@ -581,7 +586,7 @@ static int open_database(DB_DESC *desc, DB_DATABASE *db) db->charset = GB.NewZeroString(strcmp(sqlite_encoding, "iso8859") == 0 ? "ISO-8859-1" : "UTF-8"); /* set dbversion */ - db->version = db_version(); + init_version(db); /* flags */ db->flags.no_table_type = TRUE; @@ -589,6 +594,7 @@ static int open_database(DB_DESC *desc, DB_DATABASE *db) db->flags.no_blob = TRUE; db->flags.no_nest = TRUE; db->flags.no_collation = TRUE; + db->flags.no_returning = TRUE; db->db_name_char = "."; diff --git a/gb.db.sqlite3/src/main.c b/gb.db.sqlite3/src/main.c index dac8806cc..53ae6cf45 100644 --- a/gb.db.sqlite3/src/main.c +++ b/gb.db.sqlite3/src/main.c @@ -500,19 +500,22 @@ static int walk_directory(const char *dir, char ***databases) } -/* Internal function to check database version number */ -static int db_version() +// Internal function to get database version + +static void init_version(DB_DATABASE *db) { - //Check db version - int dbversion = 0; + const char *version; unsigned int verMain, verMajor, verMinor; - sscanf(sqlite3_libversion(), "%2u.%2u.%2u", &verMain, &verMajor, &verMinor); - dbversion = ((verMain * 10000) + (verMajor * 100) + verMinor); - return dbversion; + version = sqlite3_libversion(); + db->full_version = GB.NewZeroString(version); + + sscanf(version, "%2u.%2u.%2u", &verMain, &verMajor, &verMinor); + db->version = ((verMain * 10000) + (verMajor * 100) + verMinor); } -/* Get the schema of a table */ +// Get the schema of a table + static char *get_table_schema(DB_DATABASE *db, const char *table) { char *schema = NULL; @@ -598,8 +601,8 @@ static int open_database(DB_DESC *desc, DB_DATABASE *db) } db->handle = conn; - /* set dbversion */ - db->version = db_version(); + + init_version(db); if (do_query(db, "Unable to initialize connection: &1", NULL, "PRAGMA empty_result_callbacks = ON", 0)) goto CANNOT_OPEN; @@ -623,6 +626,7 @@ static int open_database(DB_DESC *desc, DB_DATABASE *db) /* flags */ db->flags.no_table_type = TRUE; db->flags.no_nest = TRUE; + db->flags.no_returning = TRUE; //db->version < 33500; // RETURNING keyword has been introduced in SQLite 3.35.0 db->db_name_char = ".";