[libgda/pstm] Saving work



commit 261f9fc88b269acdbbc426a01e38d2afa2baf4a8
Author: Daniel Espinosa <esodan gmail com>
Date:   Thu Sep 27 14:30:32 2018 -0500

    Saving work

 libgda/gda-data-select.c             |  42 +++---
 libgda/providers-support/gda-pstmt.c | 249 ++++++++++++++++++++---------------
 libgda/providers-support/gda-pstmt.h |  42 +-----
 libgda/sqlite/gda-sqlite-recordset.c |  16 +--
 4 files changed, 179 insertions(+), 170 deletions(-)
---
diff --git a/libgda/gda-data-select.c b/libgda/gda-data-select.c
index f0e25662c..11f6ce530 100644
--- a/libgda/gda-data-select.c
+++ b/libgda/gda-data-select.c
@@ -4,7 +4,7 @@
  * Copyright (C) 2008 - 2014 Vivien Malerba <malerba gnome-db org>
  * Copyright (C) 2010 David King <davidk openismus com>
  * Copyright (C) 2010 Jonh Wendell <jwendell gnome org>
- * Copyright (C) 2012 Daniel Espinosa <despinosa src gnome org>
+ * Copyright (C) 2012,2018 Daniel Espinosa <despinosa src gnome org>
  * Copyright (C) 2013 Miguel Angel Cabrera Moya <madmac2501 gmail com>
  *
  * This library is free software; you can redistribute it and/or
@@ -743,22 +743,22 @@ create_columns (GdaDataSelect *model)
        if (!model->prep_stmt)
                return;
 
-       if (model->prep_stmt->ncols < 0)
+       if (gda_pstmt_get_ncols (model->prep_stmt) < 0)
                g_error ("INTERNAL implementation error: unknown number of columns in GdaPStmt, \n"
                         "set number of columns before using with GdaDataSelect");
-       if (model->prep_stmt->tmpl_columns) {
+       if (gda_pstmt_get_tmpl_columns (model->prep_stmt)) {
                /* copy template columns */
                GSList *list;
-               for (list = model->prep_stmt->tmpl_columns; list; list = list->next)
+               for (list = gda_pstmt_get_tmpl_columns (model->prep_stmt); list; list = list->next)
                        model->priv->sh->columns = g_slist_append (model->priv->sh->columns, g_object_ref 
(list->data));
        }
        else {
                /* create columns */
-               for (i = 0; i < model->prep_stmt->ncols; i++) {
+               for (i = 0; i < gda_pstmt_get_ncols (model->prep_stmt); i++) {
                        GdaColumn *gda_col;
                        gda_col = gda_column_new ();
-                       if (model->prep_stmt->types)
-                               gda_column_set_g_type (gda_col, model->prep_stmt->types [i]);
+                       if (gda_pstmt_get_types (model->prep_stmt))
+                               gda_column_set_g_type (gda_col, (gda_pstmt_get_types (model->prep_stmt)) [i]);
                        model->priv->sh->columns = g_slist_append (model->priv->sh->columns, gda_col);
                }
        }
@@ -1460,9 +1460,9 @@ gda_data_select_set_modification_statement (GdaDataSelect *model, GdaStatement *
                                        gda_column_set_g_type (gdacol, gda_holder_get_g_type (holder));
                                        coltypeschanged = TRUE;
                                }
-                               if (model->prep_stmt && model->prep_stmt->types &&
-                                   (model->prep_stmt->types [num] == GDA_TYPE_NULL))
-                                       model->prep_stmt->types [num] = gda_holder_get_g_type (holder);
+                               if (model->prep_stmt && gda_pstmt_get_types (model->prep_stmt) &&
+                                   ((gda_pstmt_get_types (model->prep_stmt) [num]) == GDA_TYPE_NULL))
+                                       gda_pstmt_get_types (model->prep_stmt) [num] = gda_holder_get_g_type 
(holder);
                        }
                }
 
@@ -1875,7 +1875,7 @@ gda_data_select_get_n_columns (GdaDataModel *model)
        g_return_val_if_fail (imodel->priv, 0);
 
        if (imodel->prep_stmt)
-               return imodel->prep_stmt->ncols;
+               return gda_pstmt_get_ncols (imodel->prep_stmt);
        else
                return g_slist_length (imodel->priv->sh->columns);
 }
@@ -2043,11 +2043,11 @@ gda_data_select_get_value_at (GdaDataModel *model, gint col, gint row, GError **
                                return NULL;
                        }
                        GType *types = NULL;
-                       if (imodel->prep_stmt && imodel->prep_stmt->types) {
-                               types = g_new (GType, imodel->prep_stmt->ncols + 1);
-                               memcpy (types, imodel->prep_stmt->types, /* Flawfinder: ignore */
-                                       sizeof (GType) * imodel->prep_stmt->ncols);
-                               types [imodel->prep_stmt->ncols] = G_TYPE_NONE;
+                       if (imodel->prep_stmt && gda_pstmt_get_types (imodel->prep_stmt)) {
+                               types = g_new (GType, gda_pstmt_get_ncols (imodel->prep_stmt) + 1);
+                               memcpy (types, gda_pstmt_get_types (imodel->prep_stmt), /* Flawfinder: ignore 
*/
+                                       sizeof (GType) * gda_pstmt_get_ncols (imodel->prep_stmt));
+                               types [gda_pstmt_get_ncols (imodel->prep_stmt)] = G_TYPE_NONE;
                        }
                        /*g_print ("*** Executing DelayedSelectStmt %p\n", dstmt);*/
                        tmpmodel = gda_connection_statement_execute_select_full (imodel->priv->cnc,
@@ -3699,11 +3699,11 @@ gda_data_select_rerun (GdaDataSelect *model, GError **error)
                return FALSE;
        g_assert (model->prep_stmt);
        GType *types = NULL;
-       if (model->prep_stmt->types) {
-               types = g_new (GType, model->prep_stmt->ncols + 1);
-               memcpy (types, model->prep_stmt->types, /* Flawfinder: ignore */
-                       sizeof (GType) * model->prep_stmt->ncols);
-               types [model->prep_stmt->ncols] = G_TYPE_NONE;
+       if (gda_pstmt_get_types (model->prep_stmt)) {
+               types = g_new (GType, gda_pstmt_get_ncols (model->prep_stmt) + 1);
+               memcpy (types,gda_pstmt_get_types (model->prep_stmt), /* Flawfinder: ignore */
+                       sizeof (GType) * gda_pstmt_get_ncols (model->prep_stmt));
+               types [gda_pstmt_get_ncols (model->prep_stmt)] = G_TYPE_NONE;
        }
        new_model = (GdaDataSelect*) gda_connection_statement_execute_select_full (model->priv->cnc, select,
                                                                                   
model->priv->sh->ext_params,
diff --git a/libgda/providers-support/gda-pstmt.c b/libgda/providers-support/gda-pstmt.c
index a674c1d15..d10b2bd80 100644
--- a/libgda/providers-support/gda-pstmt.c
+++ b/libgda/providers-support/gda-pstmt.c
@@ -24,56 +24,29 @@
 #include "gda-pstmt.h"
 #include <string.h>
 
-static void gda_pstmt_class_init (GdaPStmtClass *klass);
-static void gda_pstmt_init       (GdaPStmt *pstmt, GdaPStmtClass *klass);
 static void gda_pstmt_dispose    (GObject *object);
-static void gda_pstmt_finalize   (GObject *object);
+static void gda_pstmt_finalize    (GObject *object);
 
-static GObjectClass *parent_class = NULL;
+typedef struct {
+       gchar        *sql; /* actual SQL code used for this prepared statement, mem freed by GdaPStmt */
+       GSList       *param_ids; /* list of parameters' IDs (as gchar *), mem freed by GdaPStmt */
+
+       /* meta data */
+       gint          ncols;
+       GType        *types; /* array of ncols types */
+       GSList       *tmpl_columns; /* list of #GdaColumn objects which data models created from this prep. 
statement
+                                    * can copy */
 
-struct _GdaPStmtPrivate {
        GRecMutex mutex;
        GWeakRef gda_stmt_ref; /* holds a weak reference to #GdaStatement, or %NULL */
-};
+} GdaPStmtPrivate;
 
-/**
- * gda_pstmt_get_type:
- *
- * Returns: the #GType of GdaPStmt.
- */
-GType
-gda_pstmt_get_type (void)
-{
-       static GType type = 0;
-
-       if (G_UNLIKELY (type == 0)) {
-               static GMutex registering;
-               static const GTypeInfo info = {
-                       sizeof (GdaPStmtClass),
-                       (GBaseInitFunc) NULL,
-                       (GBaseFinalizeFunc) NULL,
-                       (GClassInitFunc) gda_pstmt_class_init,
-                       NULL,
-                       NULL,
-                       sizeof (GdaPStmt),
-                       0,
-                       (GInstanceInitFunc) gda_pstmt_init,
-                       0
-               };
-
-               g_mutex_lock (&registering);
-               if (type == 0)
-                       type = g_type_register_static (G_TYPE_OBJECT, "GdaPStmt", &info, 
G_TYPE_FLAG_ABSTRACT);
-               g_mutex_unlock (&registering);
-       }
-       return type;
-}
+G_DEFINE_TYPE_WITH_PRIVATE (GdaPStmt, gda_pstmt, G_TYPE_OBJECT)
 
 static void 
 gda_pstmt_class_init (GdaPStmtClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
-       parent_class = g_type_class_peek_parent (klass);
 
        /* virtual functions */
        object_class->dispose = gda_pstmt_dispose;
@@ -81,17 +54,17 @@ gda_pstmt_class_init (GdaPStmtClass *klass)
 }
 
 static void
-gda_pstmt_init (GdaPStmt *pstmt, G_GNUC_UNUSED GdaPStmtClass *klass)
+gda_pstmt_init (GdaPStmt *pstmt)
 {
        g_return_if_fail (GDA_IS_PSTMT (pstmt));
-       pstmt->priv = g_new0 (GdaPStmtPrivate, 1);
-       g_rec_mutex_init (& pstmt->priv->mutex);
-       g_weak_ref_init (&pstmt->priv->gda_stmt_ref, NULL);
-       pstmt->sql = NULL;
-       pstmt->param_ids = NULL;
-       pstmt->ncols = -1;
-       pstmt->types = NULL;
-       pstmt->tmpl_columns = NULL;
+       GdaPStmtPrivate *priv = gda_pstmt_init_get_instance_private (pstmt);
+       g_rec_mutex_init (& priv->mutex);
+       g_weak_ref_init (&priv->gda_stmt_ref, NULL);
+       priv->sql = NULL;
+       priv->param_ids = NULL;
+       priv->ncols = -1;
+       priv->types = NULL;
+       priv->tmpl_columns = NULL;
 }
 
 /*
@@ -100,7 +73,8 @@ gda_pstmt_init (GdaPStmt *pstmt, G_GNUC_UNUSED GdaPStmtClass *klass)
 static void
 gda_stmt_reset_cb (GdaStatement *stmt, GdaPStmt *pstmt)
 {
-       g_rec_mutex_lock (& pstmt->priv->mutex);
+       GdaPStmtPrivate *priv = gda_pstmt_init_get_instance_private (pstmt);
+       g_rec_mutex_lock (& priv->mutex);
        if (stmt) {
                g_object_ref (stmt);
                g_signal_handlers_disconnect_by_func (G_OBJECT (stmt),
@@ -108,7 +82,7 @@ gda_stmt_reset_cb (GdaStatement *stmt, GdaPStmt *pstmt)
                g_object_unref (stmt);
        }
        else {
-               GdaStatement *stm = g_weak_ref_get (& pstmt->priv->gda_stmt_ref);
+               GdaStatement *stm = g_weak_ref_get (& priv->gda_stmt_ref);
                if (stm) {
                        g_signal_handlers_disconnect_by_func (G_OBJECT (stm),
                                                              G_CALLBACK (gda_stmt_reset_cb), pstmt);
@@ -116,8 +90,8 @@ gda_stmt_reset_cb (GdaStatement *stmt, GdaPStmt *pstmt)
                }
        }
 
-       g_weak_ref_set (& pstmt->priv->gda_stmt_ref, NULL);
-       g_rec_mutex_unlock (& pstmt->priv->mutex);
+       g_weak_ref_set (& priv->gda_stmt_ref, NULL);
+       g_rec_mutex_unlock (& priv->mutex);
 }
 
 static void
@@ -128,39 +102,39 @@ gda_pstmt_dispose (GObject *object)
        gda_stmt_reset_cb (NULL, pstmt);
 
        /* chain to parent class */
-       parent_class->dispose (object);
+       G_OBJECT_CLASS (gda_pstmt_parent_class)->dispose (object);
 }
 
 static void
 gda_pstmt_finalize (GObject *object)
 {
        GdaPStmt *pstmt = (GdaPStmt *) object;
+       GdaPStmtPrivate *priv = gda_pstmt_init_get_instance_private (pstmt);
 
        /* free memory */
-       g_rec_mutex_clear (& pstmt->priv->mutex);
-       g_weak_ref_clear (&pstmt->priv->gda_stmt_ref);
-       g_free (pstmt->priv);
+       g_rec_mutex_clear (& priv->mutex);
+       g_weak_ref_clear (&priv->gda_stmt_ref);
 
-       if (pstmt->sql) {
-               g_free (pstmt->sql);
-               pstmt->sql = NULL;
+       if (priv->sql) {
+               g_free (priv->sql);
+               priv->sql = NULL;
        }
-       if (pstmt->param_ids) {
-               g_slist_foreach (pstmt->param_ids, (GFunc) g_free, NULL);
-               g_slist_free (pstmt->param_ids);
-               pstmt->param_ids = NULL;
+       if (priv->param_ids) {
+               g_slist_foreach (priv->param_ids, (GFunc) g_free, NULL);
+               g_slist_free (priv->param_ids);
+               priv->param_ids = NULL;
        }
-       if (pstmt->types) {
-               g_free (pstmt->types);
-               pstmt->types = NULL;
+       if (priv->types) {
+               g_free (priv->types);
+               priv->types = NULL;
        }
-       if (pstmt->tmpl_columns) {
-               g_slist_foreach (pstmt->tmpl_columns, (GFunc) g_object_unref, NULL);
-               g_slist_free (pstmt->tmpl_columns);
+       if (priv->tmpl_columns) {
+               g_slist_foreach (priv->tmpl_columns, (GFunc) g_object_unref, NULL);
+               g_slist_free (priv->tmpl_columns);
        }
 
        /* chain to parent class */
-       parent_class->finalize (object);
+       G_OBJECT_CLASS (gda_pstmt_parent_class)->finalize (object);
 }
 
 /**
@@ -175,25 +149,26 @@ gda_pstmt_set_gda_statement (GdaPStmt *pstmt, GdaStatement *stmt)
 {
        g_return_if_fail (GDA_IS_PSTMT (pstmt));
        g_return_if_fail (!stmt || GDA_IS_STATEMENT (stmt));
+       GdaPStmtPrivate *priv = gda_pstmt_init_get_instance_private (pstmt);
 
-       g_rec_mutex_lock (& pstmt->priv->mutex);
+       g_rec_mutex_lock (& priv->mutex);
        g_object_ref (stmt);
 
        GdaStatement *estmt;
-       estmt = g_weak_ref_get (& pstmt->priv->gda_stmt_ref);
+       estmt = g_weak_ref_get (& priv->gda_stmt_ref);
        if (estmt == stmt) {
                if (estmt)
                        g_object_unref (estmt);
-               g_rec_mutex_unlock (& pstmt->priv->mutex);
+               g_rec_mutex_unlock (& priv->mutex);
                return;
        }
 
        gda_stmt_reset_cb (NULL, pstmt);
 
-       g_weak_ref_set (& pstmt->priv->gda_stmt_ref, stmt);
+       g_weak_ref_set (& priv->gda_stmt_ref, stmt);
        g_signal_connect (G_OBJECT (stmt), "reset", G_CALLBACK (gda_stmt_reset_cb), pstmt);
        g_object_unref (stmt);
-       g_rec_mutex_unlock (& pstmt->priv->mutex);
+       g_rec_mutex_unlock (& priv->mutex);
 }
 
 /**
@@ -209,44 +184,46 @@ gda_pstmt_copy_contents (GdaPStmt *src, GdaPStmt *dest)
        GSList *list;
        g_return_if_fail (GDA_IS_PSTMT (src));
        g_return_if_fail (GDA_IS_PSTMT (dest));
+       GdaPStmtPrivate *spriv = gda_pstmt_init_get_instance_private (src);
+       GdaPStmtPrivate *dpriv = gda_pstmt_init_get_instance_private (dest);
 
-       g_rec_mutex_lock (& src->priv->mutex);
-       g_rec_mutex_lock (& dest->priv->mutex);
-
-       g_free (dest->sql);
-       dest->sql = NULL;
-       if (src->sql)
-               dest->sql = g_strdup (src->sql);
-       if (dest->param_ids) {
-               g_slist_foreach (dest->param_ids, (GFunc) g_free, NULL);
-               g_slist_free (dest->param_ids);
-               dest->param_ids = NULL;
+       g_rec_mutex_lock (& spriv->mutex);
+       g_rec_mutex_lock (& dpriv->mutex);
+
+       g_free (dpriv->sql);
+       dpriv->sql = NULL;
+       if (spriv->sql)
+               dpriv->sql = g_strdup (spriv->sql);
+       if (dpriv->param_ids) {
+               g_slist_foreach (dpriv->param_ids, (GFunc) g_free, NULL);
+               g_slist_free (dpriv->param_ids);
+               dpriv->param_ids = NULL;
        }
-       for (list = src->param_ids; list; list = list->next) 
-               dest->param_ids = g_slist_append (dest->param_ids, g_strdup ((gchar *) list->data));
-       dest->ncols = src->ncols;
-
-       g_free (dest->types);
-       dest->types = NULL;
-       if (src->types) {
-               dest->types = g_new (GType, dest->ncols);
-               memcpy (dest->types, src->types, sizeof (GType) * dest->ncols); /* Flawfinder: ignore */
+       for (list = spriv->param_ids; list; list = list->next)
+               dpriv->param_ids = g_slist_append (dpriv->param_ids, g_strdup ((gchar *) list->data));
+       dpriv->ncols = spriv->ncols;
+
+       g_free (dpriv->types);
+       dpriv->types = NULL;
+       if (spriv->types) {
+               dpriv->types = g_new (GType, dpriv->ncols);
+               memcpy (dpriv->types, spriv->types, sizeof (GType) * dpriv->ncols); /* Flawfinder: ignore */
        }
-       if (src->tmpl_columns) {
+       if (spriv->tmpl_columns) {
                GSList *list;
-               for (list = src->tmpl_columns; list; list = list->next) 
-                       dest->tmpl_columns = g_slist_append (dest->tmpl_columns, 
+               for (list = spriv->tmpl_columns; list; list = list->next)
+                       dpriv->tmpl_columns = g_slist_append (dpriv->tmpl_columns,
                                                             gda_column_copy (GDA_COLUMN (list->data)));
        }
        GdaStatement *stmt;
-       stmt = g_weak_ref_get (& src->priv->gda_stmt_ref);
+       stmt = g_weak_ref_get (& spriv->gda_stmt_ref);
        if (stmt) {
                gda_pstmt_set_gda_statement (dest, stmt);
                g_object_unref (stmt);
        }
 
-       g_rec_mutex_unlock (& src->priv->mutex);
-       g_rec_mutex_unlock (& dest->priv->mutex);
+       g_rec_mutex_unlock (& spriv->mutex);
+       g_rec_mutex_unlock (& dpriv->mutex);
 
 }
 
@@ -265,11 +242,75 @@ GdaStatement *
 gda_pstmt_get_gda_statement (GdaPStmt *pstmt)
 {
        g_return_val_if_fail (GDA_IS_PSTMT (pstmt), NULL);
-       g_rec_mutex_lock (& pstmt->priv->mutex);
+       GdaPStmtPrivate *priv = gda_pstmt_init_get_instance_private (pstmt);
+       g_rec_mutex_lock (& priv->mutex);
        GdaStatement *stmt;
-       stmt = g_weak_ref_get (& pstmt->priv->gda_stmt_ref);
+       stmt = g_weak_ref_get (& priv->gda_stmt_ref);
        if (stmt)
                g_object_unref (stmt);
-       g_rec_mutex_unlock (& pstmt->priv->mutex);
+       g_rec_mutex_unlock (& priv->mutex);
        return stmt;
 }
+
+/**
+ * gda_pstmt_get_ncols:
+ * @pstmt: a #GdaPStmt
+ *
+ * Returns: number of columns in preprared statement
+ */
+gint
+gda_pstmt_get_ncols (GdaPStmt *pstmt) {
+       g_return_val_if_fail (GDA_IS_PSTMT (pstmt), -1);
+       GdaPStmtPrivate *priv = gda_pstmt_init_get_instance_private (pstmt);
+       return priv->ncols;
+}
+/**
+ * gda_pstmt_get_tmpl_columns:
+ * @pstmt: a #GdaPStmt
+ *
+ * Returns: (transfer none) (element-type Gda.Column): list of columns
+ */
+GSList*
+gda_pstmt_get_tmpl_columns (GdaPStmt *pstmt) {
+       g_return_val_if_fail (GDA_IS_PSTMT (pstmt), NULL);
+       GdaPStmtPrivate *priv = gda_pstmt_init_get_instance_private (pstmt);
+       return priv->tmpl_columns;
+}
+/**
+ * gda_pstmt_has_types:
+ * @pstmt: a #GdaPStmt
+ *
+ * List of types of the columns.
+ *
+ * Returns: (transfer none) (array) (element-type GLib.Type): list of columns' types
+ */
+GType*
+gda_pstmt_get_types (GdaPStmt *pstmt) {
+       g_return_val_if_fail (GDA_IS_PSTMT (pstmt), FALSE);
+       GdaPStmtPrivate *priv = gda_pstmt_init_get_instance_private (pstmt);
+       return priv->types;
+}
+
+/**
+ * gda_pstmt_has_types:
+ * @pstmt: a #GdaPStmt
+ * @ncols: number of columns to set
+ *
+ * Set the number of columns in the prepared statement. Resets this statement
+ * and its column's types to #GDA_TYPE_NULL
+ *
+ * Returns: (transfer none) (array) (element-type GLib.Type): list of columns' types
+ */
+void
+gda_pstmt_set_columns (GdaPStmt *pstmt, gint ncols) {
+       g_return_if_fail (GDA_IS_PSTMT (pstmt));
+       g_return_if_fail (ncols > 0);
+       GdaPStmtPrivate *priv = gda_pstmt_init_get_instance_private (pstmt);
+       gda_stmt_reset_cb (NULL, pstmt);
+
+       priv->ncols = ncols;
+       priv->types = g_new0 (GType, ncols);
+       for (int i = 0; i < ncols; i++) {
+               priv->types[i] = GDA_TYPE_NULL;
+       }
+}
diff --git a/libgda/providers-support/gda-pstmt.h b/libgda/providers-support/gda-pstmt.h
index 9bcefbebf..7c8eaa337 100644
--- a/libgda/providers-support/gda-pstmt.h
+++ b/libgda/providers-support/gda-pstmt.h
@@ -27,43 +27,7 @@
 G_BEGIN_DECLS
 
 #define GDA_TYPE_PSTMT            (gda_pstmt_get_type())
-#define GDA_PSTMT(obj)            (G_TYPE_CHECK_INSTANCE_CAST (obj, GDA_TYPE_PSTMT, GdaPStmt))
-#define GDA_PSTMT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST (klass, GDA_TYPE_PSTMT, GdaPStmtClass))
-#define GDA_IS_PSTMT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE(obj, GDA_TYPE_PSTMT))
-#define GDA_IS_PSTMT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GDA_TYPE_PSTMT))
-
-typedef struct _GdaPStmt        GdaPStmt;
-typedef struct _GdaPStmtPrivate GdaPStmtPrivate;
-typedef struct _GdaPStmtClass   GdaPStmtClass;
-
-/**
- * GdaPStmt:
- * @sql: actual SQL code used for this prepared statement, mem freed by GdaPStmt
- * @param_ids: (element-type utf8): list of parameters' IDs (as gchar *), mem freed by GdaPStmt
- * @ncols: number of types in array
- * @types: (array length=ncols) (element-type GLib.Type): array of ncols types
- * @tmpl_columns: (element-type Gda.Column): list of #GdaColumn objects which data models created from this 
prep. statement can copy
- *
- */
-struct _GdaPStmt {
-       GObject       object;
-
-       GdaPStmtPrivate *priv;
-       gchar        *sql; /* actual SQL code used for this prepared statement, mem freed by GdaPStmt */
-        GSList       *param_ids; /* list of parameters' IDs (as gchar *), mem freed by GdaPStmt */
-
-       /* meta data */
-        gint          ncols;
-        GType        *types; /* array of ncols types */
-       GSList       *tmpl_columns; /* list of #GdaColumn objects which data models created from this prep. 
statement
-                                    * can copy */
-
-       /*< private >*/
-       /* Padding for future expansion */
-       gpointer         _gda_reserved1;
-       gpointer         _gda_reserved2;
-};
-
+G_DECLARE_DERIVABLE_TYPE (GdaPStmt, gda_pstmt, GDA, PSTMT, GObject)
 struct _GdaPStmtClass {
        GObjectClass  parent_class;
 
@@ -107,6 +71,10 @@ GType         gda_pstmt_get_type          (void) G_GNUC_CONST;
 void          gda_pstmt_set_gda_statement (GdaPStmt *pstmt, GdaStatement *stmt);
 void          gda_pstmt_copy_contents     (GdaPStmt *src, GdaPStmt *dest);
 GdaStatement *gda_pstmt_get_gda_statement (GdaPStmt *pstmt);
+gint          gda_pstmt_get_ncols         (GdaPStmt *pstmt);
+GSList       *gda_pstmt_get_tmpl_columns  (GdaPStmt *pstmt);
+GType        *gda_pstmt_get_types         (GdaPStmt *pstmt);
+void          gda_pstmt_set_columns       (GdaPStmt *pstmt, gint ncols, GType* types);
 
 G_END_DECLS
 
diff --git a/libgda/sqlite/gda-sqlite-recordset.c b/libgda/sqlite/gda-sqlite-recordset.c
index 22db1e26a..aa7bff8e4 100644
--- a/libgda/sqlite/gda-sqlite-recordset.c
+++ b/libgda/sqlite/gda-sqlite-recordset.c
@@ -10,7 +10,7 @@
  * Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
  * Copyright (C) 2010 David King <davidk openismus com>
  * Copyright (C) 2011 Marco Ciampa <ciampix libero it>
- * Copyright (C) 2017 Daniel Espinosa <esodan gmail com>
+ * Copyright (C) 2017, 2018 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
@@ -164,9 +164,9 @@ read_rows_to_init_col_types (GdaSqliteRecordset *model)
        gint *missing_cols, nb_missing;
        GdaDataSelect *pmodel = (GdaDataSelect*) model;
 
-       missing_cols = g_new (gint, pmodel->prep_stmt->ncols);
-       for (nb_missing = 0, i = 0; i < pmodel->prep_stmt->ncols; i++) {
-               if (pmodel->prep_stmt->types[i] == GDA_TYPE_NULL)
+       missing_cols = g_new (gint, gda_pstmt_get_ncols (pmodel->prep_stmt));
+       for (nb_missing = 0, i = 0; i < gda_pstmt_get_ncols (pmodel->prep_stmt); i++) {
+               if (gda_pstmt_get_types (pmodel->prep_stmt)[i] == GDA_TYPE_NULL)
                        missing_cols [nb_missing++] = i;
        }
 
@@ -184,10 +184,10 @@ read_rows_to_init_col_types (GdaSqliteRecordset *model)
                g_print ("Prefetched row %d of model %p\n", model->priv->next_row_num - 1, pmodel);
 #endif
                for (i = nb_missing - 1; i >= 0; i--) {
-                       if (pmodel->prep_stmt->types [missing_cols [i]] != GDA_TYPE_NULL) {
+                       if (gda_pstmt_get_types (pmodel->prep_stmt) [missing_cols [i]] != GDA_TYPE_NULL) {
 #ifdef GDA_DEBUG_NO
                                g_print ("Found type '%s' for col %d\n", 
-                                        g_type_name (pmodel->prep_stmt->types [missing_cols [i]]),
+                                        g_type_name (gda_pstmt_get_types (pmodel->prep_stmt) [missing_cols 
[i]]),
                                         missing_cols [i]);
 #endif
                                memmove (missing_cols + i, missing_cols + i + 1, sizeof (gint) * (nb_missing 
- i - 1));
@@ -228,14 +228,14 @@ _gda_sqlite_recordset_new (GdaConnection *cnc, GdaSqlitePStmt *ps, GdaSet *exec_
                 _gda_sqlite_compute_types_hash (cdata);
 
         /* make sure @ps reports the correct number of columns */
-       if (_GDA_PSTMT (ps)->ncols < 0)
+       if (gda_pstmt_get_ncols (_GDA_PSTMT (ps)) < 0)
                _GDA_PSTMT (ps)->ncols = SQLITE3_CALL (sqlite3_column_count) (ps->sqlite_stmt) -
                        ps->nb_rowid_columns;
 
         /* completing ps */
        g_assert (! ps->stmt_used);
         ps->stmt_used = TRUE;
-        if (!_GDA_PSTMT (ps)->types && (_GDA_PSTMT (ps)->ncols > 0)) {
+        if (!gda_pstmt_get_types (_GDA_PSTMT (ps)) && (_GDA_PSTMT (ps)->ncols > 0)) {
                /* create prepared statement's columns */
                GSList *list;
                for (i = 0; i < _GDA_PSTMT (ps)->ncols; i++)


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