~ubuntu-branches/ubuntu/oneiric/tracker/oneiric

« back to all changes in this revision

Viewing changes to src/libtracker-data/tracker-sparql-expression.vala

  • Committer: Package Import Robot
  • Author(s): Michael Biebl
  • Date: 2011-08-26 00:26:14 UTC
  • mfrom: (4.3.17 sid)
  • Revision ID: package-import@ubuntu.com-20110826002614-4qjfs9jhh5gs4p13
Tags: 0.10.24-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
        }
72
72
 
73
73
        bool maybe_numeric (PropertyType type) {
74
 
                return (type == PropertyType.INTEGER || type == PropertyType.DOUBLE || type == PropertyType.DATETIME || type == PropertyType.UNKNOWN);
 
74
                return (type == PropertyType.INTEGER || type == PropertyType.DOUBLE || type == PropertyType.DATE || type == PropertyType.DATETIME || type == PropertyType.UNKNOWN);
75
75
        }
76
76
 
77
77
        void append_collate (StringBuilder sql) {
287
287
                        sql.insert (begin, "CASE ");
288
288
                        sql.append (" WHEN 1 THEN 'true' WHEN 0 THEN 'false' ELSE NULL END");
289
289
                        break;
 
290
                case PropertyType.DATE:
 
291
                        // ISO 8601 format
 
292
                        sql.insert (begin, "strftime (\"%Y-%m-%d\", ");
 
293
                        sql.append (", \"unixepoch\")");
 
294
                        break;
290
295
                case PropertyType.DATETIME:
291
296
                        // ISO 8601 format
292
297
                        sql.insert (begin, "strftime (\"%Y-%m-%dT%H:%M:%SZ\", ");
965
970
                        case PropertyType.INTEGER:
966
971
                        case PropertyType.BOOLEAN:
967
972
                        case PropertyType.DOUBLE:
 
973
                        case PropertyType.DATE:
968
974
                        case PropertyType.DATETIME:
969
975
                                if (query.no_cache) {
970
976
                                        sql.append (escape_sql_string_literal (literal));
1034
1040
                case SparqlTokenType.BOUND:
1035
1041
                        translate_bound_call (sql);
1036
1042
                        return PropertyType.BOOLEAN;
 
1043
                case SparqlTokenType.COALESCE:
 
1044
                        next ();
 
1045
                        expect (SparqlTokenType.OPEN_PARENS);
 
1046
                        var result = translate_function (sql, TRACKER_NS + "coalesce");
 
1047
                        expect (SparqlTokenType.CLOSE_PARENS);
 
1048
                        return result;
1037
1049
                case SparqlTokenType.IF:
1038
1050
                        return translate_if_call (sql);
1039
1051
                case SparqlTokenType.SAMETERM:
1224
1236
                                // trigger string => datetime conversion
1225
1237
                                query.bindings.last ().data.data_type = PropertyType.DATETIME;
1226
1238
                        }
 
1239
                } else if ((op1type == PropertyType.DATE && op2type == PropertyType.STRING)
 
1240
                           || (op1type == PropertyType.STRING && op2type == PropertyType.DATE)) {
 
1241
                        // TODO: improve performance (linked list)
 
1242
                        if (query.bindings.length () == n_bindings + 1) {
 
1243
                                // trigger string => date conversion
 
1244
                                query.bindings.last ().data.data_type = PropertyType.DATE;
 
1245
                        }
1227
1246
                }
1228
1247
                return PropertyType.BOOLEAN;
1229
1248
        }