...
 
Commits (2)
...@@ -60,6 +60,11 @@ GdaDataSelectInternals *_gda_data_select_internals_steal (GdaDataSelect *model); ...@@ -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_paste (GdaDataSelect *model, GdaDataSelectInternals *inter);
void _gda_data_select_internals_free (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 G_END_DECLS
#endif #endif
...@@ -73,7 +73,7 @@ typedef struct { ...@@ -73,7 +73,7 @@ typedef struct {
GHashTable *index; /* key = model row number, value = index in @rows array*/ GHashTable *index; /* key = model row number, value = index in @rows array*/
/* Internal iterator's information, if GDA_DATA_MODEL_CURSOR_* based access */ /* Internal iterator's information, if GDA_DATA_MODEL_CURSOR_* based access */
gint iter_row; /* G_MININT if at start, G_MAXINT if at end, "external" row number */ gint iter_row; /* G_MININT if at start, G_MAXINT if at end, "external" row number */
GdaStatement *sel_stmt; GdaStatement *sel_stmt;
GdaSet *ext_params; GdaSet *ext_params;
...@@ -108,6 +108,9 @@ struct _GdaDataSelectPrivate { ...@@ -108,6 +108,9 @@ struct _GdaDataSelectPrivate {
PrivateShareable *sh; PrivateShareable *sh;
gulong ext_params_changed_sig_id; gulong ext_params_changed_sig_id;
gdouble exec_time; 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 */ /* properties */
...@@ -433,10 +436,10 @@ gda_data_select_init (GdaDataSelect *model, G_GNUC_UNUSED GdaDataSelectClass *kl ...@@ -433,10 +436,10 @@ gda_data_select_init (GdaDataSelect *model, G_GNUC_UNUSED GdaDataSelectClass *kl
model->priv->sh-> notify_changes = TRUE; model->priv->sh-> notify_changes = TRUE;
model->priv->sh->rows = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); 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->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->priv->sh->columns = NULL;
model->nb_stored_rows = 0; model->priv->nb_stored_rows = 0;
model->advertized_nrows = -1; /* unknown number of rows */ model->priv->advertized_nrows = -1; /* unknown number of rows */
model->priv->sh->sel_stmt = NULL; model->priv->sh->sel_stmt = NULL;
model->priv->sh->ext_params = NULL; model->priv->sh->ext_params = NULL;
...@@ -565,9 +568,9 @@ gda_data_select_dispose (GObject *object) ...@@ -565,9 +568,9 @@ gda_data_select_dispose (GObject *object)
g_object_unref (model->priv->iter); g_object_unref (model->priv->iter);
model->priv->iter = NULL; model->priv->iter = NULL;
} }
if (model->prep_stmt) { if (model->priv->prep_stmt) {
g_object_unref (model->prep_stmt); g_object_unref (model->priv->prep_stmt);
model->prep_stmt = NULL; model->priv->prep_stmt = NULL;
} }
if (model->priv->ext_params_changed_sig_id) { if (model->priv->ext_params_changed_sig_id) {
g_signal_handler_disconnect (model->priv->sh->ext_params, g_signal_handler_disconnect (model->priv->sh->ext_params,
...@@ -727,24 +730,24 @@ create_columns (GdaDataSelect *model) ...@@ -727,24 +730,24 @@ create_columns (GdaDataSelect *model)
g_free (model->priv->sh->modif_internals->cols_mod[m]); g_free (model->priv->sh->modif_internals->cols_mod[m]);
model->priv->sh->modif_internals->cols_mod[m] = NULL; model->priv->sh->modif_internals->cols_mod[m] = NULL;
} }
if (!model->prep_stmt) if (!model->priv->prep_stmt)
return; 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")); 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 */ /* copy template columns */
GSList *list; 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)); model->priv->sh->columns = g_slist_append (model->priv->sh->columns, g_object_ref (list->data));
} }
else { else {
/* create columns */ /* create columns */
for (i = 0; i < model->prep_stmt->ncols; i++) { for (i = 0; i < model->priv->prep_stmt->ncols; i++) {
GdaColumn *gda_col; GdaColumn *gda_col;
gda_col = gda_column_new (); gda_col = gda_column_new ();
if (model->prep_stmt->types) if (model->priv->prep_stmt->types)
gda_column_set_g_type (gda_col, model->prep_stmt->types [i]); 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); model->priv->sh->columns = g_slist_append (model->priv->sh->columns, gda_col);
} }
} }
...@@ -769,13 +772,13 @@ gda_data_select_set_property (GObject *object, ...@@ -769,13 +772,13 @@ gda_data_select_set_property (GObject *object,
} }
break; break;
case PROP_PREP_STMT: case PROP_PREP_STMT:
if (model->prep_stmt) if (model->priv->prep_stmt)
g_object_unref (model->prep_stmt); g_object_unref (model->priv->prep_stmt);
model->prep_stmt = g_value_get_object (value); model->priv->prep_stmt = g_value_get_object (value);
if (model->prep_stmt) { if (model->priv->prep_stmt) {
GdaStatement *sel_stmt; GdaStatement *sel_stmt;
g_object_ref (model->prep_stmt); g_object_ref (model->priv->prep_stmt);
sel_stmt = gda_pstmt_get_gda_statement (model->prep_stmt); sel_stmt = gda_pstmt_get_gda_statement (model->priv->prep_stmt);
if (sel_stmt && if (sel_stmt &&
gda_statement_get_statement_type (sel_stmt) == GDA_SQL_STATEMENT_SELECT) { gda_statement_get_statement_type (sel_stmt) == GDA_SQL_STATEMENT_SELECT) {
model->priv->sh->sel_stmt = gda_statement_copy (sel_stmt); model->priv->sh->sel_stmt = gda_statement_copy (sel_stmt);
...@@ -861,7 +864,7 @@ gda_data_select_get_property (GObject *object, ...@@ -861,7 +864,7 @@ gda_data_select_get_property (GObject *object,
g_value_set_object (value, model->priv->cnc); g_value_set_object (value, model->priv->cnc);
break; break;
case PROP_PREP_STMT: case PROP_PREP_STMT:
g_value_set_object (value, model->prep_stmt); g_value_set_object (value, model->priv->prep_stmt);
break; break;
case PROP_FLAGS: case PROP_FLAGS:
g_value_set_uint (value, model->priv->sh->usage_flags); g_value_set_uint (value, model->priv->sh->usage_flags);
...@@ -870,9 +873,9 @@ gda_data_select_get_property (GObject *object, ...@@ -870,9 +873,9 @@ gda_data_select_get_property (GObject *object,
if (!model->priv->sh->usage_flags & GDA_DATA_MODEL_ACCESS_RANDOM) 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"); g_warning ("Cannot set the 'store-all-rows' property when access mode is cursor based");
else { 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); _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; break;
case PROP_PARAMS: case PROP_PARAMS:
...@@ -938,7 +941,7 @@ gda_data_select_take_row (GdaDataSelect *model, GdaRow *row, gint rownum) ...@@ -938,7 +941,7 @@ gda_data_select_take_row (GdaDataSelect *model, GdaRow *row, gint rownum)
ptr [1] = model->priv->sh->rows->len; ptr [1] = model->priv->sh->rows->len;
g_hash_table_insert (model->priv->sh->index, ptr, ptr+1); g_hash_table_insert (model->priv->sh->index, ptr, ptr+1);
g_ptr_array_add (model->priv->sh->rows, row); 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) ...@@ -1168,13 +1171,13 @@ check_acceptable_statement (GdaDataSelect *model, GError **error)
if (model->priv->sh->sel_stmt) if (model->priv->sh->sel_stmt)
return 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, 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")); "%s", _("Internal error: the \"prepared-stmt\" property has not been set"));
return NULL; 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) { if (! sel_stmt) {
g_set_error (error, GDA_DATA_SELECT_ERROR, GDA_DATA_SELECT_MODIFICATION_STATEMENT_ERROR, g_set_error (error, GDA_DATA_SELECT_ERROR, GDA_DATA_SELECT_MODIFICATION_STATEMENT_ERROR,
"%s", _("Can't get the prepared statement's actual statement")); "%s", _("Can't get the prepared statement's actual statement"));
...@@ -1453,9 +1456,9 @@ gda_data_select_set_modification_statement (GdaDataSelect *model, GdaStatement * ...@@ -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)); gda_column_set_g_type (gdacol, gda_holder_get_g_type (holder));
coltypeschanged = TRUE; coltypeschanged = TRUE;
} }
if (model->prep_stmt && model->prep_stmt->types && if (model->priv->prep_stmt && model->priv->prep_stmt->types &&
(model->prep_stmt->types [num] == GDA_TYPE_NULL)) (model->priv->prep_stmt->types [num] == GDA_TYPE_NULL))
model->prep_stmt->types [num] = gda_holder_get_g_type (holder); model->priv->prep_stmt->types [num] = gda_holder_get_g_type (holder);
} }
} }
...@@ -1850,8 +1853,8 @@ gda_data_select_get_n_rows (GdaDataModel *model) ...@@ -1850,8 +1853,8 @@ gda_data_select_get_n_rows (GdaDataModel *model)
imodel = GDA_DATA_SELECT (model); imodel = GDA_DATA_SELECT (model);
g_return_val_if_fail (imodel->priv, 0); g_return_val_if_fail (imodel->priv, 0);
retval = imodel->advertized_nrows; retval = imodel->priv->advertized_nrows;
if ((imodel->advertized_nrows < 0) && if ((imodel->priv->advertized_nrows < 0) &&
(imodel->priv->sh->usage_flags & GDA_DATA_MODEL_ACCESS_RANDOM) && (imodel->priv->sh->usage_flags & GDA_DATA_MODEL_ACCESS_RANDOM) &&
CLASS (model)->fetch_nb_rows) CLASS (model)->fetch_nb_rows)
retval = _gda_data_select_fetch_nb_rows (imodel); retval = _gda_data_select_fetch_nb_rows (imodel);
...@@ -1869,10 +1872,10 @@ gda_data_select_get_n_columns (GdaDataModel *model) ...@@ -1869,10 +1872,10 @@ gda_data_select_get_n_columns (GdaDataModel *model)
imodel = GDA_DATA_SELECT (model); imodel = GDA_DATA_SELECT (model);
g_return_val_if_fail (imodel->priv, 0); g_return_val_if_fail (imodel->priv, 0);
if (imodel->prep_stmt) if (imodel->priv->prep_stmt)
return imodel->prep_stmt->ncols; return imodel->priv->prep_stmt->ncols;
else
return g_slist_length (imodel->priv->sh->columns); return g_slist_length (imodel->priv->sh->columns);
} }
static GdaColumn * static GdaColumn *
...@@ -1940,8 +1943,8 @@ external_to_internal_row (GdaDataSelect *model, gint ext_row, GError **error) ...@@ -1940,8 +1943,8 @@ external_to_internal_row (GdaDataSelect *model, gint ext_row, GError **error)
} }
/* check row number validity */ /* check row number validity */
nrows = model->advertized_nrows < 0 ? gda_data_select_get_n_rows ((GdaDataModel*) model) : nrows = model->priv->advertized_nrows < 0 ? gda_data_select_get_n_rows ((GdaDataModel*) model) :
model->advertized_nrows; model->priv->advertized_nrows;
if ((ext_row < 0) || ((nrows >= 0) && (int_row >= nrows))) { if ((ext_row < 0) || ((nrows >= 0) && (int_row >= nrows))) {
gint n; gint n;
n = gda_data_select_get_n_rows ((GdaDataModel*) model); 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 ** ...@@ -2038,11 +2041,11 @@ gda_data_select_get_value_at (GdaDataModel *model, gint col, gint row, GError **
return NULL; return NULL;
} }
GType *types = NULL; GType *types = NULL;
if (imodel->prep_stmt && imodel->prep_stmt->types) { if (imodel->priv->prep_stmt && imodel->priv->prep_stmt->types) {
types = g_new (GType, imodel->prep_stmt->ncols + 1); types = g_new (GType, imodel->priv->prep_stmt->ncols + 1);
memcpy (types, imodel->prep_stmt->types, /* Flawfinder: ignore */ memcpy (types, imodel->priv->prep_stmt->types, /* Flawfinder: ignore */
sizeof (GType) * imodel->prep_stmt->ncols); sizeof (GType) * imodel->priv->prep_stmt->ncols);
types [imodel->prep_stmt->ncols] = G_TYPE_NONE; types [imodel->priv->prep_stmt->ncols] = G_TYPE_NONE;
} }
/*g_print ("*** Executing DelayedSelectStmt %p\n", dstmt);*/ /*g_print ("*** Executing DelayedSelectStmt %p\n", dstmt);*/
tmpmodel = gda_connection_statement_execute_select_full (imodel->priv->cnc, tmpmodel = gda_connection_statement_execute_select_full (imodel->priv->cnc,
...@@ -2206,7 +2209,6 @@ gda_data_select_create_iter (GdaDataModel *model) ...@@ -2206,7 +2209,6 @@ gda_data_select_create_iter (GdaDataModel *model)
"data-model", model, NULL)); "data-model", model, NULL));
imodel->priv->sh->iter_row = -1; imodel->priv->sh->iter_row = -1;
} }
g_object_ref (imodel->priv->iter);
return imodel->priv->iter; return imodel->priv->iter;
} }
} }
...@@ -2228,7 +2230,6 @@ gda_data_select_iter_next (GdaDataModel *model, GdaDataModelIter *iter) ...@@ -2228,7 +2230,6 @@ gda_data_select_iter_next (GdaDataModel *model, GdaDataModelIter *iter)
g_return_val_if_fail (CLASS (model)->fetch_next, FALSE); g_return_val_if_fail (CLASS (model)->fetch_next, FALSE);
g_return_val_if_fail (iter, FALSE); g_return_val_if_fail (iter, FALSE);
g_return_val_if_fail (imodel->priv->iter == iter, FALSE);
if (imodel->priv->sh->iter_row == G_MAXINT) { if (imodel->priv->sh->iter_row == G_MAXINT) {
gda_data_model_iter_invalidate_contents (iter); gda_data_model_iter_invalidate_contents (iter);
...@@ -2272,14 +2273,13 @@ gda_data_select_iter_prev (GdaDataModel *model, GdaDataModelIter *iter) ...@@ -2272,14 +2273,13 @@ gda_data_select_iter_prev (GdaDataModel *model, GdaDataModelIter *iter)
if (imodel->priv->sh->usage_flags & GDA_DATA_MODEL_ACCESS_RANDOM) if (imodel->priv->sh->usage_flags & GDA_DATA_MODEL_ACCESS_RANDOM)
return gda_data_model_iter_move_prev_default (model, iter); return gda_data_model_iter_move_prev_default (model, iter);
g_return_val_if_fail (iter, FALSE); g_return_val_if_fail (iter, FALSE);
g_return_val_if_fail (imodel->priv->iter == iter, FALSE);
if (imodel->priv->sh->iter_row <= 0) if (imodel->priv->sh->iter_row <= 0)
goto prev_error; goto prev_error;
else if (imodel->priv->sh->iter_row == G_MAXINT) { else if (imodel->priv->sh->iter_row == G_MAXINT) {
g_assert (imodel->advertized_nrows >= 0); g_assert (imodel->priv->advertized_nrows >= 0);
target_iter_row = imodel->advertized_nrows - 1; target_iter_row = imodel->priv->advertized_nrows - 1;
} }
else else
target_iter_row = imodel->priv->sh->iter_row - 1; target_iter_row = imodel->priv->sh->iter_row - 1;
...@@ -2320,8 +2320,7 @@ gda_data_select_iter_at_row (GdaDataModel *model, GdaDataModelIter *iter, gint r ...@@ -2320,8 +2320,7 @@ gda_data_select_iter_at_row (GdaDataModel *model, GdaDataModelIter *iter, gint r
if (imodel->priv->sh->usage_flags & GDA_DATA_MODEL_ACCESS_RANDOM) if (imodel->priv->sh->usage_flags & GDA_DATA_MODEL_ACCESS_RANDOM)
return gda_data_model_iter_move_to_row_default (model, iter, row); return gda_data_model_iter_move_to_row_default (model, iter, row);
g_return_val_if_fail (iter, FALSE); g_return_val_if_fail (iter, FALSE);
g_return_val_if_fail (imodel->priv->iter == iter, FALSE);
int_row = external_to_internal_row (imodel, row, NULL); int_row = external_to_internal_row (imodel, row, NULL);
if (imodel->priv->sh->current_prow && (imodel->priv->sh->current_prow_row == row)) if (imodel->priv->sh->current_prow && (imodel->priv->sh->current_prow_row == row))
...@@ -3130,12 +3129,12 @@ gda_data_select_append_values (GdaDataModel *model, const GList *values, GError ...@@ -3130,12 +3129,12 @@ gda_data_select_append_values (GdaDataModel *model, const GList *values, GError
} }
/* compute added row's number */ /* compute added row's number */
row = imodel->advertized_nrows; row = imodel->priv->advertized_nrows;
if (imodel->priv->sh->del_rows) if (imodel->priv->sh->del_rows)
row -= imodel->priv->sh->del_rows->len; row -= imodel->priv->sh->del_rows->len;
imodel->advertized_nrows++; imodel->priv->advertized_nrows++;
int_row = external_to_internal_row (imodel, row, error); int_row = external_to_internal_row (imodel, row, error);
imodel->advertized_nrows--; imodel->priv->advertized_nrows--;
/* BVector */ /* BVector */
BVector *bv; BVector *bv;
...@@ -3285,7 +3284,7 @@ gda_data_select_append_values (GdaDataModel *model, const GList *values, GError ...@@ -3285,7 +3284,7 @@ gda_data_select_append_values (GdaDataModel *model, const GList *values, GError
#ifdef GDA_DEBUG_NO #ifdef GDA_DEBUG_NO
dump_d (imodel); dump_d (imodel);
#endif #endif
imodel->advertized_nrows++; imodel->priv->advertized_nrows++;
gda_data_model_row_inserted ((GdaDataModel *) imodel, row); gda_data_model_row_inserted ((GdaDataModel *) imodel, row);
return row; return row;
...@@ -3696,13 +3695,13 @@ gda_data_select_rerun (GdaDataSelect *model, GError **error) ...@@ -3696,13 +3695,13 @@ gda_data_select_rerun (GdaDataSelect *model, GError **error)
select = check_acceptable_statement (model, error); select = check_acceptable_statement (model, error);
if (!select) if (!select)
return FALSE; return FALSE;
g_assert (model->prep_stmt); g_assert (model->priv->prep_stmt);
GType *types = NULL; GType *types = NULL;
if (model->prep_stmt->types) { if (model->priv->prep_stmt->types) {
types = g_new (GType, model->prep_stmt->ncols + 1); types = g_new (GType, model->priv->prep_stmt->ncols + 1);
memcpy (types, model->prep_stmt->types, /* Flawfinder: ignore */ memcpy (types, model->priv->prep_stmt->types, /* Flawfinder: ignore */
sizeof (GType) * model->prep_stmt->ncols); sizeof (GType) * model->priv->prep_stmt->ncols);
types [model->prep_stmt->ncols] = G_TYPE_NONE; types [model->priv->prep_stmt->ncols] = G_TYPE_NONE;
} }
new_model = (GdaDataSelect*) gda_connection_statement_execute_select_full (model->priv->cnc, select, new_model = (GdaDataSelect*) gda_connection_statement_execute_select_full (model->priv->cnc, select,
model->priv->sh->ext_params, model->priv->sh->ext_params,
...@@ -3861,17 +3860,17 @@ gda_data_select_prepare_for_offline (GdaDataSelect *model, GError **error) ...@@ -3861,17 +3860,17 @@ gda_data_select_prepare_for_offline (GdaDataSelect *model, GError **error)
} }
/* fetching data */ /* fetching data */
if (model->advertized_nrows < 0) { if (model->priv->advertized_nrows < 0) {
if (CLASS (model)->fetch_nb_rows) if (CLASS (model)->fetch_nb_rows)
_gda_data_select_fetch_nb_rows (model); _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, g_set_error (error, GDA_DATA_SELECT_ERROR, GDA_DATA_SELECT_ACCESS_ERROR,
"%s", _("Can't get the number of rows of data model")); "%s", _("Can't get the number of rows of data model"));
return FALSE; 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 (CLASS (model)->store_all) {
if (! _gda_data_select_store_all (model, error)) if (! _gda_data_select_store_all (model, error))
return FALSE; return FALSE;
...@@ -3879,7 +3878,7 @@ gda_data_select_prepare_for_offline (GdaDataSelect *model, GError **error) ...@@ -3879,7 +3878,7 @@ gda_data_select_prepare_for_offline (GdaDataSelect *model, GError **error)
} }
/* final check/complement */ /* 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)) { if (!g_hash_table_lookup (model->priv->sh->index, &i)) {
GdaRow *prow; GdaRow *prow;
if (! _gda_data_select_fetch_at (model, &prow, i, error)) if (! _gda_data_select_fetch_at (model, &prow, i, error))
...@@ -4094,4 +4093,22 @@ _gda_data_select_fetch_at (GdaDataSelect *model, GdaRow **prow, gint rownum ...@@ -4094,4 +4093,22 @@ _gda_data_select_fetch_at (GdaDataSelect *model, GdaRow **prow, gint rownum
return result ? TRUE : FALSE; 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;
}
...@@ -67,11 +67,6 @@ struct _GdaDataSelect { ...@@ -67,11 +67,6 @@ struct _GdaDataSelect {
GObject object; GObject object;
GdaDataSelectPrivate *priv; 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 >*/ /*< private >*/
/* Padding for future expansion */ /* Padding for future expansion */
gpointer _gda_reserved1; gpointer _gda_reserved1;
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "gda-sqlite-recordset.h" #include "gda-sqlite-recordset.h"
#include "gda-sqlite-provider.h" #include "gda-sqlite-provider.h"
#include "gda-sqlite-blob-op.h" #include "gda-sqlite-blob-op.h"
#include "gda-data-select-extra.h"
#include <libgda/gda-util.h> #include <libgda/gda-util.h>
#include <libgda/gda-connection-private.h> #include <libgda/gda-connection-private.h>
...@@ -112,7 +113,7 @@ gda_sqlite_recordset_dispose (GObject *object) ...@@ -112,7 +113,7 @@ gda_sqlite_recordset_dispose (GObject *object)
if (recset->priv) { if (recset->priv) {
GdaSqlitePStmt *ps; 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) { if (ps != NULL) {
ps->stmt_used = FALSE; ps->stmt_used = FALSE;
virt_cnc_set_working_obj (gda_data_select_get_connection ((GdaDataSelect*) recset), recset); 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) ...@@ -183,9 +184,9 @@ read_rows_to_init_col_types (GdaSqliteRecordset *model)
gint *missing_cols, nb_missing; gint *missing_cols, nb_missing;
GdaDataSelect *pmodel = (GdaDataSelect*) model; GdaDataSelect *pmodel = (GdaDataSelect*) model;
missing_cols = g_new (gint, pmodel->prep_stmt->ncols); missing_cols = g_new (gint, _gda_data_select_get_prep_stmt(pmodel)->ncols);
for (nb_missing = 0, i = 0; i < pmodel->prep_stmt->ncols; i++) { for (nb_missing = 0, i = 0; i < _gda_data_select_get_prep_stmt(pmodel)->ncols; i++) {
if (pmodel->prep_stmt->types[i] == GDA_TYPE_NULL) if ( _gda_data_select_get_prep_stmt(pmodel)->types[i] == GDA_TYPE_NULL)
missing_cols [nb_missing++] = i; missing_cols [nb_missing++] = i;
} }
...@@ -203,10 +204,10 @@ read_rows_to_init_col_types (GdaSqliteRecordset *model) ...@@ -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); g_print ("Prefetched row %d of model %p\n", model->priv->next_row_num - 1, pmodel);
#endif #endif
for (i = nb_missing - 1; i >= 0; i--) { 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 #ifdef GDA_DEBUG_NO
g_print ("Found type '%s' for col %d\n", 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]); missing_cols [i]);
#endif #endif
memmove (missing_cols + i, missing_cols + i + 1, sizeof (gint) * (nb_missing - i - 1)); 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 ...@@ -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); cdata = (SqliteConnectionData*) gda_connection_internal_get_provider_data_error (cnc, error);
if (!cdata) if (!cdata)
return NULL; 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); 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 ...@@ -673,7 +674,7 @@ fetch_next_sqlite_row (GdaSqliteRecordset *model, gboolean do_store, GError **er
/* nothing to do */ /* nothing to do */
break; break;
case SQLITE_DONE: 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); SQLITE3_CALL (sqlite3_reset) (ps->sqlite_stmt);
break; break;
case SQLITE_READONLY: case SQLITE_READONLY:
...@@ -696,7 +697,7 @@ fetch_next_sqlite_row (GdaSqliteRecordset *model, gboolean do_store, GError **er ...@@ -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); gda_data_select_add_exception (GDA_DATA_SELECT (model), lerror);
if (rc == SQLITE_ERROR) if (rc == SQLITE_ERROR)
g_propagate_error (error, g_error_copy (lerror)); 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; break;
} }
} }
...@@ -717,13 +718,13 @@ gda_sqlite_recordset_fetch_nb_rows (GdaDataSelect *model) ...@@ -717,13 +718,13 @@ gda_sqlite_recordset_fetch_nb_rows (GdaDataSelect *model)
GdaRow *prow = NULL; GdaRow *prow = NULL;
imodel = GDA_SQLITE_RECORDSET (model); imodel = GDA_SQLITE_RECORDSET (model);
if (model->advertized_nrows >= 0) if (_gda_data_select_get_advertized_nrows (model) >= 0)
return model->advertized_nrows; return _gda_data_select_get_advertized_nrows (model);
for (prow = fetch_next_sqlite_row (imodel, TRUE, NULL); for (prow = fetch_next_sqlite_row (imodel, TRUE, NULL);
prow; prow;
prow = fetch_next_sqlite_row (imodel, TRUE, NULL)); prow = fetch_next_sqlite_row (imodel, TRUE, NULL));
return model->advertized_nrows; return _gda_data_select_get_advertized_nrows (model);
} }
/* /*
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "gda-mysql-recordset.h" #include "gda-mysql-recordset.h"
#include "gda-mysql-provider.h" #include "gda-mysql-provider.h"
#include "gda-mysql-util.h" #include "gda-mysql-util.h"
#include "gda-data-select-extra.h"
#include <libgda/libgda-global-variables.h> #include <libgda/libgda-global-variables.h>
#ifdef HAVE_LOCALE_H #ifdef HAVE_LOCALE_H
#include <locale.h> #include <locale.h>
...@@ -259,7 +260,7 @@ gda_mysql_recordset_dispose (GObject *object) ...@@ -259,7 +260,7 @@ gda_mysql_recordset_dispose (GObject *object)
g_return_if_fail (GDA_IS_MYSQL_RECORDSET (recset)); g_return_if_fail (GDA_IS_MYSQL_RECORDSET (recset));
if (recset->priv) { 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) { if (recset->priv->cnc) {
g_object_unref (G_OBJECT(recset->priv->cnc)); g_object_unref (G_OBJECT(recset->priv->cnc));
...@@ -456,7 +457,7 @@ gda_mysql_recordset_new_direct (GdaConnection *cnc, GdaDataModelAccessFlags flag ...@@ -456,7 +457,7 @@ gda_mysql_recordset_new_direct (GdaConnection *cnc, GdaDataModelAccessFlags flag
MYSQL_FIELD *mysql_fields = mysql_fetch_fields (mysql_res); MYSQL_FIELD *mysql_fields = mysql_fetch_fields (mysql_res);
GSList *list; 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; for (i=0, list = columns;
i < model->priv->ncols; i < model->priv->ncols;
i++, list = list->next) { i++, list = list->next) {
...@@ -704,7 +705,7 @@ gda_mysql_recordset_new (GdaConnection *cnc, ...@@ -704,7 +705,7 @@ gda_mysql_recordset_new (GdaConnection *cnc,
model->priv->mysql_stmt = ps->mysql_stmt; 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); return GDA_DATA_MODEL (model);
} }
...@@ -719,12 +720,12 @@ gda_mysql_recordset_fetch_nb_rows (GdaDataSelect *model) ...@@ -719,12 +720,12 @@ gda_mysql_recordset_fetch_nb_rows (GdaDataSelect *model)
GdaMysqlRecordset *imodel; GdaMysqlRecordset *imodel;
imodel = GDA_MYSQL_RECORDSET (model); imodel = GDA_MYSQL_RECORDSET (model);
if (model->advertized_nrows >= 0) if (_gda_data_select_get_advertized_nrows (model) >= 0)
return model->advertized_nrows; 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 * static GdaRow *
...@@ -735,7 +736,7 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, G_GNUC_UNUSED gint rownum, G ...@@ -735,7 +736,7 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, G_GNUC_UNUSED gint rownum, G
MYSQL_BIND *mysql_bind_result; MYSQL_BIND *mysql_bind_result;
g_return_val_if_fail (imodel->priv->mysql_stmt != NULL, NULL); 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); g_assert (mysql_bind_result);
res = mysql_stmt_fetch (imodel->priv->mysql_stmt); 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 ...@@ -752,7 +753,7 @@ new_row_from_mysql_stmt (GdaMysqlRecordset *imodel, G_GNUC_UNUSED gint rownum, G
"http://gitlab.gnome.org/GNOME/libgda/issues"); "http://gitlab.gnome.org/GNOME/libgda/issues");
gint col; 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; my_bool truncated;
mysql_bind_result[col].error = &truncated; mysql_bind_result[col].error = &truncated;
mysql_stmt_fetch_column (imodel->priv->mysql_stmt, &(mysql_bind_result[col]), 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 ...@@ -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); */ /* 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; 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; gint i = col;
GValue *value = gda_row_get_value (row, i); 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));*/ /*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, ...@@ -1061,7 +1062,7 @@ gda_mysql_recordset_fetch_random (GdaDataSelect *model,
gda_data_select_take_row (model, *row, rownum); 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 */ /* All the row have been converted. We could free result now */
/* but it was done before provided no field-based API functions */ /* but it was done before provided no field-based API functions */
/* that process result set meta data was needed in the middle. */ /* that process result set meta data was needed in the middle. */
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "gda-postgres-provider.h" #include "gda-postgres-provider.h"
#include "gda-postgres-blob-op.h" #include "gda-postgres-blob-op.h"
#include "gda-postgres-util.h" #include "gda-postgres-util.h"
#include "gda-data-select-extra.h"
#include <libgda/libgda-global-variables.h> #include <libgda/libgda-global-variables.h>
#ifdef HAVE_LOCALE_H #ifdef HAVE_LOCALE_H
#include <locale.h> #include <locale.h>
...@@ -347,9 +348,9 @@ gda_postgres_recordset_new_random (GdaConnection *cnc, GdaPostgresPStmt *ps, Gda ...@@ -347,9 +348,9 @@ gda_postgres_recordset_new_random (GdaConnection *cnc, GdaPostgresPStmt *ps, Gda
"model-usage", GDA_DATA_MODEL_ACCESS_RANDOM, "model-usage", GDA_DATA_MODEL_ACCESS_RANDOM,
"exec-params", exec_params, NULL); "exec-params", exec_params, NULL);
model->priv->pg_res = pg_res; 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) ...@@ -421,14 +422,14 @@ gda_postgres_recordset_fetch_nb_rows (GdaDataSelect *model)
GdaPostgresRecordset *imodel; GdaPostgresRecordset *imodel;
imodel = GDA_POSTGRES_RECORDSET (model); imodel = GDA_POSTGRES_RECORDSET (model);
if (model->advertized_nrows >= 0) if (_gda_data_select_get_advertized_nrows (model) >= 0)
return model->advertized_nrows; return _gda_data_select_get_advertized_nrows (model);
/* use C API to determine number of rows,if possible */ /* use C API to determine number of rows,if possible */
if (!imodel->priv->cursor_name) 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 ...@@ -450,7 +451,7 @@ gda_postgres_recordset_fetch_random (GdaDataSelect *model, GdaRow **prow, gint r
*prow = new_row_from_pg_res (imodel, rownum, error); *prow = new_row_from_pg_res (imodel, rownum, error);
gda_data_select_take_row (model, *prow, rownum); 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 /* all the rows have been converted from PGresult to GdaRow objects => we can
* discard the PGresult */ * discard the PGresult */
PQclear (imodel->priv->pg_res); PQclear (imodel->priv->pg_res);
...@@ -475,7 +476,7 @@ gda_postgres_recordset_store_all (GdaDataSelect *model, GError **error) ...@@ -475,7 +476,7 @@ gda_postgres_recordset_store_all (GdaDataSelect *model, GError **error)
return FALSE; return FALSE;
} }
for (i = 0; i < model->advertized_nrows; i++) { for (i = 0; i < _gda_data_select_get_advertized_nrows (model); i++) {
GdaRow *prow; GdaRow *prow;
if (! gda_postgres_recordset_fetch_random (model, &prow, i, error)) if (! gda_postgres_recordset_fetch_random (model, &prow, i, error))
return FALSE; return FALSE;
...@@ -802,14 +803,14 @@ set_prow_with_pg_res (GdaPostgresRecordset *imodel, GdaRow *prow, gint pg_res_ro ...@@ -802,14 +803,14 @@ set_prow_with_pg_res (GdaPostgresRecordset *imodel, GdaRow *prow, gint pg_res_ro
gchar *thevalue; gchar *thevalue;
gint col; 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); thevalue = PQgetvalue (imodel->priv->pg_res, pg_res_rownum, col);
if (thevalue && (*thevalue != '\0' ? FALSE : PQgetisnull (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)); gda_value_set_null (gda_row_get_value (prow, col));
else else
set_value (gda_data_select_get_connection ((GdaDataSelect*) imodel), set_value (gda_data_select_get_connection ((GdaDataSelect*) imodel),
prow, gda_row_get_value (prow, col), prow, gda_row_get_value (prow, col),
((GdaDataSelect*) imodel)->prep_stmt->types [col], _gda_data_select_get_prep_stmt ((GdaDataSelect*) imodel)->types [col],
thevalue, thevalue,
PQgetlength (imodel->priv->pg_res, pg_res_rownum, col), error); 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 ** ...@@ -820,7 +821,7 @@ new_row_from_pg_res (GdaPostgresRecordset *imodel, gint pg_res_rownum, GError **
{ {
GdaRow *prow; 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); set_prow_with_pg_res (imodel, prow, pg_res_rownum, error);
return prow; return prow;
} }
...@@ -878,9 +879,9 @@ fetch_next_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e ...@@ -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 */ /* GDA_DATA_SELECT (model)->advertized_nrows and model->priv->pg_pos */
if (nbtuples < model->priv->chunk_size) { if (nbtuples < model->priv->chunk_size) {
if (model->priv->pg_pos == G_MININT) 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 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; model->priv->pg_pos = G_MAXINT;
} }
...@@ -893,9 +894,9 @@ fetch_next_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e ...@@ -893,9 +894,9 @@ fetch_next_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e
} }
else { else {
if (model->priv->pg_pos == G_MININT) 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 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; model->priv->pg_pos = G_MAXINT;
retval = FALSE; retval = FALSE;
} }
...@@ -921,7 +922,7 @@ fetch_prev_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e ...@@ -921,7 +922,7 @@ fetch_prev_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e
if (model->priv->pg_pos == G_MININT) if (model->priv->pg_pos == G_MININT)
return FALSE; return FALSE;
else if (model->priv->pg_pos == G_MAXINT) 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; gchar *str;
gboolean retval = TRUE; gboolean retval = TRUE;
...@@ -963,7 +964,7 @@ fetch_prev_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e ...@@ -963,7 +964,7 @@ fetch_prev_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e
if (nbtuples > 0) { if (nbtuples > 0) {
/* model->priv->pg_res_inf */ /* model->priv->pg_res_inf */
if (model->priv->pg_pos == G_MAXINT) 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 else
model->priv->pg_res_inf = model->priv->pg_res_inf =
MAX (model->priv->pg_res_inf - (noffset - model->priv->chunk_size), 0); 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 ...@@ -974,7 +975,7 @@ fetch_prev_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **e
} }
else { else {
if (model->priv->pg_pos == G_MAXINT) 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 else
model->priv->pg_pos = MAX (model->priv->pg_pos - noffset, -1) + nbtuples; model->priv->pg_pos = MAX (model->priv->pg_pos - noffset, -1) + nbtuples;
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "gda-capi.h" #include "gda-capi.h"
#include "gda-capi-recordset.h" #include "gda-capi-recordset.h"
#include "gda-capi-provider.h" #include "gda-capi-provider.h"
#include "gda-data-select-extra.h"
#include <libgda/gda-debug-macros.h> #include <libgda/gda-debug-macros.h>
#define _GDA_PSTMT(x) ((GdaPStmt*)(x)) #define _GDA_PSTMT(x) ((GdaPStmt*)(x))
...@@ -235,14 +236,14 @@ gda_capi_recordset_fetch_nb_rows (GdaDataSelect *model) ...@@ -235,14 +236,14 @@ gda_capi_recordset_fetch_nb_rows (GdaDataSelect *model)
GdaCapiRecordset *imodel; GdaCapiRecordset *imodel;
imodel = GDA_CAPI_RECORDSET (model); imodel = GDA_CAPI_RECORDSET (model);
if (model->advertized_nrows >= 0) if (_gda_data_select_get_advertized_nrows (model) >= 0)
return model->advertized_nrows; return _gda_data_select_get_advertized_nrows (model);
/* use C API to determine number of rows,if possible */ /* use C API to determine number of rows,if possible */
g_warning("imodel not used: %p", imodel); /* Avoids a compiler warning. */ g_warning("imodel not used: %p", imodel); /* Avoids a compiler warning. */
TO_IMPLEMENT; TO_IMPLEMENT;
return model->advertized_nrows; return _gda_data_select_get_advertized_nrows (model);
} }
/* /*
......