[libgda] SQLite: added the "APPEND_DB_EXTENSION" connection option



commit 729d88b8d36e10daeb05d066a5284514d9e221c0
Author: Vivien Malerba <malerba gnome-db org>
Date:   Sat Jun 8 20:11:43 2013 +0200

    SQLite: added the "APPEND_DB_EXTENSION" connection option

 doc/C/prov-notes.xml                     |    6 ++++++
 libgda/sqlite/gda-sqlite-provider.c      |   19 ++++++++++++++++---
 providers/sqlite/sqlite_specs_dsn.xml.in |    1 +
 3 files changed, 23 insertions(+), 3 deletions(-)
---
diff --git a/doc/C/prov-notes.xml b/doc/C/prov-notes.xml
index 962a593..8f0dd73 100644
--- a/doc/C/prov-notes.xml
+++ b/doc/C/prov-notes.xml
@@ -88,6 +88,12 @@
               <entry>Yes</entry>
            </row>
            <row>
+              <entry>APPEND_DB_EXTENSION</entry>
+              <entry>Defines if the '.db' extension need to be appended to the name of the database. 
Defaults to TRUE if not
+             specified.</entry>
+              <entry>No</entry>
+           </row>
+           <row>
               <entry>DB_DIR</entry>
               <entry>The directory where the database file is; if not specified, the current working
              directory is used.</entry>
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index 8644a05..9ceb486 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -719,6 +719,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 *append_extension = NULL;
        const gchar *use_extra_functions = NULL, *with_fk = NULL, *regexp, *locale_collate, *extensions;
        gint errmsg;
        SqliteConnectionData *cdata;
@@ -743,6 +744,7 @@ gda_sqlite_provider_open_connection (GdaServerProvider *provider, GdaConnection
        if (!dirname)
                dirname="."; /* default to current directory */
        dbname = gda_quark_list_find (params, "DB_NAME");
+       append_extension = gda_quark_list_find (params, "APPEND_DB_EXTENSION");
        is_virtual = gda_quark_list_find (params, "_IS_VIRTUAL");
        with_fk = gda_quark_list_find (params, "FK");
        use_extra_functions = gda_quark_list_find (params, "EXTRA_FUNCTIONS");
@@ -819,7 +821,11 @@ gda_sqlite_provider_open_connection (GdaServerProvider *provider, GdaConnection
 
                        /* try first with the file extension */
                        gchar *tmp, *f1, *f2;
-                       tmp = g_strdup_printf ("%s%s", dbname, FILE_EXTENSION);
+                       if (!append_extension ||
+                           (append_extension && ((*append_extension == 't') || (*append_extension == 'T'))))
+                               tmp = g_strdup_printf ("%s%s", dbname, FILE_EXTENSION);
+                       else
+                               tmp = g_strdup (dbname);
                        f1 = g_build_filename (dirname, tmp, NULL);
                        g_free (tmp);
                        f2 = g_build_filename (dirname, dbname, NULL);
@@ -1310,7 +1316,7 @@ gda_sqlite_provider_perform_operation (GdaServerProvider *provider, GdaConnectio
        switch (optype) {
        case GDA_SERVER_OPERATION_CREATE_DB: {
                const GValue *value;
-               const gchar *dbname = NULL;
+               const gchar *dbname = NULL, *append_extension = NULL;
                const gchar *dir = NULL;
                SqliteConnectionData *cdata;
                gint errmsg;
@@ -1320,11 +1326,18 @@ gda_sqlite_provider_perform_operation (GdaServerProvider *provider, GdaConnectio
                value = gda_server_operation_get_value_at (op, "/DB_DEF_P/DB_NAME");
                 if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value))
                         dbname = g_value_get_string (value);
+               value = gda_server_operation_get_value_at (op, "/DB_DEF_P/APPEND_DB_EXTENSION");
+                if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value))
+                        append_extension = g_value_get_string (value);
                value = gda_server_operation_get_value_at (op, "/DB_DEF_P/DB_DIR");
                 if (value && G_VALUE_HOLDS (value, G_TYPE_STRING) && g_value_get_string (value))
                         dir = g_value_get_string (value);
 
-               tmp = g_strdup_printf ("%s%s", dbname, FILE_EXTENSION);
+               if (!append_extension ||
+                   (append_extension && ((*append_extension == 't') || (*append_extension == 'T'))))
+                       tmp = g_strdup_printf ("%s%s", dbname, FILE_EXTENSION);
+               else
+                       tmp = g_strdup (dbname);
                filename = g_build_filename (dir, tmp, NULL);
                g_free (tmp);
 
diff --git a/providers/sqlite/sqlite_specs_dsn.xml.in b/providers/sqlite/sqlite_specs_dsn.xml.in
index 2d31fb4..c232bbc 100644
--- a/providers/sqlite/sqlite_specs_dsn.xml.in
+++ b/providers/sqlite/sqlite_specs_dsn.xml.in
@@ -2,6 +2,7 @@
 <data-set-spec>
   <parameters>
     <parameter id="DB_NAME" _name="Database name" _descr="The name of a database to use (without the .db)" 
gdatype="gchararray" nullok="FALSE"/>
+    <parameter id="APPEND_DB_EXTENSION" _name="Append '.db'" _descr="Defines if the '.db' extension need to 
be appended to the DB_NAME argument" gdatype="gchararray" nullok="TRUE"/>
     <parameter id="DB_DIR" _name="Directory" _descr="Directory where the database file is stored" 
gdatype="gchararray" nullok="FALSE" plugin="filesel:MODE=PICKFOLDER"/>
     <parameter id="EXTRA_FUNCTIONS" _name="Extra functions" _descr="Enable usage of extra functions 
(gda_upper, ...)" gdatype="gboolean" nullok="TRUE">
       <gda_value>TRUE</gda_value>


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