[libgda] data-select: modernization: removing public fields
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] data-select: modernization: removing public fields
- Date: Wed, 13 Feb 2019 19:20:29 +0000 (UTC)
commit 09fa2642e6d9635693a20d81fc78e05b2c54ea36
Author: Daniel Espinosa Ortiz <esodan gmail com>
Date: Wed Feb 13 13:17:48 2019 -0600
data-select: modernization: removing public fields
Removing public fields from GdaDataSelect object
instance struct.
libgda/gda-data-select-extra.h | 5 +
libgda/gda-data-select.c | 135 ++++++++++++---------
libgda/gda-data-select.h | 5 -
libgda/sqlite/gda-sqlite-recordset.c | 25 ++--
providers/mysql/gda-mysql-recordset.c | 27 +++--
providers/postgres/gda-postgres-recordset.c | 37 +++---
.../skel-implementation/capi/gda-capi-recordset.c | 7 +-
7 files changed, 133 insertions(+), 108 deletions(-)
---
diff --git a/libgda/gda-data-select-extra.h b/libgda/gda-data-select-extra.h
index a4fea2194..12a25d04d 100644
--- a/libgda/gda-data-select-extra.h
+++ b/libgda/gda-data-select-extra.h
@@ -60,6 +60,11 @@ GdaDataSelectInternals *_gda_data_select_internals_steal (GdaDataSelect *model);
void _gda_data_select_internals_paste (GdaDataSelect *model, GdaDataSelectInternals
*inter);
void _gda_data_select_internals_free (GdaDataSelectInternals *inter);
+GdaPStmt *_gda_data_select_get_prep_stmt (GdaDataSelect *model);
+gint _gda_data_select_get_nb_stored_rows (GdaDataSelect *model);
+gint _gda_data_select_get_advertized_nrows (GdaDataSelect *model);
+void _gda_data_select_set_advertized_nrows (GdaDataSelect *model, gint n);
+
G_END_DECLS
#endif
diff --git a/libgda/gda-data-select.c b/libgda/gda-data-select.c
index bca815a02..8045c17b6 100644
--- a/libgda/gda-data-select.c
+++ b/libgda/gda-data-select.c
@@ -108,6 +108,9 @@ struct _GdaDataSelectPrivate {
PrivateShareable *sh;
gulong ext_params_changed_sig_id;
gdouble exec_time;
+ GdaPStmt *prep_stmt; /* use the "prepared-stmt" property to set this */
+ gint nb_stored_rows; /* number of GdaRow objects currently stored */
+ gint advertized_nrows; /* set when the number of rows becomes known, -1 until then
*/
};
/* properties */
@@ -433,10 +436,10 @@ gda_data_select_init (GdaDataSelect *model, G_GNUC_UNUSED GdaDataSelectClass *kl
model->priv->sh-> notify_changes = TRUE;
model->priv->sh->rows = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
model->priv->sh->index = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
- model->prep_stmt = NULL;
+ model->priv->prep_stmt = NULL;
model->priv->sh->columns = NULL;
- model->nb_stored_rows = 0;
- model->advertized_nrows = -1; /* unknown number of rows */
+ model->priv->nb_stored_rows = 0;
+ model->priv->advertized_nrows = -1; /* unknown number of rows */
model->priv->sh->sel_stmt = NULL;
model->priv->sh->ext_params = NULL;
@@ -565,9 +568,9 @@ gda_data_select_dispose (GObject *object)
g_object_unref (model->priv->iter);
model->priv->iter = NULL;
}
- if (model->prep_stmt) {
- g_object_unref (model->prep_stmt);
- model->prep_stmt = NULL;
+ if (model->priv->prep_stmt) {
+ g_object_unref (model->priv->prep_stmt);
+ model->priv->prep_stmt = NULL;
}
if (model->priv->ext_params_changed_sig_id) {
g_signal_handler_disconnect (model->priv->sh->ext_params,
@@ -727,24 +730,24 @@ create_columns (GdaDataSelect *model)
g_free (model->priv->sh->modif_internals->cols_mod[m]);
model->priv->sh->modif_internals->cols_mod[m] = NULL;
}
- if (!model->prep_stmt)
+ if (!model->priv->prep_stmt)
return;
- if (model->prep_stmt->ncols < 0)
+ if (model->priv->prep_stmt->ncols < 0)
g_error (_("INTERNAL implementation error: unknown number of columns in GdaPStmt, \nset
number of columns before using with GdaDataSelect"));
- if (model->prep_stmt->tmpl_columns) {
+ if (model->priv->prep_stmt->tmpl_columns) {
/* copy template columns */
GSList *list;
- for (list = model->prep_stmt->tmpl_columns; list; list = list->next)
+ for (list = model->priv->prep_stmt->tmpl_columns; 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 < model->priv->prep_stmt->ncols; 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 (model->priv->prep_stmt->types)
+ gda_column_set_g_type (gda_col, model->priv->prep_stmt->types [i]);
model->priv->sh->columns = g_slist_append (model->priv->sh->columns, gda_col);
}
}
@@ -769,13 +772,13 @@ gda_data_select_set_property (GObject *object,
}
break;
case PROP_PREP_STMT:
- if (model->prep_stmt)
- g_object_unref (model->prep_stmt);
- model->prep_stmt = g_value_get_object (value);
- if (model->prep_stmt) {
+ if (model->priv->prep_stmt)
+ g_object_unref (model->priv->prep_stmt);
+ model->priv->prep_stmt = g_value_get_object (value);
+ if (model->priv->prep_stmt) {
GdaStatement *sel_stmt;
- g_object_ref (model->prep_stmt);
- sel_stmt = gda_pstmt_get_gda_statement (model->prep_stmt);
+ g_object_ref (model->priv->prep_stmt);
+ sel_stmt = gda_pstmt_get_gda_statement (model->priv->prep_stmt);
if (sel_stmt &&
gda_statement_get_statement_type (sel_stmt) == GDA_SQL_STATEMENT_SELECT) {
model->priv->sh->sel_stmt = gda_statement_copy (sel_stmt);
@@ -861,7 +864,7 @@ gda_data_select_get_property (GObject *object,
g_value_set_object (value, model->priv->cnc);
break;
case PROP_PREP_STMT:
- g_value_set_object (value, model->prep_stmt);
+ g_value_set_object (value, model->priv->prep_stmt);
break;
case PROP_FLAGS:
g_value_set_uint (value, model->priv->sh->usage_flags);
@@ -870,9 +873,9 @@ gda_data_select_get_property (GObject *object,
if (!model->priv->sh->usage_flags & GDA_DATA_MODEL_ACCESS_RANDOM)
g_warning ("Cannot set the 'store-all-rows' property when access mode is
cursor based");
else {
- if ((model->advertized_nrows < 0) && CLASS (model)->fetch_nb_rows)
+ if ((model->priv->advertized_nrows < 0) && CLASS (model)->fetch_nb_rows)
_gda_data_select_fetch_nb_rows (model);
- g_value_set_boolean (value, model->nb_stored_rows == model->advertized_nrows);
+ g_value_set_boolean (value, model->priv->nb_stored_rows ==
model->priv->advertized_nrows);
}
break;
case PROP_PARAMS:
@@ -938,7 +941,7 @@ gda_data_select_take_row (GdaDataSelect *model, GdaRow *row, gint rownum)
ptr [1] = model->priv->sh->rows->len;
g_hash_table_insert (model->priv->sh->index, ptr, ptr+1);
g_ptr_array_add (model->priv->sh->rows, row);
- model->nb_stored_rows = model->priv->sh->rows->len;
+ model->priv->nb_stored_rows = model->priv->sh->rows->len;
}
/**
@@ -1168,13 +1171,13 @@ check_acceptable_statement (GdaDataSelect *model, GError **error)
if (model->priv->sh->sel_stmt)
return model->priv->sh->sel_stmt;
- if (! model->prep_stmt) {
+ if (! model->priv->prep_stmt) {
g_set_error (error, GDA_DATA_SELECT_ERROR, GDA_DATA_SELECT_MODIFICATION_STATEMENT_ERROR,
"%s", _("Internal error: the \"prepared-stmt\" property has not been set"));
return NULL;
}
- sel_stmt = gda_pstmt_get_gda_statement (model->prep_stmt);
+ sel_stmt = gda_pstmt_get_gda_statement (model->priv->prep_stmt);
if (! sel_stmt) {
g_set_error (error, GDA_DATA_SELECT_ERROR, GDA_DATA_SELECT_MODIFICATION_STATEMENT_ERROR,
"%s", _("Can't get the prepared statement's actual statement"));
@@ -1453,9 +1456,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->priv->prep_stmt && model->priv->prep_stmt->types &&
+ (model->priv->prep_stmt->types [num] == GDA_TYPE_NULL))
+ model->priv->prep_stmt->types [num] = gda_holder_get_g_type (holder);
}
}
@@ -1850,8 +1853,8 @@ gda_data_select_get_n_rows (GdaDataModel *model)
imodel = GDA_DATA_SELECT (model);
g_return_val_if_fail (imodel->priv, 0);
- retval = imodel->advertized_nrows;
- if ((imodel->advertized_nrows < 0) &&
+ retval = imodel->priv->advertized_nrows;
+ if ((imodel->priv->advertized_nrows < 0) &&
(imodel->priv->sh->usage_flags & GDA_DATA_MODEL_ACCESS_RANDOM) &&
CLASS (model)->fetch_nb_rows)
retval = _gda_data_select_fetch_nb_rows (imodel);
@@ -1869,10 +1872,10 @@ gda_data_select_get_n_columns (GdaDataModel *model)
imodel = GDA_DATA_SELECT (model);
g_return_val_if_fail (imodel->priv, 0);
- if (imodel->prep_stmt)
- return imodel->prep_stmt->ncols;
- else
- return g_slist_length (imodel->priv->sh->columns);
+ if (imodel->priv->prep_stmt)
+ return imodel->priv->prep_stmt->ncols;
+
+ return g_slist_length (imodel->priv->sh->columns);
}
static GdaColumn *
@@ -1940,8 +1943,8 @@ external_to_internal_row (GdaDataSelect *model, gint ext_row, GError **error)
}
/* check row number validity */
- nrows = model->advertized_nrows < 0 ? gda_data_select_get_n_rows ((GdaDataModel*) model) :
- model->advertized_nrows;
+ nrows = model->priv->advertized_nrows < 0 ? gda_data_select_get_n_rows ((GdaDataModel*) model) :
+ model->priv->advertized_nrows;
if ((ext_row < 0) || ((nrows >= 0) && (int_row >= nrows))) {
gint n;
n = gda_data_select_get_n_rows ((GdaDataModel*) model);
@@ -2038,11 +2041,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->priv->prep_stmt && imodel->priv->prep_stmt->types) {
+ types = g_new (GType, imodel->priv->prep_stmt->ncols + 1);
+ memcpy (types, imodel->priv->prep_stmt->types, /* Flawfinder: ignore */
+ sizeof (GType) * imodel->priv->prep_stmt->ncols);
+ types [imodel->priv->prep_stmt->ncols] = G_TYPE_NONE;
}
/*g_print ("*** Executing DelayedSelectStmt %p\n", dstmt);*/
tmpmodel = gda_connection_statement_execute_select_full (imodel->priv->cnc,
@@ -2275,8 +2278,8 @@ gda_data_select_iter_prev (GdaDataModel *model, GdaDataModelIter *iter)
if (imodel->priv->sh->iter_row <= 0)
goto prev_error;
else if (imodel->priv->sh->iter_row == G_MAXINT) {
- g_assert (imodel->advertized_nrows >= 0);
- target_iter_row = imodel->advertized_nrows - 1;
+ g_assert (imodel->priv->advertized_nrows >= 0);
+ target_iter_row = imodel->priv->advertized_nrows - 1;
}
else
target_iter_row = imodel->priv->sh->iter_row - 1;
@@ -3126,12 +3129,12 @@ gda_data_select_append_values (GdaDataModel *model, const GList *values, GError
}
/* compute added row's number */
- row = imodel->advertized_nrows;
+ row = imodel->priv->advertized_nrows;
if (imodel->priv->sh->del_rows)
row -= imodel->priv->sh->del_rows->len;
- imodel->advertized_nrows++;
+ imodel->priv->advertized_nrows++;
int_row = external_to_internal_row (imodel, row, error);
- imodel->advertized_nrows--;
+ imodel->priv->advertized_nrows--;
/* BVector */
BVector *bv;
@@ -3281,7 +3284,7 @@ gda_data_select_append_values (GdaDataModel *model, const GList *values, GError
#ifdef GDA_DEBUG_NO
dump_d (imodel);
#endif
- imodel->advertized_nrows++;
+ imodel->priv->advertized_nrows++;
gda_data_model_row_inserted ((GdaDataModel *) imodel, row);
return row;
@@ -3692,13 +3695,13 @@ gda_data_select_rerun (GdaDataSelect *model, GError **error)
select = check_acceptable_statement (model, error);
if (!select)
return FALSE;
- g_assert (model->prep_stmt);
+ g_assert (model->priv->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 (model->priv->prep_stmt->types) {
+ types = g_new (GType, model->priv->prep_stmt->ncols + 1);
+ memcpy (types, model->priv->prep_stmt->types, /* Flawfinder: ignore */
+ sizeof (GType) * model->priv->prep_stmt->ncols);
+ types [model->priv->prep_stmt->ncols] = G_TYPE_NONE;
}
new_model = (GdaDataSelect*) gda_connection_statement_execute_select_full (model->priv->cnc, select,
model->priv->sh->ext_params,
@@ -3857,17 +3860,17 @@ gda_data_select_prepare_for_offline (GdaDataSelect *model, GError **error)
}
/* fetching data */
- if (model->advertized_nrows < 0) {
+ if (model->priv->advertized_nrows < 0) {
if (CLASS (model)->fetch_nb_rows)
_gda_data_select_fetch_nb_rows (model);
- if (model->advertized_nrows < 0) {
+ if (model->priv->advertized_nrows < 0) {
g_set_error (error, GDA_DATA_SELECT_ERROR, GDA_DATA_SELECT_ACCESS_ERROR,
"%s", _("Can't get the number of rows of data model"));
return FALSE;
}
}
- if (model->nb_stored_rows != model->advertized_nrows) {
+ if (model->priv->nb_stored_rows != model->priv->advertized_nrows) {
if (CLASS (model)->store_all) {
if (! _gda_data_select_store_all (model, error))
return FALSE;
@@ -3875,7 +3878,7 @@ gda_data_select_prepare_for_offline (GdaDataSelect *model, GError **error)
}
/* final check/complement */
- for (i = 0; i < model->advertized_nrows; i++) {
+ for (i = 0; i < model->priv->advertized_nrows; i++) {
if (!g_hash_table_lookup (model->priv->sh->index, &i)) {
GdaRow *prow;
if (! _gda_data_select_fetch_at (model, &prow, i, error))
@@ -4090,4 +4093,22 @@ _gda_data_select_fetch_at (GdaDataSelect *model, GdaRow **prow, gint rownum
return result ? TRUE : FALSE;
}
+/* Private API for providers */
+GdaPStmt*
+_gda_data_select_get_prep_stmt (GdaDataSelect *model) {
+ return model->priv->prep_stmt;
+}
+
+gint
+_gda_data_select_get_nb_stored_rows (GdaDataSelect *model) {
+ return model->priv->nb_stored_rows;
+}
+gint
+_gda_data_select_get_advertized_nrows (GdaDataSelect *model) {
+ return model->priv->advertized_nrows;
+}
+void
+_gda_data_select_set_advertized_nrows (GdaDataSelect *model, gint n) {
+ model->priv->advertized_nrows = n;
+}
diff --git a/libgda/gda-data-select.h b/libgda/gda-data-select.h
index 88d7104ad..b69b53922 100644
--- a/libgda/gda-data-select.h
+++ b/libgda/gda-data-select.h
@@ -67,11 +67,6 @@ struct _GdaDataSelect {
GObject object;
GdaDataSelectPrivate *priv;
- /* read only information */
- GdaPStmt *prep_stmt; /* use the "prepared-stmt" property to set this */
- gint nb_stored_rows; /* number of GdaRow objects currently stored */
- gint advertized_nrows; /* set when the number of rows becomes known, -1 until then */
-
/*< private >*/
/* Padding for future expansion */
gpointer _gda_reserved1;
diff --git a/libgda/sqlite/gda-sqlite-recordset.c b/libgda/sqlite/gda-sqlite-recordset.c
index a9deb6bb5..00d447ea6 100644
--- a/libgda/sqlite/gda-sqlite-recordset.c
+++ b/libgda/sqlite/gda-sqlite-recordset.c
@@ -36,6 +36,7 @@
#include "gda-sqlite-recordset.h"
#include "gda-sqlite-provider.h"
#include "gda-sqlite-blob-op.h"
+#include "gda-data-select-extra.h"
#include <libgda/gda-util.h>
#include <libgda/gda-connection-private.h>
@@ -112,7 +113,7 @@ gda_sqlite_recordset_dispose (GObject *object)
if (recset->priv) {
GdaSqlitePStmt *ps;
- ps = GDA_SQLITE_PSTMT (GDA_DATA_SELECT (object)->prep_stmt);
+ ps = GDA_SQLITE_PSTMT (_gda_data_select_get_prep_stmt (GDA_DATA_SELECT (object)));
if (ps != NULL) {
ps->stmt_used = FALSE;
virt_cnc_set_working_obj (gda_data_select_get_connection ((GdaDataSelect*) recset),
recset);
@@ -183,9 +184,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_data_select_get_prep_stmt(pmodel)->ncols);
+ for (nb_missing = 0, i = 0; i < _gda_data_select_get_prep_stmt(pmodel)->ncols; i++) {
+ if ( _gda_data_select_get_prep_stmt(pmodel)->types[i] == GDA_TYPE_NULL)
missing_cols [nb_missing++] = i;
}
@@ -203,10 +204,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_data_select_get_prep_stmt(pmodel)->types [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_data_select_get_prep_stmt(pmodel)->types
[missing_cols [i]]),
missing_cols [i]);
#endif
memmove (missing_cols + i, missing_cols + i + 1, sizeof (gint) * (nb_missing
- i - 1));
@@ -377,7 +378,7 @@ fetch_next_sqlite_row (GdaSqliteRecordset *model, gboolean do_store, GError **er
cdata = (SqliteConnectionData*) gda_connection_internal_get_provider_data_error (cnc, error);
if (!cdata)
return NULL;
- ps = GDA_SQLITE_PSTMT (GDA_DATA_SELECT (model)->prep_stmt);
+ ps = GDA_SQLITE_PSTMT ( _gda_data_select_get_prep_stmt(GDA_DATA_SELECT (model)));
virt_cnc_set_working_obj (gda_data_select_get_connection ((GdaDataSelect*) model), model);
@@ -673,7 +674,7 @@ fetch_next_sqlite_row (GdaSqliteRecordset *model, gboolean do_store, GError **er
/* nothing to do */
break;
case SQLITE_DONE:
- GDA_DATA_SELECT (model)->advertized_nrows = model->priv->next_row_num;
+ _gda_data_select_set_advertized_nrows (GDA_DATA_SELECT (model), model->priv->next_row_num);
SQLITE3_CALL (sqlite3_reset) (ps->sqlite_stmt);
break;
case SQLITE_READONLY:
@@ -696,7 +697,7 @@ fetch_next_sqlite_row (GdaSqliteRecordset *model, gboolean do_store, GError **er
gda_data_select_add_exception (GDA_DATA_SELECT (model), lerror);
if (rc == SQLITE_ERROR)
g_propagate_error (error, g_error_copy (lerror));
- GDA_DATA_SELECT (model)->advertized_nrows = model->priv->next_row_num;
+ _gda_data_select_set_advertized_nrows (GDA_DATA_SELECT (model), model->priv->next_row_num);
break;
}
}
@@ -717,13 +718,13 @@ gda_sqlite_recordset_fetch_nb_rows (GdaDataSelect *model)
GdaRow *prow = NULL;
imodel = GDA_SQLITE_RECORDSET (model);
- if (model->advertized_nrows >= 0)
- return model->advertized_nrows;
+ if (_gda_data_select_get_advertized_nrows (model) >= 0)
+ return _gda_data_select_get_advertized_nrows (model);
for (prow = fetch_next_sqlite_row (imodel, TRUE, NULL);
prow;
prow = fetch_next_sqlite_row (imodel, TRUE, NULL));
- return model->advertized_nrows;
+ return _gda_data_select_get_advertized_nrows (model);
}
/*
diff --git a/providers/mysql/gda-mysql-recordset.c b/providers/mysql/gda-mysql-recordset.c
index bc51abebd..5fb6f1269 100644
--- a/providers/mysql/gda-mysql-recordset.c
+++ b/providers/mysql/gda-mysql-recordset.c
@@ -40,6 +40,7 @@
#include "gda-mysql-recordset.h"
#include "gda-mysql-provider.h"
#include "gda-mysql-util.h"
+#include "gda-data-select-extra.h"
#include <libgda/libgda-global-variables.h>
#ifdef HAVE_LOCALE_H
#include <locale.h>
@@ -259,7 +260,7 @@ gda_mysql_recordset_dispose (GObject *object)
g_return_if_fail (GDA_IS_MYSQL_RECORDSET (recset));
if (recset->priv) {
- GDA_MYSQL_PSTMT (GDA_DATA_SELECT (object)->prep_stmt)->stmt_used = FALSE;
+ GDA_MYSQL_PSTMT (_gda_data_select_get_prep_stmt (GDA_DATA_SELECT (object)))->stmt_used =
FALSE;
if (recset->priv->cnc) {
g_object_unref (G_OBJECT(recset->priv->cnc));
@@ -456,7 +457,7 @@ gda_mysql_recordset_new_direct (GdaConnection *cnc, GdaDataModelAccessFlags flag
MYSQL_FIELD *mysql_fields = mysql_fetch_fields (mysql_res);
GSList *list;
- ((GdaDataSelect *) model)->advertized_nrows = mysql_affected_rows (cdata->mysql);
+ _gda_data_select_set_advertized_nrows ((GdaDataSelect *) model, mysql_affected_rows (cdata->mysql));
for (i=0, list = columns;
i < model->priv->ncols;
i++, list = list->next) {
@@ -704,7 +705,7 @@ gda_mysql_recordset_new (GdaConnection *cnc,
model->priv->mysql_stmt = ps->mysql_stmt;
- ((GdaDataSelect *) model)->advertized_nrows = mysql_stmt_affected_rows (ps->mysql_stmt);
+ _gda_data_select_set_advertized_nrows ((GdaDataSelect *) model, mysql_stmt_affected_rows
(ps->mysql_stmt));
return GDA_DATA_MODEL (model);
}
@@ -719,12 +720,12 @@ gda_mysql_recordset_fetch_nb_rows (GdaDataSelect *model)
GdaMysqlRecordset *imodel;
imodel = GDA_MYSQL_RECORDSET (model);
- if (model->advertized_nrows >= 0)
- return model->advertized_nrows;
+ if (_gda_data_select_get_advertized_nrows (model) >= 0)
+ return _gda_data_select_get_advertized_nrows (model);
- model->advertized_nrows = mysql_stmt_affected_rows (imodel->priv->mysql_stmt);
+ _gda_data_select_set_advertized_nrows (model, mysql_stmt_affected_rows (imodel->priv->mysql_stmt));
- return model->advertized_nrows;
+ return _gda_data_select_get_advertized_nrows (model);
}
static GdaRow *
@@ -735,7 +736,7 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, G_GNUC_UNUSED gint rownum, G
MYSQL_BIND *mysql_bind_result;
g_return_val_if_fail (imodel->priv->mysql_stmt != NULL, NULL);
- mysql_bind_result = ((GdaMysqlPStmt *) ((GdaDataSelect *) imodel)->prep_stmt)->mysql_bind_result;
+ mysql_bind_result = ((GdaMysqlPStmt *) _gda_data_select_get_prep_stmt ((GdaDataSelect *)
imodel))->mysql_bind_result;
g_assert (mysql_bind_result);
res = mysql_stmt_fetch (imodel->priv->mysql_stmt);
@@ -752,7 +753,7 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, G_GNUC_UNUSED gint rownum, G
"http://gitlab.gnome.org/GNOME/libgda/issues");
gint col;
- for (col = 0; col < ((GdaDataSelect *) imodel)->prep_stmt->ncols; ++col) {
+ for (col = 0; col < _gda_data_select_get_prep_stmt ((GdaDataSelect *) imodel)->ncols; ++col) {
my_bool truncated;
mysql_bind_result[col].error = &truncated;
mysql_stmt_fetch_column (imodel->priv->mysql_stmt, &(mysql_bind_result[col]),
@@ -774,13 +775,13 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, G_GNUC_UNUSED gint rownum, G
/* g_print ("%s: SQL=%s\n", __func__, ((GdaDataSelect *) imodel)->prep_stmt->sql); */
- GdaRow *row = gda_row_new (((GdaDataSelect *) imodel)->prep_stmt->ncols);
+ GdaRow *row = gda_row_new (_gda_data_select_get_prep_stmt ((GdaDataSelect *) imodel)->ncols);
gint col;
- for (col = 0; col < ((GdaDataSelect *) imodel)->prep_stmt->ncols; ++col) {
+ for (col = 0; col < _gda_data_select_get_prep_stmt ((GdaDataSelect *) imodel)->ncols; ++col) {
gint i = col;
GValue *value = gda_row_get_value (row, i);
- GType type = ((GdaDataSelect *) imodel)->prep_stmt->types[i];
+ GType type = _gda_data_select_get_prep_stmt ((GdaDataSelect *) imodel)->types[i];
/*g_print ("%s: #%d : TYPE=%d, GTYPE=%s\n", __func__, i, mysql_bind_result[i].buffer_type,
g_type_name (type));*/
@@ -1061,7 +1062,7 @@ gda_mysql_recordset_fetch_random (GdaDataSelect *model,
gda_data_select_take_row (model, *row, rownum);
- if (model->nb_stored_rows == model->advertized_nrows) {
+ if (_gda_data_select_get_nb_stored_rows (model) == _gda_data_select_get_advertized_nrows (model)) {
/* All the row have been converted. We could free result now */
/* but it was done before provided no field-based API functions */
/* that process result set meta data was needed in the middle. */
diff --git a/providers/postgres/gda-postgres-recordset.c b/providers/postgres/gda-postgres-recordset.c
index 0502df727..6d6c63116 100644
--- a/providers/postgres/gda-postgres-recordset.c
+++ b/providers/postgres/gda-postgres-recordset.c
@@ -41,6 +41,7 @@
#include "gda-postgres-provider.h"
#include "gda-postgres-blob-op.h"
#include "gda-postgres-util.h"
+#include "gda-data-select-extra.h"
#include <libgda/libgda-global-variables.h>
#ifdef HAVE_LOCALE_H
#include <locale.h>
@@ -347,9 +348,9 @@ gda_postgres_recordset_new_random (GdaConnection *cnc, GdaPostgresPStmt *ps, Gda
"model-usage", GDA_DATA_MODEL_ACCESS_RANDOM,
"exec-params", exec_params, NULL);
model->priv->pg_res = pg_res;
- ((GdaDataSelect*) model)->advertized_nrows = PQntuples (model->priv->pg_res);
+ _gda_data_select_set_advertized_nrows ((GdaDataSelect*) model, PQntuples (model->priv->pg_res));
- return GDA_DATA_MODEL (model);
+ return GDA_DATA_MODEL (model);
}
/*
@@ -421,14 +422,14 @@ gda_postgres_recordset_fetch_nb_rows (GdaDataSelect *model)
GdaPostgresRecordset *imodel;
imodel = GDA_POSTGRES_RECORDSET (model);
- if (model->advertized_nrows >= 0)
- return model->advertized_nrows;
+ 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 (!imodel->priv->cursor_name)
- model->advertized_nrows = PQntuples (imodel->priv->pg_res);
+ _gda_data_select_set_advertized_nrows (model, PQntuples (imodel->priv->pg_res));
- return model->advertized_nrows;
+ return _gda_data_select_get_advertized_nrows (model);
}
/*
@@ -450,7 +451,7 @@ gda_postgres_recordset_fetch_random (GdaDataSelect *model, GdaRow **prow, gint r
*prow = new_row_from_pg_res (imodel, rownum, error);
gda_data_select_take_row (model, *prow, rownum);
- if (model->nb_stored_rows == model->advertized_nrows) {
+ 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 (imodel->priv->pg_res);
@@ -475,7 +476,7 @@ gda_postgres_recordset_store_all (GdaDataSelect *model, GError **error)
return FALSE;
}
- for (i = 0; i < model->advertized_nrows; i++) {
+ for (i = 0; i < _gda_data_select_get_advertized_nrows (model); i++) {
GdaRow *prow;
if (! gda_postgres_recordset_fetch_random (model, &prow, i, error))
return FALSE;
@@ -802,14 +803,14 @@ set_prow_with_pg_res (GdaPostgresRecordset *imodel, GdaRow *prow, gint pg_res_ro
gchar *thevalue;
gint col;
- for (col = 0; col < ((GdaDataSelect*) imodel)->prep_stmt->ncols; col++) {
+ for (col = 0; col < _gda_data_select_get_prep_stmt ((GdaDataSelect*) imodel)->ncols; 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),
- ((GdaDataSelect*) imodel)->prep_stmt->types [col],
+ _gda_data_select_get_prep_stmt ((GdaDataSelect*) imodel)->types [col],
thevalue,
PQgetlength (imodel->priv->pg_res, pg_res_rownum, col), error);
}
@@ -820,7 +821,7 @@ new_row_from_pg_res (GdaPostgresRecordset *imodel, gint pg_res_rownum, GError **
{
GdaRow *prow;
- prow = gda_row_new (((GdaDataSelect*) imodel)->prep_stmt->ncols);
+ prow = gda_row_new (_gda_data_select_get_prep_stmt ((GdaDataSelect*) imodel)->ncols);
set_prow_with_pg_res (imodel, prow, pg_res_rownum, error);
return prow;
}
@@ -878,9 +879,9 @@ fetch_next_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e
/* 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 (model)->advertized_nrows = nbtuples;
+ _gda_data_select_set_advertized_nrows (GDA_DATA_SELECT (model),
nbtuples);
else
- GDA_DATA_SELECT (model)->advertized_nrows = model->priv->pg_pos +
nbtuples + 1;
+ _gda_data_select_set_advertized_nrows (GDA_DATA_SELECT
(model),model->priv->pg_pos + nbtuples + 1);
model->priv->pg_pos = G_MAXINT;
}
@@ -893,9 +894,9 @@ fetch_next_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e
}
else {
if (model->priv->pg_pos == G_MININT)
- GDA_DATA_SELECT (model)->advertized_nrows = 0;
+ _gda_data_select_set_advertized_nrows (GDA_DATA_SELECT (model), 0);
else
- GDA_DATA_SELECT (model)->advertized_nrows = model->priv->pg_pos + 1; /* total
number of rows */
+ _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;
}
@@ -921,7 +922,7 @@ fetch_prev_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e
if (model->priv->pg_pos == G_MININT)
return FALSE;
else if (model->priv->pg_pos == G_MAXINT)
- g_assert (GDA_DATA_SELECT (model)->advertized_nrows >= 0); /* total number of rows MUST be
known at this point */
+ 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;
gboolean retval = TRUE;
@@ -963,7 +964,7 @@ fetch_prev_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e
if (nbtuples > 0) {
/* model->priv->pg_res_inf */
if (model->priv->pg_pos == G_MAXINT)
- model->priv->pg_res_inf = GDA_DATA_SELECT (model)->advertized_nrows -
nbtuples;
+ model->priv->pg_res_inf = _gda_data_select_get_advertized_nrows
(GDA_DATA_SELECT (model)) - nbtuples;
else
model->priv->pg_res_inf =
MAX (model->priv->pg_res_inf - (noffset - model->priv->chunk_size),
0);
@@ -974,7 +975,7 @@ fetch_prev_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e
}
else {
if (model->priv->pg_pos == G_MAXINT)
- model->priv->pg_pos = GDA_DATA_SELECT (model)->advertized_nrows - 1;
+ model->priv->pg_pos = _gda_data_select_get_advertized_nrows
(GDA_DATA_SELECT (model)) - 1;
else
model->priv->pg_pos = MAX (model->priv->pg_pos - noffset, -1) +
nbtuples;
}
diff --git a/providers/skel-implementation/capi/gda-capi-recordset.c
b/providers/skel-implementation/capi/gda-capi-recordset.c
index bdc724aa0..d811f8068 100644
--- a/providers/skel-implementation/capi/gda-capi-recordset.c
+++ b/providers/skel-implementation/capi/gda-capi-recordset.c
@@ -29,6 +29,7 @@
#include "gda-capi.h"
#include "gda-capi-recordset.h"
#include "gda-capi-provider.h"
+#include "gda-data-select-extra.h"
#include <libgda/gda-debug-macros.h>
#define _GDA_PSTMT(x) ((GdaPStmt*)(x))
@@ -235,14 +236,14 @@ gda_capi_recordset_fetch_nb_rows (GdaDataSelect *model)
GdaCapiRecordset *imodel;
imodel = GDA_CAPI_RECORDSET (model);
- if (model->advertized_nrows >= 0)
- return model->advertized_nrows;
+ 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 */
g_warning("imodel not used: %p", imodel); /* Avoids a compiler warning. */
TO_IMPLEMENT;
- return model->advertized_nrows;
+ return _gda_data_select_get_advertized_nrows (model);
}
/*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]