[libgda] SQLite provider: enable using "SELECT load_extension('xxx')"



commit 1c2327652b24a7c457d52496b1973082bd7871ea
Author: Vivien Malerba <malerba gnome-db org>
Date:   Sun Oct 23 15:24:14 2011 +0200

    SQLite provider: enable using "SELECT load_extension('xxx')"

 libgda/sqlite/gda-sqlite-provider.c      |   15 ++++++++++++++-
 libgda/sqlite/gda-symbols-util.c         |    4 +++-
 libgda/sqlite/gda-symbols-util.h         |    2 ++
 libgda/sqlite/sqlite-src/Makefile.am     |    2 +-
 providers/sqlite/sqlite_specs_dsn.xml.in |    1 +
 5 files changed, 21 insertions(+), 3 deletions(-)
---
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index e270a31..6621d1d 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -723,7 +723,7 @@ gda_sqlite_provider_open_connection (GdaServerProvider *provider, GdaConnection
 	gchar *filename = NULL;
 	const gchar *dirname = NULL, *dbname = NULL;
 	const gchar *is_virtual = NULL;
-	const gchar *use_extra_functions = NULL, *with_fk = NULL, *regexp, *locale_collate;
+	const gchar *use_extra_functions = NULL, *with_fk = NULL, *regexp, *locale_collate, *extensions;
 	gint errmsg;
 	SqliteConnectionData *cdata;
 	gchar *dup = NULL;
@@ -754,6 +754,7 @@ gda_sqlite_provider_open_connection (GdaServerProvider *provider, GdaConnection
 
 	regexp = gda_quark_list_find (params, "REGEXP");
 	locale_collate = gda_quark_list_find (params, "EXTRA_COLLATIONS");
+	extensions = gda_quark_list_find (params, "EXTENSIONS");
 
 	if (! is_virtual) {
 		if (!dbname) {
@@ -886,6 +887,18 @@ gda_sqlite_provider_open_connection (GdaServerProvider *provider, GdaConnection
 	/* allow a busy timeout of 500 ms */
 	SQLITE3_CALL (sqlite3_busy_timeout) (cdata->connection, 500);
 
+	/* allow loading extensions using SELECT load_extension ()... */
+	if (extensions && ((*extensions == 't') || (*extensions == 'T'))) {
+		if (SQLITE3_CALL (sqlite3_enable_load_extension))
+			SQLITE3_CALL (sqlite3_enable_load_extension) (cdata->connection, 1);
+		else {
+			gda_connection_add_event_string (cnc, _("Extension loading is not supported"));
+			gda_sqlite_free_cnc_data (cdata);
+			g_static_rec_mutex_unlock (&cnc_mutex);
+			return FALSE;
+		}
+	}
+
 	/* try to prepare all the internal statements */
 	InternalStatementItem i;
 	for (i = INTERNAL_PRAGMA_INDEX_LIST; i < sizeof (internal_sql) / sizeof (gchar*); i++)
diff --git a/libgda/sqlite/gda-symbols-util.c b/libgda/sqlite/gda-symbols-util.c
index 0221fbc..0415737 100644
--- a/libgda/sqlite/gda-symbols-util.c
+++ b/libgda/sqlite/gda-symbols-util.c
@@ -284,7 +284,9 @@ load_symbols (GModule *module)
 		s3r->sqlite3_rekey = NULL;
 
 	if (! g_module_symbol (module, "sqlite3_create_collation", (gpointer*) &(s3r->sqlite3_create_collation)))
-		s3r->sqlite3_rekey = NULL;
+		goto onerror;
+	if (! g_module_symbol (module, "sqlite3_enable_load_extension", (gpointer*) &(s3r->sqlite3_enable_load_extension)))
+		s3r->sqlite3_enable_load_extension = NULL;
 	return;
 
  onerror:
diff --git a/libgda/sqlite/gda-symbols-util.h b/libgda/sqlite/gda-symbols-util.h
index 332ed24..f27e171 100644
--- a/libgda/sqlite/gda-symbols-util.h
+++ b/libgda/sqlite/gda-symbols-util.h
@@ -111,6 +111,8 @@ typedef struct {
 	int  (*sqlite3_rekey)(sqlite3 *, const void *, int);
 
 	int  (*sqlite3_create_collation) (sqlite3*, const char *, int, void*, int(*xCompare)(void*,int,const void*,int,const void*));
+
+	int (*sqlite3_enable_load_extension) (sqlite3 *, int);
 } Sqlite3ApiRoutines;
 
 extern Sqlite3ApiRoutines *s3r;
diff --git a/libgda/sqlite/sqlite-src/Makefile.am b/libgda/sqlite/sqlite-src/Makefile.am
index 06e68f6..446ed5f 100644
--- a/libgda/sqlite/sqlite-src/Makefile.am
+++ b/libgda/sqlite/sqlite-src/Makefile.am
@@ -1,6 +1,6 @@
 noinst_LTLIBRARIES = \
 	libsqlite.la
-AM_CPPFLAGS = -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_THREADSAFE=1 -DSQLITE_OMIT_LOAD_EXTENSION=1
+AM_CPPFLAGS = -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_THREADSAFE=1
 
 # Download the Windows prepared SQLite (series 3.x) sources in a ZIP, and
 # extract the zip in this directory (thanks to http://aaronbock.net/articles/sqlite!)
diff --git a/providers/sqlite/sqlite_specs_dsn.xml.in b/providers/sqlite/sqlite_specs_dsn.xml.in
index 2f954d8..2d31fb4 100644
--- a/providers/sqlite/sqlite_specs_dsn.xml.in
+++ b/providers/sqlite/sqlite_specs_dsn.xml.in
@@ -13,5 +13,6 @@
       <gda_value>TRUE</gda_value>
     </parameter>
     <parameter id="FK" _name="With foreign keys" _descr="Enforce foreign keys" gdatype="gboolean" nullok="TRUE"/>
+    <parameter id="EXTENSIONS" _name="Allow extensions" _descr="Allow SQLite to load extensions using the load_extension() function" gdatype="gboolean" nullok="TRUE"/>
   </parameters>
 </data-set-spec>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]