[libgda/LIBGDA_4.0] SQLite provider: more robust blob handling



commit b58c75268622a15614453b1c97287464fa365968
Author: Vivien Malerba <malerba gnome-db org>
Date:   Mon Sep 14 21:41:15 2009 +0200

    SQLite provider: more robust blob handling

 libgda/sqlite/gda-sqlite-provider.c  |    7 ++++++-
 libgda/sqlite/gda-sqlite-recordset.c |   21 +++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletions(-)
---
diff --git a/libgda/sqlite/gda-sqlite-provider.c b/libgda/sqlite/gda-sqlite-provider.c
index 0103e47..aba7563 100644
--- a/libgda/sqlite/gda-sqlite-provider.c
+++ b/libgda/sqlite/gda-sqlite-provider.c
@@ -1712,7 +1712,12 @@ add_oid_columns (GdaStatement *stmt, GHashTable **out_hash, gint *out_nb_cols_ad
 		/* add to hash table */
 		add_index++;
 		g_hash_table_insert (hash, gda_sql_identifier_remove_quotes (g_strdup (name)),
-				     GINT_TO_POINTER (add_index)); /* ADDED 1 to column number, don't forget to remove 1 when using */
+				     GINT_TO_POINTER (add_index)); /* ADDED 1 to column number,
+								    * don't forget to remove 1 when using */
+		if (target->as)
+			g_hash_table_insert (hash, gda_sql_identifier_remove_quotes (g_strdup (target->table_name)),
+					     GINT_TO_POINTER (add_index)); /* ADDED 1 to column number,
+									    * don't forget to remove 1 when using */
 		nb_cols_added ++;
 	}
 
diff --git a/libgda/sqlite/gda-sqlite-recordset.c b/libgda/sqlite/gda-sqlite-recordset.c
index 55e75b0..bf24f71 100644
--- a/libgda/sqlite/gda-sqlite-recordset.c
+++ b/libgda/sqlite/gda-sqlite-recordset.c
@@ -331,6 +331,27 @@ fetch_next_sqlite_row (GdaSqliteRecordset *model, gboolean do_store, GError **er
 
 			if (type == GDA_TYPE_NULL) {
 				type = fuzzy_get_gtype (cdata, ps, col);
+				if (type == GDA_TYPE_BLOB) {
+					/* extra check: make sure we have a rowid for this blob, or fallback to binary */
+					if (ps->rowid_hash) {
+						gint oidcol = 0;
+						const char *ctable;
+						ctable = sqlite3_column_name (ps->sqlite_stmt, real_col);
+						if (ctable)
+							oidcol = GPOINTER_TO_INT (g_hash_table_lookup (ps->rowid_hash,
+												       ctable));
+						if (oidcol == 0) {
+							ctable = sqlite3_column_table_name (ps->sqlite_stmt, real_col);
+							if (ctable)
+								oidcol = GPOINTER_TO_INT (g_hash_table_lookup (ps->rowid_hash, 
+													       ctable));
+						}
+						if (oidcol == 0)
+							type = GDA_TYPE_BINARY;
+					}
+					else
+						type = GDA_TYPE_BINARY;
+				}
 				if (type != GDA_TYPE_NULL) {
 					GdaColumn *column;
 					



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