[tracker/harmattan-pre-signal-updates: 1317/1380] libtracker-data: Fix variable name support



commit c6e8d704dd224d5bb31eea5d96c946164f6c484b
Author: Jürg Billeter <j bitron ch>
Date:   Fri Sep 10 12:35:15 2010 +0200

    libtracker-data: Fix variable name support

 src/libtracker-data/tracker-db-interface-sqlite.c  |    9 +--------
 src/libtracker-data/tracker-sparql-expression.vala |   13 +++++++++++--
 src/libtracker-data/tracker-sparql-pattern.vala    |    9 ++++-----
 3 files changed, 16 insertions(+), 15 deletions(-)
---
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c b/src/libtracker-data/tracker-db-interface-sqlite.c
index 4776c57..92f9e68 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -1432,14 +1432,7 @@ tracker_db_cursor_get_variable_names (TrackerDBCursor *cursor)
 const gchar*
 tracker_db_cursor_get_variable_name (TrackerDBCursor *cursor, guint column)
 {
-	const gchar **variable_names;
-	gint n_columns = sqlite3_column_count (cursor->stmt);
-
-	g_return_val_if_fail (column < n_columns, NULL);
-
-	variable_names = tracker_db_cursor_get_variable_names (cursor);
-
-	return variable_names[column];
+	return sqlite3_column_name (cursor->stmt, column);
 }
 
 const gchar*
diff --git a/src/libtracker-data/tracker-sparql-expression.vala b/src/libtracker-data/tracker-sparql-expression.vala
index 064217b..81843fe 100644
--- a/src/libtracker-data/tracker-sparql-expression.vala
+++ b/src/libtracker-data/tracker-sparql-expression.vala
@@ -116,7 +116,7 @@ class Tracker.Sparql.Expression : Object {
 		}
 	}
 
-	internal PropertyType translate_select_expression (StringBuilder sql, bool subquery) throws Sparql.Error {
+	internal PropertyType translate_select_expression (StringBuilder sql, bool subquery, int variable_index) throws Sparql.Error {
 		Variable variable = null;
 
 		long begin = sql.len;
@@ -149,9 +149,10 @@ class Tracker.Sparql.Expression : Object {
 				expect (SparqlTokenType.VAR);
 				variable = context.get_variable (get_last_string ().substring (1));
 			}
-			sql.append_printf (" AS %s", variable.sql_expression);
 
 			if (subquery) {
+				sql.append_printf (" AS %s", variable.sql_expression);
+
 				var binding = new VariableBinding ();
 				binding.data_type = type;
 				binding.variable = variable;
@@ -166,6 +167,14 @@ class Tracker.Sparql.Expression : Object {
 				state = VariableState.BOUND;
 			}
 			context.select_var_set.insert (variable, state);
+
+			if (!subquery) {
+				sql.append_printf (" AS \"%s\"", variable.name);
+			}
+		} else {
+			if (!subquery) {
+				sql.append_printf (" AS \"var%d\"", variable_index + 1);
+			}
 		}
 
 		return type;
diff --git a/src/libtracker-data/tracker-sparql-pattern.vala b/src/libtracker-data/tracker-sparql-pattern.vala
index aef222f..394dfac 100644
--- a/src/libtracker-data/tracker-sparql-pattern.vala
+++ b/src/libtracker-data/tracker-sparql-pattern.vala
@@ -295,18 +295,17 @@ class Tracker.Sparql.Pattern : Object {
 					sql.append (variable.sql_expression);
 				} else {
 					Expression.append_expression_as_string (sql, variable.sql_expression, variable.binding.data_type);
+					sql.append_printf (" AS \"%s\"", variable.name);
 				}
 				result.types += variable.binding.data_type;
 			}
 		} else {
-			while (true) {
-				if (!first) {
+			for (int i = 0; ; i++) {
+				if (i > 0) {
 					sql.append (", ");
-				} else {
-					first = false;
 				}
 
-				type = expression.translate_select_expression (sql, subquery);
+				type = expression.translate_select_expression (sql, subquery, i);
 				result.types += type;
 
 				switch (current ()) {



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