[gnome-db]libgda patch



This patch add's get row functionality to GdaRecordset for the C and C++ binding.

It adds

GList * gda_recordset_get_row (GdaRecordset *)
gchar * gda_recordset_get_row_as_string (GdaRecordset *)

and to the C++ binding

GList * GdaRecodset::getRow()
gchar * GdaRecordset::getRowAsString()

It also fixes C++ linkage problems with gda_init() and C++ unresolved symbols for gda_recordset_set_name() and gda_recordset_get_name().

Liam Girdwood
diff -ru libgda-0.2.10/bindings/c++/gdaRecordset.cpp libgda-0.2.10lg/bindings/c++/gdaRecordset.cpp
--- libgda-0.2.10/bindings/c++/gdaRecordset.cpp	Sat Apr 28 22:16:40 2001
+++ libgda-0.2.10lg/bindings/c++/gdaRecordset.cpp	Mon Aug 20 19:32:22 2001
@@ -156,4 +156,15 @@
 	gda_recordset_set_cursortype(_gda_recordset,type);
 }
 
+GList* Recordset::getRow ()
+{
+	return gda_recordset_get_row (_gda_recordset);
+}
+
+gchar* Recordset::getRowAsString ()
+{
+	return gda_recordset_get_row_as_string (_gda_recordset);
+}
+ 
+
 
diff -ru libgda-0.2.10/bindings/c++/gdaRecordset.h libgda-0.2.10lg/bindings/c++/gdaRecordset.h
--- libgda-0.2.10/bindings/c++/gdaRecordset.h	Sat Apr 28 22:16:40 2001
+++ libgda-0.2.10lg/bindings/c++/gdaRecordset.h	Mon Aug 20 19:13:14 2001
@@ -59,6 +59,9 @@
 		void setCursorloc(GDA_CursorLocation loc );
 		GDA_CursorType getCursortype();
 		void setCursortype(GDA_CursorType type);
+		GList* getRow ();
+		gchar* getRowAsString (); 
+
 
 	private:
 		Connection *cnc;
diff -ru libgda-0.2.10/lib/gda-client/gda-recordset.c libgda-0.2.10lg/lib/gda-client/gda-recordset.c
--- libgda-0.2.10/lib/gda-client/gda-recordset.c	Fri May 18 13:13:37 2001
+++ libgda-0.2.10lg/lib/gda-client/gda-recordset.c	Mon Aug 20 19:27:40 2001
@@ -25,6 +25,8 @@
 #  include <gtk/gtksignal.h>
 #endif
 
+#define GDA_ROW_STR_SIZE	4096 /* str size of gda row */
+
 enum {
 	RECORDSET_ERROR,
 	RECORDSET_EOF,
@@ -961,3 +963,113 @@
 	g_return_if_fail(IS_GDA_RECORDSET(rs));
 	rs->cursor_type = type;
 }
+
+/**
+ * gda_recordset_get_row:
+ * @rs: the recordset
+ *
+ * Get the current row from the recordset.
+ * Returns a GList of char *'s.
+ */
+GList *              
+gda_recordset_get_row(GdaRecordset *rs)
+{
+	gint 		rowsize;
+	GdaField* 	rc;
+	GList * 	row;
+	gint 		i;
+	gchar *		string;
+	
+	/* is rs valid */
+	g_return_val_if_fail(IS_GDA_RECORDSET(rs), 0);
+	g_return_val_if_fail(rs->open, 0);
+		
+	if (!rs->current_row && !rs->field_attributes) {
+		g_warning("This shouldn't happen. Inconsistent recordset\n");
+		return 0;
+	}
+	
+	/* construct GList of strings*/
+	row = g_list_alloc ();
+	if (row == 0)
+		return 0;
+	
+	rowsize = rs->field_attributes->_length;
+	
+	for (i = 0; i < rowsize; i++)
+	{
+		rc = gda_recordset_field_idx (rs, i);
+		string = gda_stringify_value (NULL, 0, rc);
+		g_list_append (row, (gpointer) string);
+		gda_field_free (rc);
+	}
+	return row;
+}
+
+
+/**
+ * gda_recordset_get_row_as_string:
+ * @rs: the recordset
+ *
+ * Get the current row as a string.
+ */
+gchar *
+gda_recordset_get_row_as_string(GdaRecordset *rs)
+{
+	gint 		rowsize;
+	GdaField* 	rc;
+	gint 		i;
+	gchar *		row;
+	gchar * 	field;
+	gint 		size = 0;
+	
+	/* is rs valid */
+	g_return_val_if_fail(IS_GDA_RECORDSET(rs), 0);
+	g_return_val_if_fail(rs->open, 0);
+		
+	if (!rs->current_row && !rs->field_attributes) {
+		g_warning("This shouldn't happen. Inconsistent recordset\n");
+		return 0;
+	}
+		
+	/* construct string*/
+	row = (gchar*)malloc (GDA_ROW_STR_SIZE);
+	if (row == 0)
+		return 0;
+	bzero (row, GDA_ROW_STR_SIZE);
+
+	rowsize = rs->field_attributes->_length;
+	
+	for (i = 0; i < rowsize; i++)
+	{
+		rc = gda_recordset_field_idx (rs, i);
+		field = gda_stringify_value (NULL, 0, rc);
+		size += strlen (field) + 2;
+		/* check for string length within limits */
+		if (size > GDA_ROW_STR_SIZE)
+		{
+			/* overflow */
+			free (row);
+			return 0; 
+		}
+		strcat (row, field);
+		strcat (row, ", ");
+		gda_field_free (rc);
+	}
+	
+	/* get rid of last , */
+	*(row + size - 2) = 0;
+	
+	return row;
+}  
+
+/* not implemented */
+void
+gda_recordset_set_name (GdaRecordset* rs, gchar* name)
+{}
+
+/* not implemented */
+void
+gda_recordset_get_name (GdaRecordset* rs, gchar* name)
+{}
+
diff -ru libgda-0.2.10/lib/gda-client/gda-recordset.h libgda-0.2.10lg/lib/gda-client/gda-recordset.h
--- libgda-0.2.10/lib/gda-client/gda-recordset.h	Sat Apr  7 08:49:05 2001
+++ libgda-0.2.10lg/lib/gda-client/gda-recordset.h	Sun Aug 19 20:38:01 2001
@@ -160,6 +160,10 @@
 GDA_CursorType       gda_recordset_get_cursortype (GdaRecordset* rs);
 void                 gda_recordset_set_cursortype (GdaRecordset* rs,
                                                    GDA_CursorType type);
+GList *              gda_recordset_get_row        (GdaRecordset *rs);
+gchar *              gda_recordset_get_row_as_string (GdaRecordset *rs); 
+
+
 
 #ifdef __cplusplus
 }
diff -ru libgda-0.2.10/lib/gda-common/gda-common.h libgda-0.2.10lg/lib/gda-common/gda-common.h
--- libgda-0.2.10/lib/gda-common/gda-common.h	Mon Mar  5 16:59:49 2001
+++ libgda-0.2.10lg/lib/gda-common/gda-common.h	Sun Aug 19 21:14:36 2001
@@ -32,6 +32,14 @@
 #include <gda-xml-file.h>
 #include <gda-xml-database.h>
 
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
 void gda_init (const gchar *app_id, const gchar *version, gint nargs, gchar *args[]);
+
+#if defined(__cplusplus)
+}
+#endif
 
 #endif


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