libgda r3143 - in trunk: doc/C doc/C/tmpl libgda libgda/providers-support providers/postgres
- From: vivien svn gnome org
- To: svn-commits-list gnome org
- Subject: libgda r3143 - in trunk: doc/C doc/C/tmpl libgda libgda/providers-support providers/postgres
- Date: Thu, 10 Apr 2008 20:33:50 +0100 (BST)
Author: vivien
Date: Thu Apr 10 20:33:49 2008
New Revision: 3143
URL: http://svn.gnome.org/viewvc/libgda?rev=3143&view=rev
Log:
2008-04-10 Vivien Malerba <malerba gnome-db org>
* doc/C/libgda-4.0-sections.txt:
* doc/C/tmpl/gda-pmodel.sgml:
* providers/postgres/gda-postgres-recordset.c:
* libgda/gda-holder.c:
* libgda/gda-data-model-iter.c:
* libgda/gda-value.c:
* libgda/providers-support/gda-pmodel.[ch]:
* libgda/providers-support/gda-prow.c:
* libgda/gda-value.h:
* libgda/gda-set.c:
* libgda/gda-data-model.c: minor tweaks to improve performances
Modified:
trunk/doc/C/libgda-4.0-sections.txt
trunk/doc/C/tmpl/gda-pmodel.sgml
trunk/libgda/gda-data-model-iter.c
trunk/libgda/gda-data-model.c
trunk/libgda/gda-holder.c
trunk/libgda/gda-set.c
trunk/libgda/gda-value.c
trunk/libgda/gda-value.h
trunk/libgda/providers-support/gda-pmodel.c
trunk/libgda/providers-support/gda-pmodel.h
trunk/libgda/providers-support/gda-prow.c
trunk/providers/postgres/gda-postgres-recordset.c
Modified: trunk/doc/C/libgda-4.0-sections.txt
==============================================================================
--- trunk/doc/C/libgda-4.0-sections.txt (original)
+++ trunk/doc/C/libgda-4.0-sections.txt Thu Apr 10 20:33:49 2008
@@ -776,6 +776,7 @@
gda_value_set_from_string
gda_value_set_from_value
gda_value_stringify
+gda_value_bcompare
gda_value_compare
gda_value_compare_ext
gda_value_to_xml
Modified: trunk/doc/C/tmpl/gda-pmodel.sgml
==============================================================================
--- trunk/doc/C/tmpl/gda-pmodel.sgml (original)
+++ trunk/doc/C/tmpl/gda-pmodel.sgml Thu Apr 10 20:33:49 2008
@@ -41,6 +41,7 @@
@prep_stmt: SELECT prepared statement for which the execution gave this object
@nb_stored_rows:
@advertized_nrows: initially set to -1, set to a value >= 0 when the number of rows in the data model is known
+ cnc:
<!-- ##### STRUCT GdaPModelClass ##### -->
<para>
Modified: trunk/libgda/gda-data-model-iter.c
==============================================================================
--- trunk/libgda/gda-data-model-iter.c (original)
+++ trunk/libgda/gda-data-model-iter.c Thu Apr 10 20:33:49 2008
@@ -255,7 +255,7 @@
GdaDataModelIter *iter;
gint col;
- iter = GDA_DATA_MODEL_ITER (paramlist);
+ iter = (GdaDataModelIter *) paramlist;
if (!iter->priv->keep_param_changes && (iter->priv->row >= 0)) {
g_signal_handler_block (iter->priv->data_model, iter->priv->model_changes_signals [0]);
g_signal_handler_block (iter->priv->data_model, iter->priv->model_changes_signals [1]);
@@ -264,7 +264,7 @@
col = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (param), "model_col")) - 1;
g_return_if_fail (col >= 0);
- if (! gda_data_model_set_value_at (GDA_DATA_MODEL (iter->priv->data_model),
+ if (! gda_data_model_set_value_at ((GdaDataModel *) iter->priv->data_model,
col, iter->priv->row, gda_holder_get_value (param), NULL)) {
/* writing to the model failed, revert back the change to parameter */
iter->priv->keep_param_changes = TRUE;
Modified: trunk/libgda/gda-data-model.c
==============================================================================
--- trunk/libgda/gda-data-model.c (original)
+++ trunk/libgda/gda-data-model.c Thu Apr 10 20:33:49 2008
@@ -752,7 +752,7 @@
g_object_get (G_OBJECT (iter), "update_model", &update_model, NULL);
g_object_set (G_OBJECT (iter), "update_model", FALSE, NULL);
for (col = 0, list = ((GdaSet *) iter)->holders; list; col++, list = list->next) {
- gda_holder_set_value (GDA_HOLDER (list->data),
+ gda_holder_set_value ((GdaHolder*) list->data,
gda_data_model_get_value_at (model, col, row));
set_param_attributes ((GdaHolder*) list->data,
@@ -830,7 +830,7 @@
g_object_get (G_OBJECT (iter), "update_model", &update_model, NULL);
g_object_set (G_OBJECT (iter), "update_model", FALSE, NULL);
for (col = 0, list = ((GdaSet *) iter)->holders; list; col++, list = list->next) {
- gda_holder_set_value (GDA_HOLDER (list->data),
+ gda_holder_set_value ((GdaHolder *) list->data,
gda_data_model_get_value_at (model, col, row));
set_param_attributes ((GdaHolder *) list->data,
gda_data_model_get_attributes_at (model, col, row));
@@ -893,7 +893,7 @@
g_object_get (G_OBJECT (iter), "update_model", &update_model, NULL);
g_object_set (G_OBJECT (iter), "update_model", FALSE, NULL);
for (col = 0, list = ((GdaSet *) iter)->holders; list; col++, list = list->next) {
- gda_holder_set_value (GDA_HOLDER (list->data),
+ gda_holder_set_value ((GdaHolder*) list->data,
gda_data_model_get_value_at (model, col, row));
set_param_attributes ((GdaHolder*) list->data,
gda_data_model_get_attributes_at (model, col, row));
Modified: trunk/libgda/gda-holder.c
==============================================================================
--- trunk/libgda/gda-holder.c (original)
+++ trunk/libgda/gda-holder.c Thu Apr 10 20:33:49 2008
@@ -386,9 +386,6 @@
{
GdaHolder *holder;
- g_return_if_fail (object != NULL);
- g_return_if_fail (GDA_IS_HOLDER (object));
-
holder = GDA_HOLDER (object);
if (holder->priv) {
gda_holder_set_bind (holder, NULL);
@@ -765,6 +762,7 @@
gboolean changed = TRUE;
gboolean newvalid;
const GValue *current_val;
+ gboolean newnull;
#define DEBUG_HOLDER
#undef DEBUG_HOLDER
@@ -775,27 +773,24 @@
holder->priv->invalid_forced = FALSE;
/* holder will be changed? */
+ newnull = !value || gda_value_is_null (value);
current_val = gda_holder_get_value (holder);
if (current_val == value)
changed = FALSE;
- else if ((!current_val || gda_value_is_null ((GValue *)current_val)) &&
- (!value || gda_value_is_null (value)))
+ else if ((!current_val || gda_value_is_null ((GValue *)current_val)) && newnull)
changed = FALSE;
else if (value && current_val &&
(G_VALUE_TYPE (value) == G_VALUE_TYPE ((GValue *)current_val)))
- changed = gda_value_compare (value, (GValue *)current_val);
+ changed = gda_value_bcompare (value, (GValue *)current_val);
/* holder's validity */
newvalid = TRUE;
- if (!value || gda_value_is_null (value))
+ if (newnull)
if (holder->priv->not_null)
newvalid = FALSE;
- if (value &&
- (G_VALUE_TYPE (value) != GDA_TYPE_NULL) &&
- (G_VALUE_TYPE (value) != holder->priv->g_type)) {
+ if (!newnull && (G_VALUE_TYPE (value) != holder->priv->g_type))
newvalid = FALSE;
- }
#ifdef DEBUG_HOLDER
g_print ("Changed holder %p (%s): value %s --> %s \t(type %d -> %d) VALID: %d->%d CHANGED: %d\n",
@@ -819,8 +814,7 @@
/* check is the new value is the default one */
holder->priv->default_forced = FALSE;
if (holder->priv->default_value) {
- if ((G_VALUE_TYPE (holder->priv->default_value) == GDA_TYPE_NULL) &&
- (!value || gda_value_is_null (value)))
+ if ((G_VALUE_TYPE (holder->priv->default_value) == GDA_TYPE_NULL) && newnull)
holder->priv->default_forced = TRUE;
else if ((G_VALUE_TYPE (holder->priv->default_value) == holder->priv->g_type) &&
value && (G_VALUE_TYPE (value) == holder->priv->g_type))
@@ -1226,7 +1220,7 @@
/* get a copy of the current values of @holder and @alias_of */
if (alias_of) {
- g_return_if_fail (alias_of && GDA_IS_HOLDER (alias_of));
+ g_return_if_fail (GDA_IS_HOLDER (alias_of));
g_return_if_fail (alias_of->priv);
g_return_if_fail (holder->priv->g_type == alias_of->priv->g_type);
cvalue = gda_holder_get_value (alias_of);
Modified: trunk/libgda/gda-set.c
==============================================================================
--- trunk/libgda/gda-set.c (original)
+++ trunk/libgda/gda-set.c Thu Apr 10 20:33:49 2008
@@ -725,10 +725,10 @@
gdatype = xmlGetProp (cur, BAD_CAST "gdatype");
if (!holder) {
- holder = GDA_HOLDER (g_object_new (GDA_TYPE_HOLDER,
- "g_type",
- gdatype ? gda_g_type_from_string ((gchar *) gdatype) : G_TYPE_STRING,
- NULL));
+ holder = (GdaHolder*) (g_object_new (GDA_TYPE_HOLDER,
+ "g_type",
+ gdatype ? gda_g_type_from_string ((gchar *) gdatype) : G_TYPE_STRING,
+ NULL));
holders = g_slist_append (holders, holder);
}
if (gdatype) xmlFree (gdatype);
@@ -1035,7 +1035,7 @@
for (list = set->holders; list; list = list->next) {
node = g_new0 (GdaSetNode, 1);
node->holder = GDA_HOLDER (list->data);
- node->source_model = gda_holder_get_source_model (GDA_HOLDER (list->data),
+ node->source_model = gda_holder_get_source_model (node->holder,
&(node->source_column));
if (node->source_model)
g_object_ref (node->source_model);
@@ -1318,7 +1318,7 @@
g_return_val_if_fail (set->priv, FALSE);
for (holders = set->holders; holders && retval; holders = g_slist_next (holders)) {
- if (!gda_holder_is_valid (GDA_HOLDER (holders->data)))
+ if (!gda_holder_is_valid ((GdaHolder*) holders->data))
retval = FALSE;
#ifdef GDA_DEBUG_NO
Modified: trunk/libgda/gda-value.c
==============================================================================
--- trunk/libgda/gda-value.c (original)
+++ trunk/libgda/gda-value.c Thu Apr 10 20:33:49 2008
@@ -39,9 +39,7 @@
#include <libxml/parser.h>
#include <libxml/tree.h>
-#define l_g_value_unset(val) if G_IS_VALUE (val) g_value_unset (val)
-
-
+#define l_g_value_unset(val) G_STMT_START{ if (G_IS_VALUE (val)) g_value_unset (val); }G_STMT_END
static gboolean
set_from_string (GValue *value, const gchar *as_string)
@@ -60,7 +58,7 @@
}
type = G_VALUE_TYPE (value);
- gda_value_reset_with_type (value, type);
+ g_value_reset (value);
if (g_value_type_transformable (G_TYPE_STRING, type)) {
/* use the GLib type transformation function */
@@ -1227,11 +1225,15 @@
{
g_return_if_fail (value);
- l_g_value_unset (value);
- if (type == GDA_TYPE_NULL || type == G_TYPE_INVALID)
- return;
- else
- g_value_init (value, type);
+ if (G_IS_VALUE (value) && (G_VALUE_TYPE (value) == type))
+ g_value_reset (value);
+ else {
+ l_g_value_unset (value);
+ if (type == GDA_TYPE_NULL || type == G_TYPE_INVALID)
+ return;
+ else
+ g_value_init (value, type);
+ }
}
@@ -1782,6 +1784,124 @@
}
/**
+ * gda_value_bcompare
+ * @value1: a #GValue to compare.
+ * @value2: the other #GValue to be compared to @value1.
+ *
+ * Tells if two values are equal or not
+ *
+ * Returns: 0 if @value1 and @value2 are equal, and something else otherwise
+ */
+gint
+gda_value_bcompare (const GValue *value1, const GValue *value2)
+{
+ GType type;
+ g_return_val_if_fail (value1 && value2, FALSE);
+
+ /* blind value comparison */
+ if (!bcmp (value1, value2, sizeof (GValue)))
+ return 0;
+
+ type = G_VALUE_TYPE (value1);
+ if (type == GDA_TYPE_BINARY) {
+ const GdaBinary *binary1 = gda_value_get_binary (value1);
+ const GdaBinary *binary2 = gda_value_get_binary (value2);
+ if (binary1 && binary2 && (binary1->binary_length == binary2->binary_length))
+ return bcmp (binary1->data, binary2->data, binary1->binary_length) ;
+ }
+
+ else if (type == GDA_TYPE_BLOB) {
+ const GdaBlob *blob1 = gda_value_get_blob (value1);
+ const GdaBlob *blob2 = gda_value_get_blob (value2);
+ if (blob1 && blob2 && (((GdaBinary *)blob1)->binary_length == ((GdaBinary *)blob2)->binary_length)) {
+ if (blob1->op == blob2->op)
+ return bcmp (((GdaBinary *)blob1)->data, ((GdaBinary *)blob2)->data,
+ ((GdaBinary *)blob1)->binary_length);
+ }
+ }
+
+ else if (type == G_TYPE_DATE) {
+ GDate *d1, *d2;
+
+ d1 = (GDate *) g_value_get_boxed (value1);
+ d2 = (GDate *) g_value_get_boxed (value2);
+ if (d1 && d2)
+ return g_date_compare (d1, d2);
+ }
+
+ else if (type == GDA_TYPE_GEOMETRIC_POINT) {
+ const GdaGeometricPoint *p1, *p2;
+ p1 = gda_value_get_geometric_point (value1);
+ p2 = gda_value_get_geometric_point (value2);
+ if (p1 && p2)
+ return bcmp (p1, p2, sizeof (GdaGeometricPoint));
+ }
+
+ else if (type == G_TYPE_OBJECT) {
+ if (g_value_get_object (value1) == g_value_get_object (value2))
+ return 0;
+ else
+ return -1;
+ }
+
+ else if (type == GDA_TYPE_LIST) {
+ GList *l1, *l2;
+ for (l1 = (GList*) gda_value_get_list (value1), l2 = (GList*) gda_value_get_list (value2);
+ l1 != NULL && l2 != NULL; l1 = l1->next, l2 = l2->next){
+ if (gda_value_bcompare ((GValue *) l1->data, (GValue *) l2->data))
+ return 1;
+ }
+ return 0;
+ }
+
+ else if (type == GDA_TYPE_NUMERIC) {
+ const GdaNumeric *num1, *num2;
+ num1= gda_value_get_numeric (value1);
+ num2 = gda_value_get_numeric (value2);
+ if (num1 && num2)
+ return strcmp (num1->number, num2->number);
+ }
+
+ else if (type == GDA_TYPE_SHORT) {
+ gshort i1 = gda_value_get_short (value1);
+ gshort i2 = gda_value_get_short (value2);
+ return (i1 == i2) ? 0 : 1;
+ }
+
+ else if (type == GDA_TYPE_USHORT) {
+ gushort i1 = gda_value_get_ushort (value1);
+ gushort i2 = gda_value_get_ushort (value2);
+ return (i1 == i2) ? 0 : 1;
+ }
+
+ else if (type == G_TYPE_STRING) {
+ const gchar *str1, *str2;
+ str1 = g_value_get_string (value1);
+ str2 = g_value_get_string (value2);
+ if (str1 && str2)
+ return strcmp (str1, str2);
+ }
+
+ else if (type == GDA_TYPE_TIME) {
+ const GdaTime *t1, *t2;
+ t1 = gda_value_get_time (value1);
+ t2 = gda_value_get_time (value2);
+ if (t1 && t2)
+ return bcmp (t1, t2, sizeof (GdaTime));
+ }
+
+ else if (type == GDA_TYPE_TIMESTAMP) {
+ const GdaTimestamp *ts1, *ts2;
+ ts1 = gda_value_get_timestamp (value1);
+ ts2 = gda_value_get_timestamp (value2);
+ if (ts1 && ts2)
+ return bcmp (ts1, ts2, sizeof (GdaTimestamp));
+ }
+
+ return 1;
+}
+
+/**
* gda_value_compare
* @value1: a #GValue to compare.
* @value2: the other #GValue to be compared to @value1.
@@ -1807,13 +1927,17 @@
if (value1 == value2)
return 0;
- else if (type == G_TYPE_INT64)
- return (g_value_get_int64 (value1) > g_value_get_int64 (value2)) ? 1 :
- ((g_value_get_int64 (value1) == g_value_get_int64 (value2)) ? 0 : -1);
+ else if (type == G_TYPE_INT64) {
+ gint64 i1 = g_value_get_int64 (value1);
+ gint64 i2 = g_value_get_int64 (value2);
+ return (i1 > i2) ? 1 : ((i1 == i2) ? 0 : -1);
+ }
- else if (type == G_TYPE_UINT64)
- return (g_value_get_uint64 (value1) > g_value_get_uint64 (value2)) ? 1 :
- ((g_value_get_uint64 (value1) == g_value_get_uint64 (value2)) ? 0 : -1);
+ else if (type == G_TYPE_UINT64) {
+ guint64 i1 = g_value_get_uint64 (value1);
+ guint64 i2 = g_value_get_uint64 (value2);
+ return (i1 > i2) ? 1 : ((i1 == i2) ? 0 : -1);
+ }
else if (type == GDA_TYPE_BINARY) {
const GdaBinary *binary1 = gda_value_get_binary (value1);
@@ -1894,8 +2018,7 @@
}
else if (type == G_TYPE_INT)
- return (g_value_get_int (value1) > g_value_get_int (value2)) ? 1 :
- ((g_value_get_int (value1) == g_value_get_int (value2)) ? 0 : -1);
+ return g_value_get_int (value1) - g_value_get_int (value2);
else if (type == GDA_TYPE_LIST) {
retval = 0;
@@ -1931,25 +2054,35 @@
return retval;
}
- else if (type == G_TYPE_FLOAT)
- return (g_value_get_float (value1) > g_value_get_float (value2)) ? 1 :
- ((g_value_get_float (value1) == g_value_get_float (value2)) ? 0 : -1);
-
- else if (type == GDA_TYPE_SHORT)
- return (gda_value_get_short (value1) > gda_value_get_short (value2)) ? 1 :
- ((gda_value_get_short (value1) == gda_value_get_short (value2)) ? 0 : -1);
-
- else if (type == G_TYPE_ULONG)
- return (g_value_get_ulong (value1) > g_value_get_ulong (value2)) ? 1 :
- ((g_value_get_ulong (value1) == g_value_get_ulong (value2)) ? 0 : -1);
-
- else if (type == G_TYPE_LONG)
- return (g_value_get_long (value1) > g_value_get_long (value2)) ? 1 :
- ((g_value_get_long (value1) == g_value_get_long (value2)) ? 0 : -1);
-
- else if (type == GDA_TYPE_USHORT)
- return (gda_value_get_ushort (value1) > gda_value_get_ushort (value2)) ? 1 :
- ((gda_value_get_ushort (value1) == gda_value_get_ushort (value2)) ? 0 : -1);
+ else if (type == G_TYPE_FLOAT) {
+ gfloat f1 = g_value_get_float (value1);
+ gfloat f2 = g_value_get_float (value2);
+ return (f1 > f2) ? 1 : ((f1 == f2) ? 0 : -1);
+ }
+
+ else if (type == GDA_TYPE_SHORT) {
+ gshort i1 = gda_value_get_short (value1);
+ gshort i2 = gda_value_get_short (value2);
+ return (i1 > i2) ? 1 : ((i1 == i2) ? 0 : -1);
+ }
+
+ else if (type == G_TYPE_ULONG) {
+ gulong i1 = g_value_get_ulong (value1);
+ gulong i2 = g_value_get_ulong (value2);
+ return (i1 > i2) ? 1 : ((i1 == i2) ? 0 : -1);
+ }
+
+ else if (type == G_TYPE_LONG) {
+ glong i1 = g_value_get_long (value1);
+ glong i2 = g_value_get_long (value2);
+ return (i1 > i2) ? 1 : ((i1 == i2) ? 0 : -1);
+ }
+
+ else if (type == GDA_TYPE_USHORT) {
+ gushort i1 = gda_value_get_ushort (value1);
+ gushort i2 = gda_value_get_ushort (value2);
+ return (i1 > i2) ? 1 : ((i1 == i2) ? 0 : -1);
+ }
else if (type == G_TYPE_STRING) {
const gchar *str1, *str2;
@@ -1999,18 +2132,23 @@
return 0;
}
- else if (type == G_TYPE_CHAR)
- return (g_value_get_char (value1) > g_value_get_char (value2)) ? 1 :
- ((g_value_get_char (value1) == g_value_get_char (value2)) ? 0 : -1);
-
- else if (type == G_TYPE_UCHAR)
- return (g_value_get_uchar (value1) > g_value_get_uchar (value2)) ? 1 :
- ((g_value_get_uchar (value1) == g_value_get_uchar (value2)) ? 0 : -1);
-
- else if (type == G_TYPE_UINT)
- return (g_value_get_uint (value1) > g_value_get_uint (value2)) ? 1 :
- ((g_value_get_uint (value1) == g_value_get_uint (value2)) ? 0 : -1);
+ else if (type == G_TYPE_CHAR) {
+ gchar c1 = g_value_get_char (value1);
+ gchar c2 = g_value_get_char (value2);
+ return (c1 > c2) ? 1 : ((c1 == c2) ? 0 : -1);
+ }
+ else if (type == G_TYPE_UCHAR) {
+ guchar c1 = g_value_get_uchar (value1);
+ guchar c2 = g_value_get_uchar (value2);
+ return (c1 > c2) ? 1 : ((c1 == c2) ? 0 : -1);
+ }
+
+ else if (type == G_TYPE_UINT) {
+ guint i1 = g_value_get_uint (value1);
+ guint i2 = g_value_get_uint (value2);
+ return (i1 > i2) ? 1 : ((i1 == i2) ? 0 : -1);
+ }
g_warning ("%s() cannot handle values of type %s", __FUNCTION__, g_type_name (G_VALUE_TYPE (value1)));
Modified: trunk/libgda/gda-value.h
==============================================================================
--- trunk/libgda/gda-value.h (original)
+++ trunk/libgda/gda-value.h Thu Apr 10 20:33:49 2008
@@ -155,7 +155,7 @@
GType type);
gboolean gda_value_set_from_value (GValue *value, const GValue *from);
-
+gint gda_value_bcompare (const GValue *value1, const GValue *value2);
gint gda_value_compare (const GValue *value1, const GValue *value2);
gint gda_value_compare_ext (const GValue *value1, const GValue *value2);
gchar *gda_value_stringify (const GValue *value);
Modified: trunk/libgda/providers-support/gda-pmodel.c
==============================================================================
--- trunk/libgda/providers-support/gda-pmodel.c (original)
+++ trunk/libgda/providers-support/gda-pmodel.c Thu Apr 10 20:33:49 2008
@@ -48,7 +48,6 @@
* model row ==(model->index)==> model->rows index ==(model->rows)==> GdaPRow
*/
struct _GdaPModelPrivate {
- GdaConnection *cnc;
GSList *columns; /* list of GdaColumn objects */
GArray *rows; /* Array of GdaPRow */
GHashTable *index; /* key = model row number + 1, value = index in @rows array + 1*/
@@ -222,7 +221,7 @@
{
g_return_if_fail (GDA_IS_PMODEL (model));
model->priv = g_new0 (GdaPModelPrivate, 1);
- model->priv->cnc = NULL;
+ model->cnc = NULL;
model->priv->rows = g_array_new (FALSE, FALSE, sizeof (GdaPRow *));
model->priv->index = g_hash_table_new (g_direct_hash, g_direct_equal);
model->prep_stmt = NULL;
@@ -243,9 +242,9 @@
/* free memory */
if (model->priv) {
gint i;
- if (model->priv->cnc) {
- g_object_unref (model->priv->cnc);
- model->priv->cnc = NULL;
+ if (model->cnc) {
+ g_object_unref (model->cnc);
+ model->cnc = NULL;
}
if (model->prep_stmt) {
g_object_unref (model->prep_stmt);
@@ -342,9 +341,9 @@
if (model->priv) {
switch (param_id) {
case PROP_CNC:
- model->priv->cnc = g_value_get_object (value);
- if (model->priv->cnc)
- g_object_ref (model->priv->cnc);
+ model->cnc = g_value_get_object (value);
+ if (model->cnc)
+ g_object_ref (model->cnc);
break;
case PROP_PREP_STMT:
if (model->prep_stmt)
@@ -408,7 +407,7 @@
if (model->priv) {
switch (param_id) {
case PROP_CNC:
- g_value_set_object (value, model->priv->cnc);
+ g_value_set_object (value, model->cnc);
break;
case PROP_PREP_STMT:
g_value_set_object (value, model->prep_stmt);
@@ -501,7 +500,7 @@
g_return_val_if_fail (GDA_IS_PMODEL (model), NULL);
g_return_val_if_fail (model->priv, NULL);
- return model->priv->cnc;
+ return model->cnc;
}
/**
@@ -831,24 +830,24 @@
static void
update_iter (GdaPModel *imodel, GdaPRow *prow)
{
- gint i, length;
+ gint i;
GdaDataModelIter *iter = imodel->priv->iter;
GSList *plist;
gboolean update_model;
g_object_get (G_OBJECT (iter), "update_model", &update_model, NULL);
- g_object_set (G_OBJECT (iter), "update_model", FALSE, NULL);
+ if (update_model)
+ g_object_set (G_OBJECT (iter), "update_model", FALSE, NULL);
- length = gda_prow_get_length (prow);
- g_assert (length == g_slist_length (GDA_SET (iter)->holders));
for (i = 0, plist = GDA_SET (iter)->holders;
- i < length;
+ plist;
i++, plist = plist->next) {
const GValue *value;
value = gda_prow_get_value (prow, i);
- gda_holder_set_value (GDA_HOLDER (plist->data), value);
+ gda_holder_set_value ((GdaHolder*) plist->data, value);
}
g_object_set (G_OBJECT (iter), "current-row", imodel->priv->iter_row, NULL);
- g_object_set (G_OBJECT (iter), "update_model", update_model, NULL);
+ if (update_model)
+ g_object_set (G_OBJECT (iter), "update_model", update_model, NULL);
}
Modified: trunk/libgda/providers-support/gda-pmodel.h
==============================================================================
--- trunk/libgda/providers-support/gda-pmodel.h (original)
+++ trunk/libgda/providers-support/gda-pmodel.h Thu Apr 10 20:33:49 2008
@@ -46,6 +46,7 @@
GdaPStmt *prep_stmt; /* use the "prepared-stmt" property to set this */
gint nb_stored_rows; /* number of GdaPRow objects currently stored */
gint advertized_nrows; /* set when the number of rows becomes known */
+ GdaConnection *cnc;
};
/*
Modified: trunk/libgda/providers-support/gda-prow.c
==============================================================================
--- trunk/libgda/providers-support/gda-prow.c (original)
+++ trunk/libgda/providers-support/gda-prow.c Thu Apr 10 20:33:49 2008
@@ -204,13 +204,9 @@
GdaPRow *
gda_prow_new (gint count)
{
- GdaPRow *prow = NULL;
-
g_return_val_if_fail (count > 0, NULL);
-
- prow = g_object_new (GDA_TYPE_PROW, "nb_values", count, NULL);
-
- return prow;
+
+ return (GdaPRow*) g_object_new (GDA_TYPE_PROW, "nb_values", count, NULL);
}
/**
@@ -229,7 +225,6 @@
gda_prow_get_value (GdaPRow *prow, gint num)
{
g_return_val_if_fail (GDA_IS_PROW (prow), NULL);
- g_return_val_if_fail (prow->priv, NULL);
g_return_val_if_fail (num >= 0 && num < prow->priv->nfields, NULL);
return & (prow->priv->fields[num]);
Modified: trunk/providers/postgres/gda-postgres-recordset.c
==============================================================================
--- trunk/providers/postgres/gda-postgres-recordset.c (original)
+++ trunk/providers/postgres/gda-postgres-recordset.c Thu Apr 10 20:33:49 2008
@@ -62,8 +62,9 @@
static void make_point (GdaGeometricPoint *point, const gchar *value);
static void make_time (GdaTime *timegda, const gchar *value);
static void make_timestamp (GdaTimestamp *timestamp, const gchar *value);
-static void set_value (GdaConnection *cnc, GValue *value, GType type, const gchar *thevalue, gboolean isNull, gint length);
+static void set_value (GdaConnection *cnc, GValue *value, GType type, const gchar *thevalue, gint length);
+static void set_prow_with_pg_res (GdaPostgresRecordset *imodel, GdaPRow *prow, gint pg_res_rownum);
static GdaPRow *new_row_from_pg_res (GdaPostgresRecordset *imodel, gint pg_res_rownum);
static gboolean row_is_in_current_pg_res (GdaPostgresRecordset *model, gint row);
static gboolean fetch_next_chunk (GdaPostgresRecordset *model, gboolean *fetch_error, GError **error);
@@ -487,21 +488,22 @@
if (*prow)
return TRUE;
- if (imodel->priv->tmp_row) {
- g_object_unref (imodel->priv->tmp_row);
- imodel->priv->tmp_row = NULL;
- }
-
if (row_is_in_current_pg_res (imodel, rownum)) {
- *prow = new_row_from_pg_res (imodel, rownum - imodel->priv->pg_res_inf);
- imodel->priv->tmp_row = *prow;
+ if (imodel->priv->tmp_row)
+ set_prow_with_pg_res (imodel, imodel->priv->tmp_row, rownum - imodel->priv->pg_res_inf);
+ else
+ imodel->priv->tmp_row = new_row_from_pg_res (imodel, rownum - imodel->priv->pg_res_inf);
+ *prow = imodel->priv->tmp_row;
return TRUE;
}
else {
gboolean fetch_error = FALSE;
if (fetch_next_chunk (imodel, &fetch_error, error)) {
- *prow = new_row_from_pg_res (imodel, rownum - imodel->priv->pg_res_inf);
- imodel->priv->tmp_row = *prow;
+ if (imodel->priv->tmp_row)
+ set_prow_with_pg_res (imodel, imodel->priv->tmp_row, rownum - imodel->priv->pg_res_inf);
+ else
+ imodel->priv->tmp_row = new_row_from_pg_res (imodel, rownum - imodel->priv->pg_res_inf);
+ *prow = imodel->priv->tmp_row;
return TRUE;
}
else
@@ -523,21 +525,22 @@
if (*prow)
return TRUE;
- if (imodel->priv->tmp_row) {
- g_object_unref (imodel->priv->tmp_row);
- imodel->priv->tmp_row = NULL;
- }
-
if (row_is_in_current_pg_res (imodel, rownum)) {
- *prow = new_row_from_pg_res (imodel, rownum - imodel->priv->pg_res_inf);
- imodel->priv->tmp_row = *prow;
+ if (imodel->priv->tmp_row)
+ set_prow_with_pg_res (imodel, imodel->priv->tmp_row, rownum - imodel->priv->pg_res_inf);
+ else
+ imodel->priv->tmp_row = new_row_from_pg_res (imodel, rownum - imodel->priv->pg_res_inf);
+ *prow = imodel->priv->tmp_row;
return TRUE;
}
else {
gboolean fetch_error = FALSE;
if (fetch_prev_chunk (imodel, &fetch_error, error)) {
- *prow = new_row_from_pg_res (imodel, rownum - imodel->priv->pg_res_inf);
- imodel->priv->tmp_row = *prow;
+ if (imodel->priv->tmp_row)
+ set_prow_with_pg_res (imodel, imodel->priv->tmp_row, rownum - imodel->priv->pg_res_inf);
+ else
+ imodel->priv->tmp_row = new_row_from_pg_res (imodel, rownum - imodel->priv->pg_res_inf);
+ *prow = imodel->priv->tmp_row;
return TRUE;
}
else
@@ -669,13 +672,8 @@
static void
set_value (GdaConnection *cnc, GValue *value, GType type,
- const gchar *thevalue, gboolean isNull, gint length)
+ const gchar *thevalue, gint length)
{
- if (isNull) {
- gda_value_set_null (value);
- return;
- }
-
gda_value_reset_with_type (value, type);
if (type == G_TYPE_BOOLEAN)
@@ -781,24 +779,32 @@
return FALSE;
}
-static GdaPRow *
-new_row_from_pg_res (GdaPostgresRecordset *imodel, gint pg_res_rownum)
+static void
+set_prow_with_pg_res (GdaPostgresRecordset *imodel, GdaPRow *prow, gint pg_res_rownum)
{
- GdaPRow *prow;
gchar *thevalue;
- gboolean isNull;
gint col;
- prow = gda_prow_new (((GdaPModel*) imodel)->prep_stmt->ncols);
for (col = 0; col < ((GdaPModel*) imodel)->prep_stmt->ncols; col++) {
thevalue = PQgetvalue (imodel->priv->pg_res, pg_res_rownum, col);
- isNull = thevalue && *thevalue != '\0' ? FALSE : PQgetisnull (imodel->priv->pg_res, pg_res_rownum, col);
- set_value (gda_pmodel_get_connection ((GdaPModel*) imodel),
- gda_prow_get_value (prow, col),
- ((GdaPModel*) imodel)->prep_stmt->types [col],
- thevalue, isNull,
- PQgetlength (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_prow_get_value (prow, col));
+ else
+ set_value (((GdaPModel*) imodel)->cnc,
+ gda_prow_get_value (prow, col),
+ ((GdaPModel*) imodel)->prep_stmt->types [col],
+ thevalue,
+ PQgetlength (imodel->priv->pg_res, pg_res_rownum, col));
}
+}
+
+static GdaPRow *
+new_row_from_pg_res (GdaPostgresRecordset *imodel, gint pg_res_rownum)
+{
+ GdaPRow *prow;
+
+ prow = gda_prow_new (((GdaPModel*) imodel)->prep_stmt->ncols);
+ set_prow_with_pg_res (imodel, prow, pg_res_rownum);
return prow;
}
@@ -828,7 +834,7 @@
status = PQresultStatus (model->priv->pg_res);
model->priv->chunks_read ++;
if (status != PGRES_TUPLES_OK) {
- _gda_postgres_make_error (gda_pmodel_get_connection ((GdaPModel*) model),
+ _gda_postgres_make_error (((GdaPModel*) model)->cnc,
model->priv->pconn, model->priv->pg_res, error);
PQclear (model->priv->pg_res);
model->priv->pg_res = NULL;
@@ -920,7 +926,7 @@
status = PQresultStatus (model->priv->pg_res);
model->priv->chunks_read ++;
if (status != PGRES_TUPLES_OK) {
- _gda_postgres_make_error (gda_pmodel_get_connection ((GdaPModel*) model),
+ _gda_postgres_make_error (((GdaPModel*) model)->cnc,
model->priv->pconn, model->priv->pg_res, error);
PQclear (model->priv->pg_res);
model->priv->pg_res = NULL;
@@ -994,7 +1000,7 @@
status = PQresultStatus (model->priv->pg_res);
model->priv->chunks_read ++; /* Not really correct, because we are only fetching 1 row, not a whole chunk of rows. */
if (status != PGRES_TUPLES_OK) {
- _gda_postgres_make_error (gda_pmodel_get_connection ((GdaPModel*) model),
+ _gda_postgres_make_error (((GdaPModel*) model)->cnc,
model->priv->pconn, model->priv->pg_res, error);
PQclear (model->priv->pg_res);
model->priv->pg_res = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]