libgda r3300 - in trunk: . providers/postgres tools
- From: vivien svn gnome org
- To: svn-commits-list gnome org
- Subject: libgda r3300 - in trunk: . providers/postgres tools
- Date: Sun, 25 Jan 2009 19:58:35 +0000 (UTC)
Author: vivien
Date: Sun Jan 25 19:58:35 2009
New Revision: 3300
URL: http://svn.gnome.org/viewvc/libgda?rev=3300&view=rev
Log:
2009-01-25 Vivien Malerba <malerba gnome-db org>
* tools/test_blob.sh: new script used to test database provider's blobs
implementations
* providers/postgres/gda-postgres-provider.c: correct a double free problem
and prevent memory leaks in some cases
Added:
trunk/tools/test_blob.sh
Modified:
trunk/ChangeLog
trunk/providers/postgres/gda-postgres-provider.c
Modified: trunk/providers/postgres/gda-postgres-provider.c
==============================================================================
--- trunk/providers/postgres/gda-postgres-provider.c (original)
+++ trunk/providers/postgres/gda-postgres-provider.c Sun Jan 25 19:58:35 2009
@@ -1890,6 +1890,26 @@
}
/*
+ * Free:
+ * - all the *param_values
+ * - param_values
+ * - param_mem
+ *
+ */
+static void
+params_freev (gchar **param_values, gboolean *param_mem, gint size)
+{
+ gint i;
+
+ for (i = 0; i < size; i++) {
+ if (param_values [i] && ! param_mem [i])
+ g_free (param_values [i]);
+ }
+ g_free (param_values);
+ g_free (param_mem);
+}
+
+/*
* Execute statement request
*
* Executes a statement. This method should do the following:
@@ -2021,13 +2041,15 @@
char **param_values = NULL;
int *param_lengths = NULL;
int *param_formats = NULL;
+ gboolean *param_mem = NULL;
gint nb_params;
gboolean transaction_started = FALSE;
nb_params = g_slist_length (_GDA_PSTMT (ps)->param_ids);
- param_values = g_new0 (char *, nb_params + 1);
- param_lengths = g_new0 (int, nb_params + 1);
- param_formats = g_new0 (int, nb_params + 1);
+ param_values = g_new0 (char *, nb_params);
+ param_lengths = g_new0 (int, nb_params);
+ param_formats = g_new0 (int, nb_params);
+ param_mem = g_new0 (gboolean, nb_params);
for (i = 0, list = _GDA_PSTMT (ps)->param_ids; list; list = list->next, i++) {
const gchar *pname = (gchar *) list->data;
@@ -2123,6 +2145,7 @@
param_values [i] = (gchar*) bin->data;
param_lengths [i] = bin->binary_length;
param_formats [i] = 1; /* binary format */
+ param_mem [i] = TRUE; /* don't free later */
}
else if ((G_VALUE_TYPE (value) == G_TYPE_DATE) ||
(G_VALUE_TYPE (value) == GDA_TYPE_TIMESTAMP) ||
@@ -2147,7 +2170,7 @@
if (event) {
gda_connection_add_event (cnc, event);
- g_strfreev (param_values);
+ params_freev (param_values, param_mem, nb_params);
g_free (param_lengths);
g_free (param_formats);
if (transaction_started)
@@ -2188,7 +2211,7 @@
pg_res = PQexecPrepared (cdata->pconn, ps->prep_name, nb_params, (const char * const *) param_values,
param_lengths, param_formats, 0);
- g_strfreev (param_values);
+ params_freev (param_values, param_mem, nb_params);
g_free (param_lengths);
g_free (param_formats);
Added: trunk/tools/test_blob.sh
==============================================================================
--- (empty file)
+++ trunk/tools/test_blob.sh Sun Jan 25 19:58:35 2009
@@ -0,0 +1,67 @@
+#!/bin/sh
+
+#
+# This script tests Blob implementation. It was first designed for PostgreSQL but does not
+# depend on it.
+#
+# It requires:
+# - a DSN named ${prefix}blobs where ${prefix} is set to the database provider being tested later
+# - the DSN must point to a database which at least has the 'blobs' table created as:
+# Postgresql: CREATE TABLE blobs (id int, descr VARCHAR, blob OID);
+# H2: CREATE TABLE blobs (id int, descr VARCHAR, blob BLOB);
+# SQLite: CREATE TABLE blobs (id int, descr string, blob blob);
+# note: the OID type is the data type for blobs for PostgreSQL
+# - it must be run in the tools/ directory of Libgda's sources since it loads the gda-sql.c and gda-sql.ico
+# files.
+#
+# Note: the 'blobs' table's contents will be overriden by the test
+
+prefix=pg
+#prefix=h2
+#prefix=sqlite
+
+rm -f EXPORT_gda_sql_c EXPORT_gda_sql_ico
+./gda-sql-4.0 ${prefix}blobs <<EOF
+delete from blobs;
+.setex bl gda-sql.c
+insert into blobs (id, descr, blob) values (1, 'descr1', ##bl::GdaBlob);
+insert into blobs (id, descr, blob) values (10, 'descr1', ##bl::GdaBlob);
+#select * from blobs;
+.setex bl2 gda-sql.ico
+insert into blobs (id, descr, blob) values (2, 'descr2', ##bl2::GdaBlob);
+.unset
+.setex bl blobs blob id=2
+update blobs set descr='copied from id=2', blob= ##bl::GdaBlob WHERE id=1;
+insert into blobs (id, descr, blob) values (3, 'inserted from id=2', ##bl::GdaBlob);
+#select * from blobs;
+.unset
+.setex bl10 blobs blob id=10
+.export bl10 EXPORT_gda_sql_c
+.export blobs blob id=2 EXPORT_gda_sql_ico
+.export blobs blob id=1 EXPORT_gda_sql_ico1
+EOF
+if test $? != 0
+then
+ echo "ERROR executing script"
+fi
+cmp EXPORT_gda_sql_c gda-sql.c
+if test $? != 0
+then
+ echo "BLOB export failed for gda-sql.c"
+ exit 1
+fi
+cmp EXPORT_gda_sql_ico gda-sql.ico
+if test $? != 0
+then
+ echo "BLOB export failed for gda-sql.ico"
+ exit 1
+fi
+cmp EXPORT_gda_sql_ico1 gda-sql.ico
+if test $? != 0
+then
+ echo "BLOB export failed for gda-sql.ico (ID=1)"
+ exit 1
+fi
+
+rm -f EXPORT_gda_sql_c EXPORT_gda_sql_ico EXPORT_gda_sql_ico1
+echo "Test successfull"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]