[tracker/miner-web-review: 2/74] SPARQL: Report use of undefined variables
- From: Adrien Bustany <abustany src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/miner-web-review: 2/74] SPARQL: Report use of undefined variables
- Date: Mon, 1 Mar 2010 15:32:22 +0000 (UTC)
commit 218b5a4bdc940593e789b9fda1d0e7826c3d61ef
Author: Jürg Billeter <j bitron ch>
Date: Wed Feb 24 11:50:55 2010 +0100
SPARQL: Report use of undefined variables
In certain situations, use of undefined variables could lead to crashes.
Fixes GB#610882.
src/libtracker-data/tracker-sparql-query.vala | 16 +++++++++++++++-
1 files changed, 15 insertions(+), 1 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-query.vala b/src/libtracker-data/tracker-sparql-query.vala
index a53e5ec..03b01c7 100644
--- a/src/libtracker-data/tracker-sparql-query.vala
+++ b/src/libtracker-data/tracker-sparql-query.vala
@@ -671,6 +671,10 @@ public class Tracker.SparqlQuery : Object {
type = translate_expression (sql);
// we need variable name in case of compositional subqueries
variable = get_variable (get_last_string ().substring (1));
+
+ if (variable.binding == null) {
+ throw get_error ("use of undefined variable `%s'".printf (variable.name));
+ }
} else {
type = translate_expression (sql);
}
@@ -767,6 +771,13 @@ public class Tracker.SparqlQuery : Object {
var after_where = get_location ();
set_location (select_variables_location);
+ // report use of undefined variables
+ foreach (var variable in var_map.get_values ()) {
+ if (variable.binding == null) {
+ throw get_error ("use of undefined variable `%s'".printf (variable.name));
+ }
+ }
+
bool first = true;
if (accept (SparqlTokenType.STAR)) {
foreach (var variable in var_map.get_values ()) {
@@ -1012,6 +1023,9 @@ public class Tracker.SparqlQuery : Object {
first = false;
}
+ if (variable.binding == null) {
+ throw get_error ("use of undefined variable `%s'".printf (variable.name));
+ }
append_expression_as_string (sql, variable.sql_expression, variable.binding.data_type);
}
@@ -2174,7 +2188,7 @@ public class Tracker.SparqlQuery : Object {
next ();
result = var_value_map.lookup (get_last_string ().substring (1));
if (result == null) {
- throw get_error ("undefined variable");
+ throw get_error ("use of undefined variable `%s'".printf (get_last_string ().substring (1)));
}
} else if (current () == SparqlTokenType.IRI_REF) {
next ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]