Re: [gnome-db] db grid ordering
- From: Marius Andreiana <mandreiana rdslink ro>
- To: gnome-db <gnome-db-list gnome org>
- Subject: Re: [gnome-db] db grid ordering
- Date: Sun, 07 Dec 2003 02:47:31 +0200
On Sun, 2003-12-07 at 01:43, Marius Andreiana wrote:
> it only checks for BIGINT, but I have an INTEGER (tested this in
> libgda).
> Let's see if I can provide a patch
attached, what do you think?
Looks ok to me, it works ok except on one INTEGER column (other INTEGERs
work ok). Sorts fine 1st time, but on descending it crashes, mono gives
message:
Unhandled Exception: System.NullReferenceException: A null value was
found where an object instance was required
in (unmanaged) (wrapper managed-to-native) Gtk.Application:gtk_main ()
in <0x00004> (wrapper managed-to-native) Gtk.Application:gtk_main ()
--
Marius Andreiana
Galuna - Solutii Linux in Romania
http://www.galuna.ro
Index: libgnomedb/gnome-db-model.c
===================================================================
RCS file: /cvs/gnome/libgnomedb/libgnomedb/gnome-db-model.c,v
retrieving revision 1.27
diff -u -r1.27 gnome-db-model.c
--- libgnomedb/gnome-db-model.c 10 Mar 2003 00:16:57 -0000 1.27
+++ libgnomedb/gnome-db-model.c 7 Dec 2003 00:37:32 -0000
@@ -85,6 +85,7 @@
{
DataModelInfo *infoa, *infob;
const GdaValue *valuea, *valueb;
+ gchar *stra, *strb;
gint retval = 1;
gtk_tree_model_get (model, itera, 0, &infoa, -1);
@@ -101,35 +102,92 @@
if (!valuea || !valueb)
return 0;
+ /* types of values should be the same, as they are in the same column */
+ g_assert( gda_value_get_type( (GdaValue *) valuea ) == gda_value_get_type( (GdaValue *) valueb ) );
+
/* compare values */
- if (gda_value_isa ((GdaValue *) valuea, GDA_VALUE_TYPE_NULL) &&
- gda_value_isa ((GdaValue *) valueb, GDA_VALUE_TYPE_NULL))
- retval = 0;
- else if (gda_value_isa ((GdaValue *) valuea, GDA_VALUE_TYPE_BIGINT) &&
- gda_value_isa ((GdaValue *) valueb, GDA_VALUE_TYPE_BIGINT)) {
- if (gda_value_get_bigint ((GdaValue *) valuea) >
- gda_value_get_bigint ((GdaValue *) valueb))
- retval = -1;
- }
- else {
- gchar *stra, *strb;
-
- /* data types don't match, so use strings to sort */
- stra = gda_value_stringify ((GdaValue *) valuea);
- strb = gda_value_stringify ((GdaValue *) valueb);
- if (!stra && !strb)
+ /* return equal for NULL, UNKNOWN and BLOB, compare numeric and last fall to string */
+ switch( gda_value_get_type( (GdaValue *) valuea ) ) {
+ case GDA_VALUE_TYPE_NULL:
+ case GDA_VALUE_TYPE_UNKNOWN:
+ case GDA_VALUE_TYPE_BLOB:
retval = 0;
- else if (!stra)
- retval = 1;
- else if (!strb)
+ break;
+ case GDA_VALUE_TYPE_BIGINT:
+ if (gda_value_get_bigint ((GdaValue *) valuea) >
+ gda_value_get_bigint ((GdaValue *) valueb))
retval = -1;
- else
- retval = strcmp (stra, strb);
-
- g_free (stra);
- g_free (strb);
+ break;
+ case GDA_VALUE_TYPE_BIGUINT:
+ if (gda_value_get_biguint ((GdaValue *) valuea) >
+ gda_value_get_biguint ((GdaValue *) valueb))
+ retval = -1;
+ break;
+ case GDA_VALUE_TYPE_INTEGER:
+ if (gda_value_get_integer ((GdaValue *) valuea) >
+ gda_value_get_integer ((GdaValue *) valueb))
+ retval = -1;
+ break;
+ case GDA_VALUE_TYPE_MONEY:
+ if (gda_value_get_money ((GdaValue *) valuea) >
+ gda_value_get_money ((GdaValue *) valueb))
+ retval = -1;
+ break;
+ case GDA_VALUE_TYPE_NUMERIC:
+ case GDA_VALUE_TYPE_DOUBLE:
+ if (gda_value_get_double ((GdaValue *) valuea) >
+ gda_value_get_double ((GdaValue *) valueb))
+ retval = -1;
+ break;
+ case GDA_VALUE_TYPE_SINGLE:
+ if (gda_value_get_single ((GdaValue *) valuea) >
+ gda_value_get_single ((GdaValue *) valueb))
+ retval = -1;
+ break;
+ case GDA_VALUE_TYPE_SMALLINT:
+ if (gda_value_get_smallint ((GdaValue *) valuea) >
+ gda_value_get_smallint ((GdaValue *) valueb))
+ retval = -1;
+ break;
+ case GDA_VALUE_TYPE_SMALLUINT:
+ if (gda_value_get_smalluint ((GdaValue *) valuea) >
+ gda_value_get_smalluint ((GdaValue *) valueb))
+ retval = -1;
+ break;
+ case GDA_VALUE_TYPE_TINYINT:
+ if (gda_value_get_tinyint ((GdaValue *) valuea) >
+ gda_value_get_tinyint ((GdaValue *) valueb))
+ retval = -1;
+ break;
+ case GDA_VALUE_TYPE_TINYUINT:
+ if (gda_value_get_tinyuint ((GdaValue *) valuea) >
+ gda_value_get_tinyuint ((GdaValue *) valueb))
+ retval = -1;
+ break;
+ case GDA_VALUE_TYPE_UINTEGER:
+ if (gda_value_get_uinteger ((GdaValue *) valuea) >
+ gda_value_get_uinteger ((GdaValue *) valueb))
+ retval = -1;
+ break;
+ default:
+ /* data types don't match, so use strings to sort */
+ /* note: maybe dates should be converted to unix time and compared as integers? */
+ stra = gda_value_stringify ((GdaValue *) valuea);
+ strb = gda_value_stringify ((GdaValue *) valueb);
+ if (!stra && !strb)
+ retval = 0;
+ else if (!stra)
+ retval = 1;
+ else if (!strb)
+ retval = -1;
+ else
+ retval = strcmp (stra, strb);
+
+ g_free (stra);
+ g_free (strb);
+ break;
}
-
+
return retval;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]