[planner: 11/40] unknown type name 'GdaClient'.




commit 8c99dc1d0e7d995ad604ae7a404e1eb3aed4c5d8
Author: Ahmed Baïzid <ahmed baizid org>
Date:   Thu Jun 18 12:42:58 2015 +0200

    unknown type name 'GdaClient'.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=584556

 libplanner/mrp-sql.c     | 10 ++--------
 src/planner-sql-plugin.c | 45 +++++++++++++++++++++++----------------------
 2 files changed, 25 insertions(+), 30 deletions(-)
---
diff --git a/libplanner/mrp-sql.c b/libplanner/mrp-sql.c
index d3d36f5c..8b0121f6 100644
--- a/libplanner/mrp-sql.c
+++ b/libplanner/mrp-sql.c
@@ -2216,7 +2216,6 @@ mrp_sql_load_project (MrpStorageSQL *storage,
 {
        SQLData        *data;
        gboolean        success;
-       GdaClient      *client;
        const gchar    *dsn_name = "planner-auto";
        gchar          *db_txt;
        MrpCalendar    *calendar;
@@ -2249,9 +2248,7 @@ mrp_sql_load_project (MrpStorageSQL *storage,
                                     "planner project", login, password, FALSE);
        g_free (db_txt);
 
-       client = gda_client_new ();
-
-       data->con = gda_client_open_connection (client, dsn_name, NULL, NULL, 0, error);
+       data->con = gda_connection_open_from_dsn (dsn_name, NULL, GDA_CONNECTION_OPTIONS_NONE, error);
 
        if (!GDA_IS_CONNECTION (data->con)) {
                g_warning (_("Connection to database '%s' failed.\n"), database);
@@ -3650,7 +3647,6 @@ mrp_sql_save_project (MrpStorageSQL  *storage,
        gchar        *db_txt = NULL;
        const gchar  *dsn_name = "planner-auto";
        gboolean      success;
-       GdaClient    *client;
        gboolean      ret = FALSE;
        const gchar  *provider = "PostgreSQL";
 
@@ -3678,9 +3674,7 @@ mrp_sql_save_project (MrpStorageSQL  *storage,
                                     "planner project", user, password, FALSE);
        g_free (db_txt);
 
-       client = gda_client_new ();
-
-       data->con = gda_client_open_connection (client, dsn_name, NULL, NULL, 0, error);
+       data->con = gda_connection_open_from_dsn (dsn_name, NULL, GDA_CONNECTION_OPTIONS_NONE, error);
 
        data->revision = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (data->project),
                                                             REVISION));
diff --git a/src/planner-sql-plugin.c b/src/planner-sql-plugin.c
index 254cb854..5d322b83 100644
--- a/src/planner-sql-plugin.c
+++ b/src/planner-sql-plugin.c
@@ -616,13 +616,13 @@ create_database (const gchar   *dsn_name,
        guint              result;
        gboolean           retval;
        GdaConnection     *conn;
-       GdaClient         *client;
        GdaDataSourceInfo *dsn;
        gchar             *cnc_string_orig;
+       gchar             *init_cnc;
        /* FIXME: In postgresql we use template1 as the connection database */
        gchar             *init_database = "template1";
        gchar             *query;
-       GError            *error;
+       GError            *error = NULL;
 
        dsn = gda_config_find_data_source (dsn_name);
        cnc_string_orig = dsn->cnc_string;
@@ -631,11 +631,15 @@ create_database (const gchar   *dsn_name,
        window = GTK_WINDOW (plugin->main_window);
 
        /* Use same data but changing the database */
-       dsn->cnc_string = g_strdup_printf (CONNECTION_FORMAT_STRING, host, init_database);
+       init_cnc = g_strdup_printf (CONNECTION_FORMAT_STRING, host, init_database);
        gda_config_save_data_source_info (dsn);
 
-       client = gda_client_new ();
-       conn = gda_client_open_connection (client, dsn_name, NULL, NULL, 0, &error);
+       conn = gda_connection_open_from_string(dsn->provider, init_cnc, dsn->auth_string, 0, &error);
+       if (error) {
+               g_warning (error->message);
+               g_clear_error (&error);
+       }
+       g_free(init_cnc);
        if (conn == NULL) {
                g_warning ("Can't connect to database server in order to check/create the database: %s", 
cnc_string_orig);
        } else {
@@ -660,10 +664,7 @@ create_database (const gchar   *dsn_name,
                        retval = FALSE;
                }
                gda_connection_close (conn);
-               g_object_unref (client);
        }
-       g_free (dsn->cnc_string);
-       dsn->cnc_string = cnc_string_orig;
        gda_config_save_data_source_info (dsn);
 
        return retval;
@@ -674,24 +675,31 @@ static GdaConnection *
 sql_get_tested_connection (const gchar   *dsn_name,
                           const gchar   *host,
                           const gchar   *db_name,
-                          GdaClient     *client,
                           PlannerPlugin *plugin)
 {
        GdaConnection *conn = NULL;
        gboolean       success;
        gchar         *str;
-       GError        *error;
+       GError        *error = NULL;
 
-       conn = gda_client_open_connection (client, dsn_name, NULL, NULL, 0, &error);
+       conn = gda_connection_open_from_dsn (dsn_name, NULL, 0, &error);
+       if (error) {
+           g_warning (error->message);
+           g_clear_error (&error);
+       }
 
        if (conn == NULL) {
                if (!create_database (dsn_name, host, db_name, plugin)) {
                        str = g_strdup_printf (_("Connection to database '%s@%s' failed."),
                                               db_name, host);
                        show_error_dialog (plugin, str);
-                       conn = NULL;
+                       g_free (str);
                } else {
-                       conn = gda_client_open_connection (client, dsn_name, NULL, NULL, 0, &error);
+                       conn = gda_connection_open_from_dsn (dsn_name, NULL, 0, &error);
+                       if (error) {
+                           g_warning (error->message);
+                           g_clear_error (&error);
+                       }
                }
        }
 
@@ -713,7 +721,6 @@ sql_get_tested_connection (const gchar   *dsn_name,
                }
        }
 
-       /* g_object_unref (client); */
        return conn;
 
 out:
@@ -739,7 +746,6 @@ sql_plugin_retrieve_project_id (PlannerPlugin *plugin,
        GdaConnection     *conn;
        GdaDataModel      *model;
        gboolean           success;
-       GdaClient         *client;
        GladeXML          *gui;
        GtkWidget         *dialog;
        GtkWidget         *treeview;
@@ -764,8 +770,7 @@ sql_plugin_retrieve_project_id (PlannerPlugin *plugin,
                                      "planner project", login, password, FALSE);
        g_free (db_txt);
 
-       client = gda_client_new ();
-       conn = sql_get_tested_connection (dsn_name, server, database, client, plugin);
+       conn = sql_get_tested_connection (dsn_name, server, database, plugin);
 
        if (conn == NULL) {
                return -1;
@@ -1118,7 +1123,6 @@ static void
 sql_plugin_save (GtkAction *action,
                 gpointer   user_data)
 {
-       GdaClient     *client;
        GdaConnection *conn;
        PlannerPlugin *plugin   = user_data;
        MrpProject    *project;
@@ -1153,14 +1157,11 @@ sql_plugin_save (GtkAction *action,
                                      db_txt,
                                      "planner project", login, password, FALSE);
        g_free (db_txt);
-       client = gda_client_new ();
-       conn = sql_get_tested_connection (dsn_name, server, database, client, plugin);
+       conn = sql_get_tested_connection (dsn_name, server, database, plugin);
        if (conn == NULL) {
-               g_object_unref (client);
                return;
        }
        gda_connection_close (conn);
-       g_object_unref (client);
 
        /* This code is prepared for getting support for selecting a project to
         * save over. Needs finishing though. Pass project id -1 for now (always


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