[gnome-db][PATCH] gda_recorset_to_array



hi

	Here is a path against gda-recordset.[c-h] that Rodrigo asked me to
send. It implements gda_recordset_to_array, it returns a GPtrArray
containing the hole recordset.

	I don't know if this is the best way to do it, but here it is anyway. 

Diego
Index: gda-recordset.c
===================================================================
RCS file: /cvs/gnome/libgda/lib/gda-client/gda-recordset.c,v
retrieving revision 1.16
diff -u -5 -r1.16 gda-recordset.c
--- gda-recordset.c	2001/07/24 23:50:57	1.16
+++ gda-recordset.c	2001/08/14 20:12:43
@@ -607,10 +607,51 @@
 	}
 	return rc;
 }
 
 /**
+ * gda_recordset_to_array:
+ * @rs: the recordset
+ *
+ * Returns a pointer array containing the hole recordset
+ * without modifying the cursor position.
+ **/
+
+GPtrArray *
+gda_recordset_to_array (GdaRecordset *rs)
+{
+	GDA_CursorLocation location;
+	GPtrArray *array, *row;
+	GdaField *rc;
+	gint fields, i, j;
+	
+	g_return_val_if_fail (GDA_IS_RECORDSET(rs), 0);
+	g_return_val_if_fail (rs->open, 0);
+	
+	location = gda_recordset_get_cursorloc (rs);
+	gda_recordset_move_first(rs);
+	fields = rs->field_attributes->_length;
+
+	array = g_ptr_array_new();
+
+	for (i = 0; i < rs->affected_rows; i++) {
+		row = g_ptr_array_new(); 
+
+		for (j = 0; j < fields; j++) {
+			rc = gda_recordset_field_idx(rs, j);
+			g_ptr_array_add(row, rc);
+		}
+		
+		g_ptr_array_add(array, row);
+	}
+
+	gda_recordset_set_cursorloc (rs, location);
+	
+	return array;
+}
+
+/**
  * gda_recordset_field_name:
  * @rs: the recordset
  * @idx: the name of the field in the current row
  *
  * Returns a pointer to the field with the name  @name of
Index: gda-recordset.h
===================================================================
RCS file: /cvs/gnome/libgda/lib/gda-client/gda-recordset.h,v
retrieving revision 1.12
diff -u -5 -r1.12 gda-recordset.h
--- gda-recordset.h	2001/07/22 23:59:22	1.12
+++ gda-recordset.h	2001/08/14 20:12:43
@@ -95,10 +95,11 @@
 void gda_recordset_set_name (GdaRecordset * rs, gchar * name);
 void gda_recordset_get_name (GdaRecordset * rs, gchar * name);
 void gda_recordset_close (GdaRecordset * rs);
 GdaField *gda_recordset_field_name (GdaRecordset * rs, gchar * name);
 GdaField *gda_recordset_field_idx (GdaRecordset * rs, gint idx);
+GPtrArray *gda_recordset_to_array (GdaRecordset * rs);
 gboolean gda_recordset_bof (GdaRecordset * rs);
 gboolean gda_recordset_eof (GdaRecordset * rs);
 gulong gda_recordset_move (GdaRecordset * rs,
 			   gint count, gpointer bookmark);
 gulong gda_recordset_move_first (GdaRecordset * rs);


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