[tracker] SPARQL: Improve predicate variable support
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] SPARQL: Improve predicate variable support
- Date: Wed, 29 Dec 2010 16:50:32 +0000 (UTC)
commit 960a5faf18a3f2a87fa494880d9918731eb48326
Author: Jürg Billeter <j bitron ch>
Date: Wed Dec 29 17:28:50 2010 +0100
SPARQL: Improve predicate variable support
This allows use of object from predicate variable pattern as subject in
other patterns.
Fixes NB#212736.
src/libtracker-data/tracker-sparql-expression.vala | 1 -
src/libtracker-data/tracker-sparql-pattern.vala | 19 +++++++++++++++++--
tests/libtracker-data/aggregates/aggregate-1.out | 2 +-
.../aggregates/aggregate-distinct-1.out | 2 +-
4 files changed, 19 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-expression.vala b/src/libtracker-data/tracker-sparql-expression.vala
index 49b49e5..824495b 100644
--- a/src/libtracker-data/tracker-sparql-expression.vala
+++ b/src/libtracker-data/tracker-sparql-expression.vala
@@ -246,7 +246,6 @@ class Tracker.Sparql.Expression : Object {
static void convert_expression_to_string (StringBuilder sql, PropertyType type, long begin) {
switch (type) {
case PropertyType.STRING:
- case PropertyType.INTEGER:
// nothing to convert
break;
case PropertyType.RESOURCE:
diff --git a/src/libtracker-data/tracker-sparql-pattern.vala b/src/libtracker-data/tracker-sparql-pattern.vala
index da907ab..9080678 100644
--- a/src/libtracker-data/tracker-sparql-pattern.vala
+++ b/src/libtracker-data/tracker-sparql-pattern.vala
@@ -659,6 +659,7 @@ class Tracker.Sparql.Pattern : Object {
foreach (var variable in triple_context.variables) {
bool maybe_null = true;
bool in_simple_optional = false;
+ PropertyType last_type = PropertyType.UNKNOWN;
string last_name = null;
foreach (VariableBinding binding in triple_context.var_bindings.lookup (variable).list) {
string name;
@@ -669,6 +670,7 @@ class Tracker.Sparql.Pattern : Object {
// always first in loop as variable is required to be unbound
name = variable.sql_expression;
}
+ var type = binding.data_type;
if (last_name != null) {
if (!first_where) {
sql.append (" AND ");
@@ -676,11 +678,23 @@ class Tracker.Sparql.Pattern : Object {
sql.append (" WHERE ");
first_where = false;
}
- sql.append (last_name);
+
+ if (last_type == PropertyType.STRING && type == PropertyType.RESOURCE) {
+ sql.append_printf ("(SELECT ID FROM Resource WHERE Uri = %s)", last_name);
+ } else {
+ sql.append (last_name);
+ }
+
sql.append (" = ");
- sql.append (name);
+
+ if (last_type == PropertyType.RESOURCE && type == PropertyType.STRING) {
+ sql.append_printf ("(SELECT ID FROM Resource WHERE Uri = %s)", name);
+ } else {
+ sql.append (name);
+ }
}
last_name = name;
+ last_type = type;
if (!binding.maybe_null) {
maybe_null = false;
}
@@ -1409,6 +1423,7 @@ class Tracker.Sparql.Pattern : Object {
}
} else {
// variable as predicate
+ binding.data_type = PropertyType.STRING;
binding.sql_db_column_name = "object";
binding.maybe_null = true;
}
diff --git a/tests/libtracker-data/aggregates/aggregate-1.out b/tests/libtracker-data/aggregates/aggregate-1.out
index 702d22b..8ea62e7 100644
--- a/tests/libtracker-data/aggregates/aggregate-1.out
+++ b/tests/libtracker-data/aggregates/aggregate-1.out
@@ -1 +1 @@
-"9" "3.333333" "5" "1"
+"9" "3.33333333333333" "5" "1"
diff --git a/tests/libtracker-data/aggregates/aggregate-distinct-1.out b/tests/libtracker-data/aggregates/aggregate-distinct-1.out
index 5d49fe0..e5cb99d 100644
--- a/tests/libtracker-data/aggregates/aggregate-distinct-1.out
+++ b/tests/libtracker-data/aggregates/aggregate-distinct-1.out
@@ -1 +1 @@
-"3.333333" "4.000000"
+"3.33333333333333" "4.0"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]