[libgda/LIBGDA_4.0] Make it possible to use a system installed SQLite, and fixed bug #578748
- From: Vivien Malerba <vivien src gnome org>
- To: svn-commits-list gnome org
- Subject: [libgda/LIBGDA_4.0] Make it possible to use a system installed SQLite, and fixed bug #578748
- Date: Fri, 17 Apr 2009 17:04:21 -0400 (EDT)
commit 56e063753fdc5f7e869c4b459b16bd961922a792
Author: Vivien Malerba <malerba gnome-db org>
Date: Fri Apr 17 22:59:14 2009 +0200
Make it possible to use a system installed SQLite, and fixed bug #578748
* providers/postgres/gda-postgres-provider.c: fix for bug #578748
* libgda/sqlite/gda-sqlite.h:
* libgda/sqlite/gda-sqlite-meta.c:
* libgda/sqlite/gda-sqlite-provider.c: make the SQLite provider
compile with a system installed SQLite
* configure.in: a system installed SQLite is now only searched
for if the --enable-system-sqlite option is passed, and the presence of the
sqlite3CreateFunc symbol is not anymore required. The only drawback of using a
system installed SQLite is that meta data regarding functions will not be
available
* libgda/handlers/gda-handler-time.c: fix mem leak
---
ChangeLog | 13 ++
configure.in | 33 +++---
libgda/handlers/gda-handler-time.c | 1 +
libgda/sqlite/gda-sqlite-meta.c | 154 +++++++-----------------
libgda/sqlite/gda-sqlite-provider.c | 179 ----------------------------
libgda/sqlite/gda-sqlite.h | 2 -
providers/postgres/gda-postgres-provider.c | 5 +-
7 files changed, 78 insertions(+), 309 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fb11b6e..ff06383 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2009-04-17 Vivien Malerba <malerba gnome-db org>
+
+ * providers/postgres/gda-postgres-provider.c: fix for bug #578748
+ * libgda/sqlite/gda-sqlite.h:
+ * libgda/sqlite/gda-sqlite-meta.c:
+ * libgda/sqlite/gda-sqlite-provider.c: make the SQLite provider
+ compile with a system installed SQLite
+ * configure.in: a system installed SQLite is now only searched for if the
+ --enable-system-sqlite option is passed, and the presence of the sqlite3CreateFunc
+ symbol is not anymore required. The only drawback of using a system installed
+ SQLite is that meta data regarding functions will not be available
+ * libgda/handlers/gda-handler-time.c: fix mem leak
+
2009-04-07 Vivien Malerba <malerba gnome-db org>
* configure.in:
diff --git a/configure.in b/configure.in
index 72b5c94..7434cf6 100644
--- a/configure.in
+++ b/configure.in
@@ -1102,31 +1102,30 @@ if test x"$platform_win32" = "xyes"
then
AM_CONDITIONAL(HAVE_SQLITE, 0)
else
- SQLITE_MODULES="sqlite3 >= 3.6.0"
- PKG_CHECK_MODULES(SQLITE, $SQLITE_MODULES, have_sqlite=yes, have_sqlite=no)
- if test x"$have_sqlite" = "xyes"
- then
- AC_CHECK_LIB(sqlite3, sqlite3_table_column_metadata,[sqlite3_api=1], [sqlite3_api=0], $SQLITE_CFLAGS $SQLITE_LIBS)
+ AC_ARG_ENABLE(system-sqlite,
+ [ --enable-system-sqlite Use SQLite installed on the system [default=no]],
+ use_syst_sqlite="Yes", use_syst_sqlite="No")
+
+ if test "x$use_syst_sqlite" = "xYes"; then
+ SQLITE_MODULES="sqlite3 >= 3.6.11"
+ PKG_CHECK_MODULES(SQLITE, $SQLITE_MODULES, have_sqlite=yes, have_sqlite=no)
+ if test x"$have_sqlite" = "xyes"
+ then
+ AC_CHECK_LIB(sqlite3, sqlite3_table_column_metadata,[sqlite3_api=1], [sqlite3_api=0], $SQLITE_CFLAGS $SQLITE_LIBS)
- if test $sqlite3_api = 0
- then
- AC_MSG_RESULT([Installed SQLite was not compiled with the SQLITE_ENABLE_COLUMN_METADATA, using embedded SQLite])
- have_sqlite=no
- else
- AC_CHECK_LIB(sqlite3, sqlite3CreateFunc,[sqlite3_api=1], [sqlite3_api=0], $SQLITE_CFLAGS $SQLITE_LIBS)
if test $sqlite3_api = 0
- then
- AC_MSG_RESULT([Could not find the sqlite3CreateFunc symbol in installed SQLite library, using embedded SQLite])
+ then
+ AC_MSG_RESULT([Installed SQLite was not compiled with the SQLITE_ENABLE_COLUMN_METADATA, using embedded SQLite])
have_sqlite=no
- else
- AC_MSG_RESULT(Using this version of SQLite)
+ else
+ AC_MSG_RESULT(Note: using system installed version of SQLite, meta data for functions will not be available)
have_sqlite=yes
SQLITE_CFLAGS="$SQLITE_CFLAGS -DHAVE_SQLITE"
AC_SUBST(SQLITE_CFLAGS)
AC_SUBST(SQLITE_LIBS)
AC_SUBST(SQLITE_VERS)
- fi
- fi
+ fi
+ fi
fi
AM_CONDITIONAL(HAVE_SQLITE, test x"$have_sqlite" = "xyes")
fi
diff --git a/libgda/handlers/gda-handler-time.c b/libgda/handlers/gda-handler-time.c
index f56c336..7a4bbeb 100644
--- a/libgda/handlers/gda-handler-time.c
+++ b/libgda/handlers/gda-handler-time.c
@@ -273,6 +273,7 @@ handler_compute_locale (GdaHandlerTime *hdl)
date = g_date_new_dmy (4, 7, 1976); /* Same date used by GLib */
g_date_strftime (buf, 127, "%x", date);
+ g_date_free (date);
/* 1st number */
ptr = buf;
diff --git a/libgda/sqlite/gda-sqlite-meta.c b/libgda/sqlite/gda-sqlite-meta.c
index 5055383..106ba28 100644
--- a/libgda/sqlite/gda-sqlite-meta.c
+++ b/libgda/sqlite/gda-sqlite-meta.c
@@ -2038,124 +2038,62 @@ _gda_sqlite_meta_routines (GdaServerProvider *prov, GdaConnection *cnc,
const GValue *routine_catalog, const GValue *routine_schema,
const GValue *routine_name_n)
{
- SqliteConnectionData *cdata;
gboolean retval = TRUE;
+
+#ifndef HAVE_SQLITE
+ /* get list of procedures */
+ SqliteConnectionData *cdata;
+ GdaDataModel *tmpmodel, *mod_model;
+ gint i, nrows;
cdata = (SqliteConnectionData*) gda_connection_internal_get_provider_data (cnc);
if (!cdata)
return FALSE;
+
+ tmpmodel = (GdaDataModel *) gda_connection_statement_execute (cnc, internal_stmt[I_PRAGMA_PROCLIST],
+ NULL, GDA_STATEMENT_MODEL_RANDOM_ACCESS,
+ NULL, error);
+ if (!tmpmodel)
+ return FALSE;
- if (cdata->functions_model) {
- /* use cdata->functions_model and cdata->aggregates_model */
- GdaDataModel *mod_model;
- mod_model = gda_meta_store_create_modify_data_model (store, context->table_name);
- g_assert (mod_model);
-
- if (cdata->functions_model) {
- gint i, nrows;
- for (i = 0; i < nrows; i++) {
- const GValue *cv0, *cv2, *cv3;
- cv0 = gda_data_model_get_value_at (cdata->functions_model, 0, i, error);
- if (!cv0) {
- retval = FALSE;
- break;
- }
- cv2 = gda_data_model_get_value_at (cdata->functions_model, 1, i, error);
- if (!cv2) {
- retval = FALSE;
- break;
- }
- cv3 = gda_data_model_get_value_at (cdata->functions_model, 2, i, error);
- if (!cv3) {
- retval = FALSE;
- break;
- }
- if ((!routine_name_n || (routine_name_n && !gda_value_compare (routine_name_n, cv0)))
- && ! fill_routines (mod_model, cv0, false_value, cv2, cv3, error)) {
- retval = FALSE;
- break;
- }
- }
+ mod_model = gda_meta_store_create_modify_data_model (store, context->table_name);
+ g_assert (mod_model);
+
+ nrows = gda_data_model_get_n_rows (tmpmodel);
+ for (i = 0; i < nrows; i++) {
+ const GValue *cv0, *cv1, *cv2, *cv3;
+ cv0 = gda_data_model_get_value_at (tmpmodel, 0, i, error);
+ if (!cv0) {
+ retval = FALSE;
+ break;
}
- if (cdata->aggregates_model) {
- gint i, nrows;
- for (i = 0; i < nrows; i++) {
- const GValue *cv0, *cv2, *cv3;
- cv0 = gda_data_model_get_value_at (cdata->aggregates_model, 0, i, error);
- if (!cv0) {
- retval = FALSE;
- break;
- }
- cv2 = gda_data_model_get_value_at (cdata->aggregates_model, 1, i, error);
- if (!cv2) {
- retval = FALSE;
- break;
- }
- cv3 = gda_data_model_get_value_at (cdata->aggregates_model, 2, i, error);
- if (!cv3) {
- retval = FALSE;
- break;
- }
- if ((!routine_name_n || (routine_name_n && !gda_value_compare (routine_name_n, cv0)))
- && ! fill_routines (mod_model, cv0, true_value, cv2, cv3, error)) {
- retval = FALSE;
- break;
- }
- }
+ cv1 = gda_data_model_get_value_at (tmpmodel, 1, i, error);
+ if (!cv1) {
+ retval = FALSE;
+ break;
}
-
- if (retval)
- retval = gda_meta_store_modify_with_context (store, context, mod_model, error);
- g_object_unref (mod_model);
- }
- else {
- /* get list of procedures */
- GdaDataModel *tmpmodel, *mod_model;
- gint i, nrows;
- tmpmodel = (GdaDataModel *) gda_connection_statement_execute (cnc, internal_stmt[I_PRAGMA_PROCLIST],
- NULL, GDA_STATEMENT_MODEL_RANDOM_ACCESS,
- NULL, error);
- if (!tmpmodel)
- return FALSE;
-
- mod_model = gda_meta_store_create_modify_data_model (store, context->table_name);
- g_assert (mod_model);
-
- nrows = gda_data_model_get_n_rows (tmpmodel);
- for (i = 0; i < nrows; i++) {
- const GValue *cv0, *cv1, *cv2, *cv3;
- cv0 = gda_data_model_get_value_at (tmpmodel, 0, i, error);
- if (!cv0) {
- retval = FALSE;
- break;
- }
- cv1 = gda_data_model_get_value_at (tmpmodel, 1, i, error);
- if (!cv1) {
- retval = FALSE;
- break;
- }
- cv2 = gda_data_model_get_value_at (tmpmodel, 2, i, error);
- if (!cv2) {
- retval = FALSE;
- break;
- }
- cv3 = gda_data_model_get_value_at (tmpmodel, 3, i, error);
- if (!cv3) {
- retval = FALSE;
- break;
- }
- if ((!routine_name_n || (routine_name_n && !gda_value_compare (routine_name_n, cv0)))
- && ! fill_routines (mod_model, cv0, cv1, cv2, cv3, error)) {
- retval = FALSE;
- break;
- }
+ cv2 = gda_data_model_get_value_at (tmpmodel, 2, i, error);
+ if (!cv2) {
+ retval = FALSE;
+ break;
+ }
+ cv3 = gda_data_model_get_value_at (tmpmodel, 3, i, error);
+ if (!cv3) {
+ retval = FALSE;
+ break;
+ }
+ if ((!routine_name_n || (routine_name_n && !gda_value_compare (routine_name_n, cv0)))
+ && ! fill_routines (mod_model, cv0, cv1, cv2, cv3, error)) {
+ retval = FALSE;
+ break;
}
-
- if (retval)
- retval = gda_meta_store_modify_with_context (store, context, mod_model, error);
- g_object_unref (mod_model);
- g_object_unref (tmpmodel);
}
+
+ if (retval)
+ retval = gda_meta_store_modify_with_context (store, context, mod_model, error);
+ g_object_unref (mod_model);
+ g_object_unref (tmpmodel);
+#endif
return retval;
}
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index 4bcd4a4..415fa5b 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -54,10 +54,6 @@
#define FILE_EXTENSION ".db"
static GStaticRecMutex cnc_mutex = G_STATIC_REC_MUTEX_INIT;
-#ifdef HAVE_SQLITE
-static SqliteConnectionData *opening_cdata = NULL;
-static GHashTable *db_connections_hash = NULL;
-#endif
/* TMP */
typedef struct {
@@ -495,149 +491,6 @@ gda_sqlite_provider_get_version (GdaServerProvider *provider)
return PACKAGE_VERSION;
}
-#ifndef G_OS_WIN32
-#ifdef HAVE_SQLITE
-static void
-add_g_list_row (gpointer data, GdaDataModelArray *recset)
-{
- GList *rowlist = data;
- GError *error = NULL;
- if (gda_data_model_append_values (GDA_DATA_MODEL (recset), rowlist, &error) < 0) {
- g_warning ("Data model append error: %s\n", error && error->message ? error->message : "no detail");
- g_error_free (error);
- }
- g_list_foreach (rowlist, (GFunc) gda_value_free, NULL);
- g_list_free (rowlist);
-}
-
-int sqlite3CreateFunc (sqlite3 *db, const char *name, int nArg, int eTextRep, void *data,
- void (*xFunc)(sqlite3_context*,int,sqlite3_value **),
- void (*xStep)(sqlite3_context*,int,sqlite3_value **),
- void (*xFinal)(sqlite3_context*))
-{
- SqliteConnectionData *cdata = NULL;
- gboolean is_func = FALSE;
- gboolean is_agg = FALSE;
- GdaDataModelArray *recset = NULL;
-
- static int (*func) (sqlite3 *, const char *, int, int, void *,
- void (*)(sqlite3_context*,int,sqlite3_value **),
- void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*)) = NULL;
-
- if (!func)
- func = (int (*) (sqlite3 *, const char *, int, int, void *,
- void (*)(sqlite3_context*,int,sqlite3_value **),
- void (*)(sqlite3_context*,int,sqlite3_value **),
- void (*)(sqlite3_context*))) dlsym (RTLD_NEXT, "sqlite3CreateFunc");
-
- /* try to find which SqliteConnectionData this concerns */
- if (db_connections_hash)
- cdata = g_hash_table_lookup (db_connections_hash, db);
- if (!cdata)
- cdata = opening_cdata;
- if (!cdata)
- return func (db, name, nArg, eTextRep, data, xFunc, xStep, xFinal);
-
- if (xFunc) {
- /* It's a function */
- recset = (GdaDataModelArray *) cdata->functions_model;
- if (!recset) {
- recset = GDA_DATA_MODEL_ARRAY (gda_data_model_array_new, 3);
- gda_column_set_description (0, "name");
- gda_column_set_name (0, "name");
- gda_column_set_g_type (0, G_TYPE_STRING);
- gda_column_set_description (1, "nargs");
- gda_column_set_name (1, "nargs");
- gda_column_set_g_type (1, G_TYPE_INT);
- gda_column_set_description (2, "specificname");
- gda_column_set_name (2, "specificname");
- gda_column_set_g_type (2, G_TYPE_STRING);
- cdata->functions_model = (GdaDataModel *) recset;
- }
- is_func = TRUE;
- }
- else if (xStep && xFinal) {
- /* It's an aggregate */
- recset = (GdaDataModelArray *) cdata->aggregates_model;
- if (!recset) {
- recset = GDA_DATA_MODEL_ARRAY (gda_data_model_array_new, 3);
- gda_column_set_description (0, "name");
- gda_column_set_name (0, "name");
- gda_column_set_g_type (0, G_TYPE_STRING);
- gda_column_set_description (1, "nargs");
- gda_column_set_name (1, "nargs");
- gda_column_set_g_type (1, G_TYPE_INT);
- gda_column_set_description (2, "specificname");
- gda_column_set_name (2, "specificname");
- gda_column_set_g_type (2, G_TYPE_STRING);
- cdata->functions_model = (GdaDataModel *) recset;
- cdata->aggregates_model = (GdaDataModel *) recset;
- }
- is_agg = TRUE;
- }
- else if (!xFunc && !xStep && !xFinal) {
- /* remove function or aggregate definition */
- GSList *values;
- GValue *value;
- gint cols_index [] = {0};
- gint row;
-
- g_value_set_string (value = gda_value_new (G_TYPE_STRING), name);
- values = g_slist_prepend (NULL, value);
-
- if (cdata->functions_model) {
- row = gda_data_model_get_row_from_values (cdata->functions_model, values, cols_index);
- if (row >= 0) {
- g_object_set (G_OBJECT (cdata->functions_model), "read-only", FALSE, NULL);
- g_assert (gda_data_model_remove_row (cdata->functions_model, row, NULL));
- g_object_set (G_OBJECT (cdata->functions_model), "read-only", TRUE, NULL);
- }
- }
- if (cdata->aggregates_model) {
- row = gda_data_model_get_row_from_values (cdata->aggregates_model, values, cols_index);
- if (row >= 0) {
- g_object_set (G_OBJECT (cdata->aggregates_model), "read-only", FALSE, NULL);
- g_assert (gda_data_model_remove_row (cdata->aggregates_model, row, NULL));
- g_object_set (G_OBJECT (cdata->aggregates_model), "read-only", TRUE, NULL);
- }
- }
-
- gda_value_free (value);
- g_slist_free (values);
- }
-
- if (is_func || is_agg) {
- gchar *str;
- GValue *value;
- GList *rowlist = NULL;
-
- /* 'unlock' the data model */
- g_object_set (G_OBJECT (recset), "read-only", FALSE, NULL);
-
- /* name */
- g_value_set_string (value = gda_value_new (G_TYPE_STRING), name);
- rowlist = g_list_append (rowlist, value);
-
- /* Number of args */
- g_value_set_int (value = gda_value_new (G_TYPE_INT), nArg);
- rowlist = g_list_append (rowlist, value);
-
- /* specific name */
- str = g_strdup_printf ("%s_%d_%d", name, nArg, eTextRep);
- g_value_take_string (value = gda_value_new (G_TYPE_STRING), str);
- rowlist = g_list_append (rowlist, value);
-
- add_g_list_row ((gpointer) rowlist, recset);
-
- /* 'lock' the data model */
- g_object_set (G_OBJECT (recset), "read-only", TRUE, NULL);
- }
-
- return func (db, name, nArg, eTextRep, data, xFunc, xStep, xFinal);
-}
-#endif
-#endif
-
/*
* Open connection request
*/
@@ -752,10 +605,6 @@ gda_sqlite_provider_open_connection (GdaServerProvider *provider, GdaConnection
cdata = g_new0 (SqliteConnectionData, 1);
-#ifdef HAVE_SQLITE
- opening_cdata = cdata;
-#endif
-
if (filename)
cdata->file = filename;
@@ -765,9 +614,6 @@ gda_sqlite_provider_open_connection (GdaServerProvider *provider, GdaConnection
gda_connection_add_event_string (cnc, sqlite3_errmsg (cdata->connection));
gda_sqlite_free_cnc_data (cdata);
-#ifdef HAVE_SQLITE
- opening_cdata = NULL;
-#endif
g_static_rec_mutex_unlock (&cnc_mutex);
return FALSE;
}
@@ -816,9 +662,6 @@ gda_sqlite_provider_open_connection (GdaServerProvider *provider, GdaConnection
sqlite3_free (errmsg);
gda_sqlite_free_cnc_data (cdata);
gda_connection_internal_set_provider_data (cnc, NULL, (GDestroyNotify) gda_sqlite_free_cnc_data);
-#ifdef HAVE_SQLITE
- opening_cdata = NULL;
-#endif
g_static_rec_mutex_unlock (&cnc_mutex);
return FALSE;
}
@@ -835,21 +678,11 @@ gda_sqlite_provider_open_connection (GdaServerProvider *provider, GdaConnection
if (res != SQLITE_OK) {
gda_sqlite_free_cnc_data (cdata);
gda_connection_internal_set_provider_data (cnc, NULL, (GDestroyNotify) gda_sqlite_free_cnc_data);
-#ifdef HAVE_SQLITE
- opening_cdata = NULL;
-#endif
g_static_rec_mutex_unlock (&cnc_mutex);
return FALSE;
}
}
}
-
-#ifdef HAVE_SQLITE
- /* add the (cdata->connection, cdata) to db_connections_hash */
- if (!db_connections_hash)
- db_connections_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
- g_hash_table_insert (db_connections_hash, cdata->connection, cdata);
-#endif
/* Note: we don't need to set the thread owner because as stating with SQLite version 3.6.0
* connections and prepared statement can be shared by threads */
@@ -2701,22 +2534,10 @@ gda_sqlite_free_cnc_data (SqliteConnectionData *cdata)
if (!cdata)
return;
-#ifdef HAVE_SQLITE
- /* remove the (cdata->connection, cdata) to db_connections_hash */
- g_static_rec_mutex_lock (&cnc_mutex);
- if (db_connections_hash && cdata->connection)
- g_hash_table_remove (db_connections_hash, cdata->connection);
- g_static_rec_mutex_unlock (&cnc_mutex);
-#endif
-
if (cdata->connection)
sqlite3_close (cdata->connection);
g_free (cdata->file);
if (cdata->types)
g_hash_table_destroy (cdata->types);
- if (cdata->aggregates_model)
- g_object_unref (cdata->aggregates_model);
- if (cdata->functions_model)
- g_object_unref (cdata->functions_model);
g_free (cdata);
}
diff --git a/libgda/sqlite/gda-sqlite.h b/libgda/sqlite/gda-sqlite.h
index 96e8e7a..557e3d9 100644
--- a/libgda/sqlite/gda-sqlite.h
+++ b/libgda/sqlite/gda-sqlite.h
@@ -44,8 +44,6 @@ typedef struct {
sqlite3 *connection;
gchar *file;
GHashTable *types; /* key = type name, value = GType */
- GdaDataModel *functions_model;
- GdaDataModel *aggregates_model;
} SqliteConnectionData;
/*
diff --git a/providers/postgres/gda-postgres-provider.c b/providers/postgres/gda-postgres-provider.c
index 8d3ccbe..fcee13d 100644
--- a/providers/postgres/gda-postgres-provider.c
+++ b/providers/postgres/gda-postgres-provider.c
@@ -479,9 +479,8 @@ get_connection_type_list (PostgresConnectionData *cdata)
/* main query to fetch infos about the data types */
query = g_strdup_printf (
"SELECT t.oid, t.typname, u.usename, pg_catalog.obj_description(t.oid), t.typinput "
- "FROM pg_catalog.pg_type t, pg_catalog.pg_user u, pg_catalog.pg_namespace n "
- "WHERE t.typowner=u.usesysid "
- "AND n.oid = t.typnamespace "
+ "FROM pg_catalog.pg_type t LEFT JOIN pg_catalog.pg_user u ON (t.typowner=u.usesysid), pg_catalog.pg_namespace n "
+ "WHERE n.oid = t.typnamespace "
"AND pg_catalog.pg_type_is_visible(t.oid) "
/*--AND (n.nspname = 'public' OR n.nspname = 'pg_catalog')*/
"AND typname !~ '^_' "
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]