[libgda] Revert "GdaPostgresRecordset: portedt to G_DECLARE/G_DEFINE"



commit 7bd39f57dcb5b34d753491b04f979412dc1d26f2
Author: Daniel Espinosa <esodan gmail com>
Date:   Mon Apr 8 15:28:39 2019 -0500

    Revert "GdaPostgresRecordset: portedt to G_DECLARE/G_DEFINE"
    
    This reverts commit 70a4e78d5cb4a1254d70272793e8d4ce98a21ec6.

 providers/postgres/gda-postgres-recordset.c | 446 +++++++++++++++-------------
 providers/postgres/gda-postgres-recordset.h |  17 +-
 2 files changed, 248 insertions(+), 215 deletions(-)
---
diff --git a/providers/postgres/gda-postgres-recordset.c b/providers/postgres/gda-postgres-recordset.c
index 2dbc347af..a22e4e5ba 100644
--- a/providers/postgres/gda-postgres-recordset.c
+++ b/providers/postgres/gda-postgres-recordset.c
@@ -13,7 +13,7 @@
  * Copyright (C) 2006 - 2011 Murray Cumming <murrayc murrayc com>
  * Copyright (C) 2007 Armin Burgmeier <armin openismus com>
  * Copyright (C) 2010 David King <davidk openismus com>
- * Copyright (C) 2011-2019 Daniel Espinosa <esodan gmail com>
+ * Copyright (C) 2011-2017 Daniel Espinosa <esodan gmail com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -50,7 +50,8 @@
 #define _GDA_PSTMT(x) ((GdaPStmt*)(x))
 
 static void gda_postgres_recordset_class_init (GdaPostgresRecordsetClass *klass);
-static void gda_postgres_recordset_init       (GdaPostgresRecordset *recset);
+static void gda_postgres_recordset_init       (GdaPostgresRecordset *recset,
+                                              GdaPostgresRecordsetClass *klass);
 static void gda_postgres_recordset_dispose   (GObject *object);
 
 static void gda_postgres_recordset_set_property (GObject *object,
@@ -82,7 +83,7 @@ static gboolean fetch_prev_chunk (GdaPostgresRecordset *model, gboolean *fetch_e
 static gboolean fetch_row_number_chunk (GdaPostgresRecordset *model, int row_index, gboolean *fetch_error, 
GError **error);
 
 
-typedef struct {
+struct _GdaPostgresRecordsetPrivate {
        /* random access attributes */
        PGresult         *pg_res;
 
@@ -97,33 +98,32 @@ typedef struct {
         gint              pg_pos; /* from G_MININT to G_MAXINT */
         gint              pg_res_size; /* The number of rows in the current chunk - usually equal to 
chunk_size when iterating forward or backward. */
         gint              pg_res_inf; /* The row number of the first row in the current chunk. Don't use if 
(@pg_res_size <= 0). */
-} GdaPostgresRecordsetPrivate;
-
-G_DEFINE_TYPE_WITH_PRIVATE(GdaPostgresRecordset, gda_postgres_recordset, GDA_TYPE_POSTGRES_RECORDSET)
+};
+static GObjectClass *parent_class = NULL;
 
 /* properties */
 enum
 {
-  PROP_0,
-  PROP_CHUNCK_SIZE,
-  PROP_CHUNCKS_READ
+        PROP_0,
+        PROP_CHUNCK_SIZE,
+        PROP_CHUNCKS_READ
 };
 
 /*
  * Object init and finalize
  */
 static void
-gda_postgres_recordset_init (GdaPostgresRecordset *recset)
+gda_postgres_recordset_init (GdaPostgresRecordset *recset, G_GNUC_UNUSED GdaPostgresRecordsetClass *klass)
 {
        g_return_if_fail (GDA_IS_POSTGRES_RECORDSET (recset));
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (recset);
+       recset->priv = g_new0 (GdaPostgresRecordsetPrivate, 1);
 
-       priv->pg_res = NULL;
-  priv->pg_pos = G_MININT;
-  priv->pg_res_size = 0;
+       recset->priv->pg_res = NULL;
+        recset->priv->pg_pos = G_MININT;
+        recset->priv->pg_res_size = 0;
 
-       priv->chunk_size = 10;
-  priv->chunks_read = 0;
+       recset->priv->chunk_size = 10;
+        recset->priv->chunks_read = 0;
 }
 
 static void
@@ -132,6 +132,8 @@ gda_postgres_recordset_class_init (GdaPostgresRecordsetClass *klass)
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
        GdaDataSelectClass *pmodel_class = GDA_DATA_SELECT_CLASS (klass);
 
+       parent_class = g_type_class_peek_parent (klass);
+
        object_class->dispose = gda_postgres_recordset_dispose;
        pmodel_class->fetch_nb_rows = gda_postgres_recordset_fetch_nb_rows;
        pmodel_class->fetch_random = gda_postgres_recordset_fetch_random;
@@ -161,30 +163,29 @@ gda_postgres_recordset_dispose (GObject *object)
        GdaPostgresRecordset *recset = (GdaPostgresRecordset *) object;
 
        g_return_if_fail (GDA_IS_POSTGRES_RECORDSET (recset));
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (recset);
-
-       if (priv->tmp_row) {
-               g_object_unref (priv->tmp_row);
-    priv->tmp_row = NULL;
-  }
-
-       if (priv->pg_res) {
-               PQclear (priv->pg_res);
-    priv->pg_res = NULL;
-  }
-
-       if (priv->cursor_name) {
-               gchar *str;
-               PGresult *pg_res;
-               str = g_strdup_printf ("CLOSE %s", priv->cursor_name);
-               pg_res = PQexec (priv->pconn, str);
-               g_free (str);
-               PQclear (pg_res);
-               g_free (priv->cursor_name);
-    priv->cursor_name = NULL;
+
+       if (recset->priv) {
+               if (recset->priv->tmp_row)
+                       g_object_unref (recset->priv->tmp_row);
+
+               if (recset->priv->pg_res)
+                       PQclear (recset->priv->pg_res);
+
+               if (recset->priv->cursor_name) {
+                       gchar *str;
+                       PGresult *pg_res;
+                       str = g_strdup_printf ("CLOSE %s", recset->priv->cursor_name);
+                       pg_res = PQexec (recset->priv->pconn, str);
+                       g_free (str);
+                       PQclear (pg_res);
+                       g_free (recset->priv->cursor_name);
+               }
+
+               g_free (recset->priv);
+               recset->priv = NULL;
        }
 
-       G_OBJECT_CLASS (gda_postgres_recordset_parent_class)->dispose (object);
+       parent_class->dispose (object);
 }
 
 static void
@@ -193,16 +194,17 @@ gda_postgres_recordset_set_property (GObject *object,
                                     const GValue *value,
                                     GParamSpec *pspec)
 {
-  GdaPostgresRecordset *recset = (GdaPostgresRecordset *) object;
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (recset);
-  switch (param_id) {
-  case PROP_CHUNCK_SIZE:
-    priv->chunk_size = g_value_get_int (value);
-    break;
-  default:
-    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
-    break;
-  }
+        GdaPostgresRecordset *model = (GdaPostgresRecordset *) object;
+        if (model->priv) {
+                switch (param_id) {
+                case PROP_CHUNCK_SIZE:
+                        model->priv->chunk_size = g_value_get_int (value);
+                        break;
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+                       break;
+                }
+        }
 }
 
 static void
@@ -211,19 +213,52 @@ gda_postgres_recordset_get_property (GObject *object,
                                     GValue *value,
                                     GParamSpec *pspec)
 {
-  GdaPostgresRecordset *model = (GdaPostgresRecordset *) object;
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (model);
-  switch (param_id) {
-  case PROP_CHUNCK_SIZE:
-    g_value_set_int (value, priv->chunk_size);
-    break;
-  case PROP_CHUNCKS_READ:
-    g_value_set_int (value, priv->chunks_read);
-    break;
-       default:
-               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
-               break;
-  }
+        GdaPostgresRecordset *model = (GdaPostgresRecordset *) object;
+        if (model->priv) {
+                switch (param_id) {
+                case PROP_CHUNCK_SIZE:
+                        g_value_set_int (value, model->priv->chunk_size);
+                        break;
+                case PROP_CHUNCKS_READ:
+                        g_value_set_int (value, model->priv->chunks_read);
+                        break;
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+                       break;
+                }
+        }
+}
+
+/*
+ * Public functions
+ */
+
+GType
+gda_postgres_recordset_get_type (void)
+{
+       static GType type = 0;
+
+       if (G_UNLIKELY (type == 0)) {
+               static GMutex registering;
+               static const GTypeInfo info = {
+                       sizeof (GdaPostgresRecordsetClass),
+                       (GBaseInitFunc) NULL,
+                       (GBaseFinalizeFunc) NULL,
+                       (GClassInitFunc) gda_postgres_recordset_class_init,
+                       NULL,
+                       NULL,
+                       sizeof (GdaPostgresRecordset),
+                       0,
+                       (GInstanceInitFunc) gda_postgres_recordset_init,
+                       0
+               };
+               g_mutex_lock (&registering);
+               if (type == 0)
+                       type = g_type_register_static (GDA_TYPE_DATA_SELECT, "GdaPostgresRecordset", &info, 
0);
+               g_mutex_unlock (&registering);
+       }
+
+       return type;
 }
 
 static void
@@ -296,10 +331,10 @@ gda_postgres_recordset_new_random (GdaConnection *cnc, GdaPostgresPStmt *ps, Gda
                                   PGresult *pg_res, GType *col_types)
 {
        GdaPostgresRecordset *model;
-  PostgresConnectionData *cdata;
+        PostgresConnectionData *cdata;
 
-  g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
-  g_return_val_if_fail (ps, NULL);
+        g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
+        g_return_val_if_fail (ps, NULL);
 
        cdata = (PostgresConnectionData*) gda_connection_internal_get_provider_data_error (cnc, NULL);
        if (!cdata)
@@ -309,13 +344,12 @@ gda_postgres_recordset_new_random (GdaConnection *cnc, GdaPostgresPStmt *ps, Gda
        finish_prep_stmt_init (cdata, ps, pg_res, col_types);
 
        /* create data model */
-  model = g_object_new (GDA_TYPE_POSTGRES_RECORDSET, "connection", cnc,
-      "prepared-stmt", ps,
-      "model-usage", GDA_DATA_MODEL_ACCESS_RANDOM,
-      "exec-params", exec_params, NULL);
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (model);
-       priv->pg_res = pg_res;
-       gda_data_select_set_advertized_nrows ((GdaDataSelect*) model, PQntuples (priv->pg_res));
+        model = g_object_new (GDA_TYPE_POSTGRES_RECORDSET, "connection", cnc, 
+                             "prepared-stmt", ps, 
+                             "model-usage", GDA_DATA_MODEL_ACCESS_RANDOM, 
+                             "exec-params", exec_params, NULL);
+       model->priv->pg_res = pg_res;
+       gda_data_select_set_advertized_nrows ((GdaDataSelect*) model, PQntuples (model->priv->pg_res));
 
        return GDA_DATA_MODEL (model);
 }
@@ -328,10 +362,10 @@ gda_postgres_recordset_new_cursor (GdaConnection *cnc, GdaPostgresPStmt *ps, Gda
                                   gchar *cursor_name, GType *col_types)
 {
        GdaPostgresRecordset *model;
-  PostgresConnectionData *cdata;
+        PostgresConnectionData *cdata;
 
-  g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
-  g_return_val_if_fail (ps, NULL);
+        g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
+        g_return_val_if_fail (ps, NULL);
 
        cdata = (PostgresConnectionData*) gda_connection_internal_get_provider_data_error (cnc, NULL);
        if (!cdata)
@@ -372,9 +406,8 @@ gda_postgres_recordset_new_cursor (GdaConnection *cnc, GdaPostgresPStmt *ps, Gda
                              "prepared-stmt", ps, "model-usage", 
                              GDA_DATA_MODEL_ACCESS_CURSOR_FORWARD | GDA_DATA_MODEL_ACCESS_CURSOR_BACKWARD, 
                              "exec-params", exec_params, NULL);
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (model);
-       priv->pconn = cdata->pconn;
-       priv->cursor_name = cursor_name;
+       model->priv->pconn = cdata->pconn;
+       model->priv->cursor_name = cursor_name;
        gboolean fetch_error;
        fetch_next_chunk (model, &fetch_error, NULL);
 
@@ -390,13 +423,12 @@ gda_postgres_recordset_fetch_nb_rows (GdaDataSelect *model)
        GdaPostgresRecordset *imodel;
 
        imodel = GDA_POSTGRES_RECORDSET (model);
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (imodel);
        if (gda_data_select_get_advertized_nrows (model) >= 0)
                return gda_data_select_get_advertized_nrows (model);
 
        /* use C API to determine number of rows,if possible */
-       if (!priv->cursor_name)
-               gda_data_select_set_advertized_nrows (model, PQntuples (priv->pg_res));
+       if (!imodel->priv->cursor_name)
+               gda_data_select_set_advertized_nrows (model, PQntuples (imodel->priv->pg_res));
 
        return gda_data_select_get_advertized_nrows (model);
 }
@@ -413,9 +445,8 @@ gda_postgres_recordset_fetch_random (GdaDataSelect *model, GdaRow **prow, gint r
        g_return_val_if_fail (GDA_IS_DATA_SELECT (model), FALSE);
 
        GdaPostgresRecordset *imodel = (GdaPostgresRecordset *) model;
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (imodel);
 
-       if (!priv->pg_res) {
+       if (!imodel->priv->pg_res) {
                g_set_error (error, GDA_SERVER_PROVIDER_ERROR, GDA_SERVER_PROVIDER_INTERNAL_ERROR,
                             "%s", _("Internal error"));
                return TRUE;
@@ -427,8 +458,8 @@ gda_postgres_recordset_fetch_random (GdaDataSelect *model, GdaRow **prow, gint r
        if (gda_data_select_get_nb_stored_rows (model) == gda_data_select_get_advertized_nrows (model)) {
                /* all the rows have been converted from PGresult to GdaRow objects => we can
                 * discard the PGresult */
-               PQclear (priv->pg_res);
-               priv->pg_res = NULL;
+               PQclear (imodel->priv->pg_res);
+               imodel->priv->pg_res = NULL;
        }
 
        return TRUE;
@@ -441,10 +472,9 @@ static gboolean
 gda_postgres_recordset_store_all (GdaDataSelect *model, GError **error)
 {
        GdaPostgresRecordset *imodel = (GdaPostgresRecordset*) model;
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (imodel);
        gint i;
        
-       if (!priv->pg_res) {
+       if (!imodel->priv->pg_res) {
                g_set_error (error, GDA_SERVER_PROVIDER_ERROR, GDA_SERVER_PROVIDER_INTERNAL_ERROR,
                             "%s", _("Internal error"));
                return FALSE;
@@ -461,30 +491,29 @@ gda_postgres_recordset_store_all (GdaDataSelect *model, GError **error)
 /*
  * Create a new filled #GdaRow object for the next cursor row, and put it into *prow.
  *
- * Each new #GdaRow created is referenced only by priv->tmp_row (the #GdaDataSelect implementation
+ * Each new #GdaRow created is referenced only by imodel->priv->tmp_row (the #GdaDataSelect implementation
  * never keeps a reference to it).
  */
 static gboolean
 gda_postgres_recordset_fetch_next (GdaDataSelect *model, GdaRow **prow, gint rownum, GError **error)
 {
        GdaPostgresRecordset *imodel = (GdaPostgresRecordset*) model;
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (imodel);
 
        if (row_is_in_current_pg_res (imodel, rownum)) {
-               if (priv->tmp_row)
-                       set_prow_with_pg_res (imodel, priv->tmp_row, rownum - priv->pg_res_inf, error);
+               if (imodel->priv->tmp_row)
+                       set_prow_with_pg_res (imodel, imodel->priv->tmp_row, rownum - 
imodel->priv->pg_res_inf, error);
                else
-                       priv->tmp_row = new_row_from_pg_res (imodel, rownum - priv->pg_res_inf, error);
-               *prow = priv->tmp_row;
+                       imodel->priv->tmp_row = new_row_from_pg_res (imodel, rownum - 
imodel->priv->pg_res_inf, error);
+               *prow = imodel->priv->tmp_row;
        }
        else {
                gboolean fetch_error = FALSE;
                if (fetch_next_chunk (imodel, &fetch_error, error)) {
-                       if (priv->tmp_row)
-                               set_prow_with_pg_res (imodel, priv->tmp_row, rownum - priv->pg_res_inf, 
error);
+                       if (imodel->priv->tmp_row)
+                               set_prow_with_pg_res (imodel, imodel->priv->tmp_row, rownum - 
imodel->priv->pg_res_inf, error);
                        else
-                               priv->tmp_row = new_row_from_pg_res (imodel, rownum - priv->pg_res_inf, 
error);
-                       *prow = priv->tmp_row;
+                               imodel->priv->tmp_row = new_row_from_pg_res (imodel, rownum - 
imodel->priv->pg_res_inf, error);
+                       *prow = imodel->priv->tmp_row;
                }
        }
        return TRUE;
@@ -493,30 +522,29 @@ gda_postgres_recordset_fetch_next (GdaDataSelect *model, GdaRow **prow, gint row
 /*
  * Create a new filled #GdaRow object for the previous cursor row, and put it into *prow.
  *
- * Each new #GdaRow created is referenced only by priv->tmp_row (the #GdaDataSelect implementation
+ * Each new #GdaRow created is referenced only by imodel->priv->tmp_row (the #GdaDataSelect implementation
  * never keeps a reference to it).
  */
 static gboolean
 gda_postgres_recordset_fetch_prev (GdaDataSelect *model, GdaRow **prow, gint rownum, GError **error)
 {
        GdaPostgresRecordset *imodel = (GdaPostgresRecordset*) model;
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (imodel);
 
        if (row_is_in_current_pg_res (imodel, rownum)) {
-               if (priv->tmp_row)
-                       set_prow_with_pg_res (imodel, priv->tmp_row, rownum - priv->pg_res_inf, error);
+               if (imodel->priv->tmp_row)
+                       set_prow_with_pg_res (imodel, imodel->priv->tmp_row, rownum - 
imodel->priv->pg_res_inf, error);
                else
-                       priv->tmp_row = new_row_from_pg_res (imodel, rownum - priv->pg_res_inf, error);
-               *prow = priv->tmp_row;
+                       imodel->priv->tmp_row = new_row_from_pg_res (imodel, rownum - 
imodel->priv->pg_res_inf, error);
+               *prow = imodel->priv->tmp_row;
        }
        else {
                gboolean fetch_error = FALSE;
                if (fetch_prev_chunk (imodel, &fetch_error, error)) {
-                       if (priv->tmp_row)
-                               set_prow_with_pg_res (imodel, priv->tmp_row, rownum - priv->pg_res_inf, 
error);
+                       if (imodel->priv->tmp_row)
+                               set_prow_with_pg_res (imodel, imodel->priv->tmp_row, rownum - 
imodel->priv->pg_res_inf, error);
                        else
-                               priv->tmp_row = new_row_from_pg_res (imodel, rownum - priv->pg_res_inf, 
error);
-                       *prow = priv->tmp_row;
+                               imodel->priv->tmp_row = new_row_from_pg_res (imodel, rownum - 
imodel->priv->pg_res_inf, error);
+                       *prow = imodel->priv->tmp_row;
                }
        }
        return TRUE;
@@ -525,29 +553,28 @@ gda_postgres_recordset_fetch_prev (GdaDataSelect *model, GdaRow **prow, gint row
 /*
  * Create a new filled #GdaRow object for the cursor row at position @rownum, and put it into *prow.
  *
- * Each new #GdaRow created is referenced only by priv->tmp_row (the #GdaDataSelect implementation
+ * Each new #GdaRow created is referenced only by imodel->priv->tmp_row (the #GdaDataSelect implementation
  * never keeps a reference to it).
  */
 static gboolean
 gda_postgres_recordset_fetch_at (GdaDataSelect *model, GdaRow **prow, gint rownum, GError **error)
 {
        GdaPostgresRecordset *imodel = (GdaPostgresRecordset*) model;
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (imodel);
 
-       if (priv->tmp_row) {
-               g_object_unref (priv->tmp_row);
-               priv->tmp_row = NULL;
+       if (imodel->priv->tmp_row) {
+               g_object_unref (imodel->priv->tmp_row);
+               imodel->priv->tmp_row = NULL;
        }
 
        if (row_is_in_current_pg_res (imodel, rownum)) {
-               *prow = new_row_from_pg_res (imodel, rownum - priv->pg_res_inf, error);
-               priv->tmp_row = *prow;
+               *prow = new_row_from_pg_res (imodel, rownum - imodel->priv->pg_res_inf, error);
+               imodel->priv->tmp_row = *prow;
        }
        else {
                gboolean fetch_error = FALSE;
                if (fetch_row_number_chunk (imodel, rownum, &fetch_error, error)) {
-                       *prow = new_row_from_pg_res (imodel, rownum - priv->pg_res_inf, error);
-                       priv->tmp_row = *prow;
+                       *prow = new_row_from_pg_res (imodel, rownum - imodel->priv->pg_res_inf, error);
+                       imodel->priv->tmp_row = *prow;
                }
        }
        return TRUE;
@@ -767,9 +794,8 @@ set_value (GdaConnection *cnc, GdaRow *row, GValue *value, GType type, const gch
 static gboolean
 row_is_in_current_pg_res (GdaPostgresRecordset *model, gint row)
 {
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (model);
-       if ((priv->pg_res) && (priv->pg_res_size > 0) &&
-            (row >= priv->pg_res_inf) && (row < priv->pg_res_inf + priv->pg_res_size))
+       if ((model->priv->pg_res) && (model->priv->pg_res_size > 0) &&
+            (row >= model->priv->pg_res_inf) && (row < model->priv->pg_res_inf + model->priv->pg_res_size))
                 return TRUE;
         else
                 return FALSE;
@@ -780,18 +806,17 @@ set_prow_with_pg_res (GdaPostgresRecordset *imodel, GdaRow *prow, gint pg_res_ro
 {
        gchar *thevalue;
        gint col;
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (imodel);
 
        for (col = 0; col < gda_pstmt_get_ncols (gda_data_select_get_prep_stmt ((GdaDataSelect*) imodel)); 
col++) {
-               thevalue = PQgetvalue (priv->pg_res, pg_res_rownum, col);
-               if (thevalue && (*thevalue != '\0' ? FALSE : PQgetisnull (priv->pg_res, pg_res_rownum, col)))
+               thevalue = PQgetvalue (imodel->priv->pg_res, pg_res_rownum, col);
+               if (thevalue && (*thevalue != '\0' ? FALSE : PQgetisnull (imodel->priv->pg_res, 
pg_res_rownum, col)))
                        gda_value_set_null (gda_row_get_value (prow, col));
                else
                        set_value (gda_data_select_get_connection ((GdaDataSelect*) imodel),
                                   prow, gda_row_get_value (prow, col), 
                                   gda_pstmt_get_types (gda_data_select_get_prep_stmt ((GdaDataSelect*) 
imodel)) [col],
                                   thevalue, 
-                                  PQgetlength (priv->pg_res, pg_res_rownum, col), error);
+                                  PQgetlength (imodel->priv->pg_res, pg_res_rownum, col), error);
        }
 }
 
@@ -810,14 +835,13 @@ new_row_from_pg_res (GdaPostgresRecordset *imodel, gint pg_res_rownum, GError **
 static gboolean
 fetch_next_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **error)
 {
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (model);
-       if (priv->pg_res) {
-               PQclear (priv->pg_res);
-               priv->pg_res = NULL;
+       if (model->priv->pg_res) {
+               PQclear (model->priv->pg_res);
+               model->priv->pg_res = NULL;
        }
        *fetch_error = FALSE;
 
-       if (priv->pg_pos == G_MAXINT)
+       if (model->priv->pg_pos == G_MAXINT) 
                return FALSE;
 
        gchar *str;
@@ -825,68 +849,68 @@ fetch_next_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e
        int status;
 
        str = g_strdup_printf ("FETCH FORWARD %d FROM %s;",
-                              priv->chunk_size, priv->cursor_name);
+                              model->priv->chunk_size, model->priv->cursor_name);
 #ifdef GDA_PG_DEBUG
        g_print ("QUERY: %s\n", str);
 #endif
-        priv->pg_res = PQexec (priv->pconn, str);
+        model->priv->pg_res = PQexec (model->priv->pconn, str);
         g_free (str);
-        status = PQresultStatus (priv->pg_res);
-       priv->chunks_read ++;
+        status = PQresultStatus (model->priv->pg_res);
+       model->priv->chunks_read ++;
         if (status != PGRES_TUPLES_OK) {
                _gda_postgres_make_error (gda_data_select_get_connection ((GdaDataSelect*) model), 
-                                         priv->pconn, priv->pg_res, error);
-                PQclear (priv->pg_res);
-                priv->pg_res = NULL;
-               priv->pg_res_size = 0;
+                                         model->priv->pconn, model->priv->pg_res, error);
+                PQclear (model->priv->pg_res);
+                model->priv->pg_res = NULL;
+               model->priv->pg_res_size = 0;
                 retval = FALSE;
                *fetch_error = TRUE;
         }
        else {
 #ifdef GDA_PG_DEBUG
-               dump_pg_res (priv->pg_res);
+               dump_pg_res (model->priv->pg_res);
 #endif
 
                 //PQntuples() returns the number of rows in the result:
-                const gint nbtuples = PQntuples (priv->pg_res);
-               priv->pg_res_size = nbtuples;
+                const gint nbtuples = PQntuples (model->priv->pg_res);
+               model->priv->pg_res_size = nbtuples;
 
                 if (nbtuples > 0) {
-                       /* priv->pg_res_inf */
-                       if (priv->pg_pos == G_MININT)
-                               priv->pg_res_inf = 0;
+                       /* model->priv->pg_res_inf */
+                       if (model->priv->pg_pos == G_MININT)
+                               model->priv->pg_res_inf = 0;
                        else
-                               priv->pg_res_inf = priv->pg_pos + 1;
+                               model->priv->pg_res_inf = model->priv->pg_pos + 1;
 
-                       /* GDA_DATA_SELECT (model)->advertized_nrows and priv->pg_pos */
-                       if (nbtuples < priv->chunk_size) {
-                               if (priv->pg_pos == G_MININT)
+                       /* GDA_DATA_SELECT (model)->advertized_nrows and model->priv->pg_pos */
+                       if (nbtuples < model->priv->chunk_size) {
+                               if (model->priv->pg_pos == G_MININT) 
                                        gda_data_select_set_advertized_nrows (GDA_DATA_SELECT (model), 
nbtuples);
                                else
-                                       gda_data_select_set_advertized_nrows (GDA_DATA_SELECT 
(model),priv->pg_pos + nbtuples + 1);
+                                       gda_data_select_set_advertized_nrows (GDA_DATA_SELECT 
(model),model->priv->pg_pos + nbtuples + 1);
 
-                               priv->pg_pos = G_MAXINT;
+                               model->priv->pg_pos = G_MAXINT;                         
                        }
                        else {
-                               if (priv->pg_pos == G_MININT)
-                                       priv->pg_pos = nbtuples - 1;
+                               if (model->priv->pg_pos == G_MININT)
+                                       model->priv->pg_pos = nbtuples - 1;
                                else
-                                       priv->pg_pos += nbtuples;
+                                       model->priv->pg_pos += nbtuples;
                        }
                }
                else {
-                       if (priv->pg_pos == G_MININT)
+                       if (model->priv->pg_pos == G_MININT)
                                gda_data_select_set_advertized_nrows (GDA_DATA_SELECT (model), 0);
                        else
-                               gda_data_select_set_advertized_nrows (GDA_DATA_SELECT (model), priv->pg_pos + 
1); /* total number of rows */
-                       priv->pg_pos = G_MAXINT;
+                               gda_data_select_set_advertized_nrows (GDA_DATA_SELECT (model), 
model->priv->pg_pos + 1); /* total number of rows */
+                       model->priv->pg_pos = G_MAXINT;
                        retval = FALSE;
                }
        }
 
 #ifdef GDA_PG_DEBUG
-       g_print ("--> SIZE = %d (inf = %d) nrows = %d, pg_pos = %d\n", priv->pg_res_size, priv->pg_res_inf,
-                GDA_DATA_SELECT (model)->advertized_nrows, priv->pg_pos);
+       g_print ("--> SIZE = %d (inf = %d) nrows = %d, pg_pos = %d\n", model->priv->pg_res_size, 
model->priv->pg_res_inf,
+                GDA_DATA_SELECT (model)->advertized_nrows, model->priv->pg_pos);
 #endif
 
        return retval;
@@ -895,16 +919,15 @@ fetch_next_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e
 static gboolean
 fetch_prev_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **error)
 {
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (model);
-       if (priv->pg_res) {
-               PQclear (priv->pg_res);
-               priv->pg_res = NULL;
+       if (model->priv->pg_res) {
+               PQclear (model->priv->pg_res);
+               model->priv->pg_res = NULL;
        }
        *fetch_error = FALSE;
 
-       if (priv->pg_pos == G_MININT)
+       if (model->priv->pg_pos == G_MININT) 
                return FALSE;
-       else if (priv->pg_pos == G_MAXINT)
+       else if (model->priv->pg_pos == G_MAXINT) 
                g_assert (gda_data_select_get_advertized_nrows (GDA_DATA_SELECT (model)) >= 0); /* total 
number of rows MUST be known at this point */
 
        gchar *str;
@@ -912,66 +935,66 @@ fetch_prev_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e
        int status;
        gint noffset;
        
-       if (priv->pg_pos == G_MAXINT)
-               noffset = priv->chunk_size + 1;
+       if (model->priv->pg_pos == G_MAXINT)
+               noffset = model->priv->chunk_size + 1;
        else
-               noffset = priv->pg_res_size + priv->chunk_size;
+               noffset = model->priv->pg_res_size + model->priv->chunk_size;
        str = g_strdup_printf ("MOVE BACKWARD %d FROM %s; FETCH FORWARD %d FROM %s;",
-                              noffset, priv->cursor_name,
-                              priv->chunk_size, priv->cursor_name);
+                              noffset, model->priv->cursor_name,
+                              model->priv->chunk_size, model->priv->cursor_name);
 #ifdef GDA_PG_DEBUG
        g_print ("QUERY: %s\n", str);
 #endif
-        priv->pg_res = PQexec (priv->pconn, str);
+        model->priv->pg_res = PQexec (model->priv->pconn, str);
         g_free (str);
-        status = PQresultStatus (priv->pg_res);
-       priv->chunks_read ++;
+        status = PQresultStatus (model->priv->pg_res);
+       model->priv->chunks_read ++;
         if (status != PGRES_TUPLES_OK) {
                _gda_postgres_make_error (gda_data_select_get_connection ((GdaDataSelect*) model),
-                                         priv->pconn, priv->pg_res, error);
-                PQclear (priv->pg_res);
-                priv->pg_res = NULL;
-               priv->pg_res_size = 0;
+                                         model->priv->pconn, model->priv->pg_res, error);
+                PQclear (model->priv->pg_res);
+                model->priv->pg_res = NULL;
+               model->priv->pg_res_size = 0;
                 retval = FALSE;
                *fetch_error = TRUE;
         }
        else {
 #ifdef GDA_PG_DEBUG
-               dump_pg_res (priv->pg_res);
+               dump_pg_res (model->priv->pg_res);
 #endif
 
                 //PQntuples() returns the number of rows in the result:
-                const gint nbtuples = PQntuples (priv->pg_res);
-               priv->pg_res_size = nbtuples;
+                const gint nbtuples = PQntuples (model->priv->pg_res);
+               model->priv->pg_res_size = nbtuples;
 
                 if (nbtuples > 0) {
-                       /* priv->pg_res_inf */
-                       if (priv->pg_pos == G_MAXINT)
-                               priv->pg_res_inf = gda_data_select_get_advertized_nrows (GDA_DATA_SELECT 
(model)) - nbtuples;
+                       /* model->priv->pg_res_inf */
+                       if (model->priv->pg_pos == G_MAXINT)
+                               model->priv->pg_res_inf = gda_data_select_get_advertized_nrows 
(GDA_DATA_SELECT (model)) - nbtuples;
                        else
-                               priv->pg_res_inf =
-                                       MAX (priv->pg_res_inf - (noffset - priv->chunk_size), 0);
+                               model->priv->pg_res_inf = 
+                                       MAX (model->priv->pg_res_inf - (noffset - model->priv->chunk_size), 
0);
 
-                       /* priv->pg_pos */
-                       if (nbtuples < priv->chunk_size) {
-                               priv->pg_pos = G_MAXINT;
+                       /* model->priv->pg_pos */
+                       if (nbtuples < model->priv->chunk_size) {
+                               model->priv->pg_pos = G_MAXINT;
                        }
                        else {
-                               if (priv->pg_pos == G_MAXINT)
-                                       priv->pg_pos = gda_data_select_get_advertized_nrows (GDA_DATA_SELECT 
(model)) - 1;
+                               if (model->priv->pg_pos == G_MAXINT)
+                                       model->priv->pg_pos = gda_data_select_get_advertized_nrows 
(GDA_DATA_SELECT (model)) - 1;
                                else
-                                       priv->pg_pos = MAX (priv->pg_pos - noffset, -1) + nbtuples;
+                                       model->priv->pg_pos = MAX (model->priv->pg_pos - noffset, -1) + 
nbtuples;
                        }
                }
                else {
-                       priv->pg_pos = G_MAXINT;
+                       model->priv->pg_pos = G_MAXINT;
                        retval = FALSE;
                }
        }
 
 #ifdef GDA_PG_DEBUG
-       g_print ("<-- SIZE = %d (inf = %d) nrows = %d, pg_pos = %d\n", priv->pg_res_size, priv->pg_res_inf,
-                GDA_DATA_SELECT (model)->advertized_nrows, priv->pg_pos);
+       g_print ("<-- SIZE = %d (inf = %d) nrows = %d, pg_pos = %d\n", model->priv->pg_res_size, 
model->priv->pg_res_inf,
+                GDA_DATA_SELECT (model)->advertized_nrows, model->priv->pg_pos);
 #endif
 
        return retval;
@@ -980,11 +1003,10 @@ fetch_prev_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e
 static gboolean
 fetch_row_number_chunk (GdaPostgresRecordset *model, int row_index, gboolean *fetch_error, GError **error)
 {
-  GdaPostgresRecordsetPrivate *priv = gda_postgres_recordset_get_instance_private (model);
-  if (priv->pg_res) {
-          PQclear (priv->pg_res);
-          priv->pg_res = NULL;
-  }
+        if (model->priv->pg_res) {
+                PQclear (model->priv->pg_res);
+                model->priv->pg_res = NULL;
+        }
        *fetch_error = FALSE;
 
         gchar *str;
@@ -993,49 +1015,49 @@ fetch_row_number_chunk (GdaPostgresRecordset *model, int row_index, gboolean *fe
 
         /* Postgres's FETCH ABSOLUTE seems to use a 1-based index: */
         str = g_strdup_printf ("FETCH ABSOLUTE %d FROM %s;",
-                               row_index + 1, priv->cursor_name);
+                               row_index + 1, model->priv->cursor_name);
 #ifdef GDA_PG_DEBUG
         g_print ("QUERY: %s\n", str);
 #endif
-        priv->pg_res = PQexec (priv->pconn, str);
+        model->priv->pg_res = PQexec (model->priv->pconn, str);
         g_free (str);
-        status = PQresultStatus (priv->pg_res);
-        priv->chunks_read ++; /* Not really correct, because we are only fetching 1 row, not a whole chunk 
of rows. */
+        status = PQresultStatus (model->priv->pg_res);
+        model->priv->chunks_read ++; /* Not really correct, because we are only fetching 1 row, not a whole 
chunk of rows. */
         if (status != PGRES_TUPLES_OK) {
                _gda_postgres_make_error (gda_data_select_get_connection ((GdaDataSelect*) model), 
-                                         priv->pconn, priv->pg_res, error);
-                PQclear (priv->pg_res);
-                priv->pg_res = NULL;
-                priv->pg_res_size = 0;
+                                         model->priv->pconn, model->priv->pg_res, error);
+                PQclear (model->priv->pg_res);
+                model->priv->pg_res = NULL;
+                model->priv->pg_res_size = 0;
                 retval = FALSE;
                *fetch_error = TRUE;
         }
         else {
 #ifdef GDA_PG_DEBUG
-                dump_pg_res (priv->pg_res);
+                dump_pg_res (model->priv->pg_res);
 #endif
 
                 //PQntuples() returns the number of rows in the result:
-                const gint nbtuples = PQntuples (priv->pg_res);
-                priv->pg_res_size = nbtuples;
+                const gint nbtuples = PQntuples (model->priv->pg_res);
+                model->priv->pg_res_size = nbtuples;
 
                 if (nbtuples > 0) {
                         /* Remember the row number for the start of this chunk:
                          * (actually a chunk of just 1 record in this case.) */
-                        priv->pg_res_inf = row_index;
+                        model->priv->pg_res_inf = row_index;
 
-                        /* don't change priv->nrows because we can't know if we have reached the end */
-                        priv->pg_pos = row_index;
+                        /* don't change model->priv->nrows because we can't know if we have reached the end 
*/
+                        model->priv->pg_pos = row_index;
                 }
                 else {
-                        priv->pg_pos = G_MAXINT;
+                        model->priv->pg_pos = G_MAXINT;
                         retval = FALSE;
                 }
         }
 
 #ifdef GDA_PG_DEBUG
-        g_print ("--> SIZE = %d (inf = %d) nrows = %d, pg_pos = %d\n", priv->pg_res_size, priv->pg_res_inf,
-                 priv->nrows, priv->pg_pos);
+        g_print ("--> SIZE = %d (inf = %d) nrows = %d, pg_pos = %d\n", model->priv->pg_res_size, 
model->priv->pg_res_inf,
+                 model->priv->nrows, model->priv->pg_pos);
 #endif
 
         return retval;
diff --git a/providers/postgres/gda-postgres-recordset.h b/providers/postgres/gda-postgres-recordset.h
index f6cdcad88..fdee82d31 100644
--- a/providers/postgres/gda-postgres-recordset.h
+++ b/providers/postgres/gda-postgres-recordset.h
@@ -4,7 +4,6 @@
  * Copyright (C) 2001 Carlos Perelló Marín <carlos gnome-db org>
  * Copyright (C) 2001 - 2012 Vivien Malerba <malerba gnome-db org>
  * Copyright (C) 2002 Gonzalo Paniagua Javier <gonzalo gnome-db org>
- * Copyright (C) 2019 Daniel Espinosa <esodan gmail com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -32,13 +31,25 @@
 G_BEGIN_DECLS
 
 #define GDA_TYPE_POSTGRES_RECORDSET            (gda_postgres_recordset_get_type())
-
-G_DECLARE_DERIVABLE_TYPE(GdaPostgresRecordset, gda_postgres_recordset, GDA, POSTGRES_RECORDSET,  
GdaDataSelect)
+#define GDA_POSTGRES_RECORDSET(obj)            (G_TYPE_CHECK_INSTANCE_CAST (obj, 
GDA_TYPE_POSTGRES_RECORDSET, GdaPostgresRecordset))
+#define GDA_POSTGRES_RECORDSET_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_POSTGRES_RECORDSET, 
GdaPostgresRecordsetClass))
+#define GDA_IS_POSTGRES_RECORDSET(obj)         (G_TYPE_CHECK_INSTANCE_TYPE (obj, 
GDA_TYPE_POSTGRES_RECORDSET))
+#define GDA_IS_POSTGRES_RECORDSET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GDA_TYPE_POSTGRES_RECORDSET))
+
+typedef struct _GdaPostgresRecordset        GdaPostgresRecordset;
+typedef struct _GdaPostgresRecordsetClass   GdaPostgresRecordsetClass;
+typedef struct _GdaPostgresRecordsetPrivate GdaPostgresRecordsetPrivate;
+
+struct _GdaPostgresRecordset {
+       GdaDataSelect                    model;
+       GdaPostgresRecordsetPrivate     *priv;
+};
 
 struct _GdaPostgresRecordsetClass {
        GdaDataSelectClass               parent_class;
 };
 
+GType         gda_postgres_recordset_get_type   (void) G_GNUC_CONST;
 GdaDataModel *gda_postgres_recordset_new_random (GdaConnection *cnc, GdaPostgresPStmt *ps, GdaSet 
*exec_params, PGresult *pg_res, GType *col_types);
 GdaDataModel *gda_postgres_recordset_new_cursor (GdaConnection *cnc, GdaPostgresPStmt *ps, GdaSet 
*exec_params, gchar *cursor_name, GType *col_types);
 


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