[tracker/wip/garnacho/sparql1.1: 21/23] libtracker-data: Add support for MD5/SHA1/256/512 builtin functions



commit 8e80adeea0b60bea1d66729d3e726e70149f3e1a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jul 30 00:08:38 2015 +0200

    libtracker-data: Add support for MD5/SHA1/256/512 builtin functions
    
    These functions are defined in Sparql 1.1 query language recommendation,
    http://www.w3.org/TR/sparql11-query/#func-md5
    http://www.w3.org/TR/sparql11-query/#func-sha1
    http://www.w3.org/TR/sparql11-query/#func-sha256
    http://www.w3.org/TR/sparql11-query/#func-sha512

 src/libtracker-data/tracker-sparql-expression.vala |   24 +++++++++++++++++
 src/libtracker-data/tracker-sparql-scanner.vala    |   27 ++++++++++++++++++++
 2 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-data/tracker-sparql-expression.vala 
b/src/libtracker-data/tracker-sparql-expression.vala
index 95c7246..9d33a38 100644
--- a/src/libtracker-data/tracker-sparql-expression.vala
+++ b/src/libtracker-data/tracker-sparql-expression.vala
@@ -1391,6 +1391,30 @@ class Tracker.Sparql.Expression : Object {
                        var result = translate_function (sql, FN_NS + "year-from-dateTime");
                        expect (SparqlTokenType.CLOSE_PARENS);
                        return result;
+               case SparqlTokenType.MD5:
+                       next ();
+                       sql.append ("SparqlChecksum(");
+                       type = translate_aggregate_expression (sql);
+                       sql.append (", \"md5\")");
+                       return type;
+               case SparqlTokenType.SHA1:
+                       next ();
+                       sql.append ("SparqlChecksum(");
+                       type = translate_aggregate_expression (sql);
+                       sql.append (", \"sha1\")");
+                       return type;
+               case SparqlTokenType.SHA256:
+                       next ();
+                       sql.append ("SparqlChecksum(");
+                       type = translate_aggregate_expression (sql);
+                       sql.append (", \"sha256\")");
+                       return type;
+               case SparqlTokenType.SHA512:
+                       next ();
+                       sql.append ("SparqlChecksum(");
+                       type = translate_aggregate_expression (sql);
+                       sql.append (", \"sha512\")");
+                       return type;
                case SparqlTokenType.GROUP_CONCAT:
                        next ();
                        sql.append ("GROUP_CONCAT(");
diff --git a/src/libtracker-data/tracker-sparql-scanner.vala b/src/libtracker-data/tracker-sparql-scanner.vala
index 3a1c126..f23ba0a 100644
--- a/src/libtracker-data/tracker-sparql-scanner.vala
+++ b/src/libtracker-data/tracker-sparql-scanner.vala
@@ -117,6 +117,10 @@ public class Tracker.SparqlScanner : Object {
                                case 'a':
                                        if (matches (begin, "MAX")) return SparqlTokenType.MAX;
                                        break;
+                               case 'D':
+                               case 'd':
+                                       if (matches (begin, "MD5")) return SparqlTokenType.MD5;
+                                       break;
                                case 'I':
                                case 'i':
                                        if (matches (begin, "MIN")) return SparqlTokenType.MIN;
@@ -198,6 +202,10 @@ public class Tracker.SparqlScanner : Object {
                        case 'r':
                                if (matches (begin, "RAND")) return SparqlTokenType.RAND;
                                break;
+                       case 'S':
+                       case 's':
+                               if (matches (begin, "SHA1")) return SparqlTokenType.SHA1;
+                               break;
                        case 'T':
                        case 't':
                                if (matches (begin, "TRUE")) return SparqlTokenType.TRUE;
@@ -380,6 +388,17 @@ public class Tracker.SparqlScanner : Object {
                                case 'u':
                                        if (matches (begin, "SUBSTR")) return SparqlTokenType.SUBSTR;
                                        break;
+                               case 'H':
+                               case 'h':
+                                       switch (begin[3]) {
+                                       case '2':
+                                               if (matches (begin, "SHA256")) return SparqlTokenType.SHA256;
+                                               break;
+                                       case '5':
+                                               if (matches (begin, "SHA512")) return SparqlTokenType.SHA512;
+                                               break;
+                                       }
+                                       break;
                                }
                                break;
                        }
@@ -1054,6 +1073,7 @@ public enum Tracker.SparqlTokenType {
        LCASE,
        LIMIT,
        MAX,
+       MD5,
        MIN,
        MINUS,
        MINUTES,
@@ -1091,6 +1111,9 @@ public enum Tracker.SparqlTokenType {
        SECONDS,
        SELECT,
        SEMICOLON,
+       SHA1,
+       SHA256,
+       SHA512,
        SILENT,
        STAR,
        STR,
@@ -1174,6 +1197,7 @@ public enum Tracker.SparqlTokenType {
                case LCASE: return "`LCASE'";
                case LIMIT: return "`LIMIT'";
                case MAX: return "`MAX'";
+               case MD5: return "`MD5'";
                case MIN: return "`MIN'";
                case MINUS: return "`-'";
                case MINUTES: return "`MINUTES'";
@@ -1210,6 +1234,9 @@ public enum Tracker.SparqlTokenType {
                case SECONDS: return "`SECONDS'";
                case SELECT: return "`SELECT'";
                case SEMICOLON: return "`;'";
+               case SHA1: return "`SHA1'";
+               case SHA256: return "`SHA256'";
+               case SHA512: return "`SHA512'";
                case SILENT: return "`SILENT'";
                case STAR: return "`*'";
                case STR: return "`STR'";


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