rygel-media-export-db-container.vala \
rygel-media-export-sql-factory.vala \
rygel-media-export-media-cache.vala \
+ rygel-media-export-sql-operator.vala \
+ rygel-media-export-sql-function.vala \
rygel-media-export-media-cache-upgrader.vala \
rygel-media-export-metadata-extractor.vala \
rygel-media-export-null-container.vala \
private string? relational_expression_to_sql (RelationalExpression? exp,
GLib.ValueArray args)
throws Error {
- string sql_function = null;
GLib.Value? v = null;
string collate = null;
string column = map_operand_to_column (exp.operand1, out collate);
+ SqlOperator operator;
switch (exp.op) {
case SearchCriteriaOp.EXISTS:
+ string sql_function;
if (exp.operand2 == "true") {
sql_function = "IS NOT NULL AND %s != ''";
} else {
sql_function = "IS NULL OR %s = ''";
}
+ operator = new SqlOperator (sql_function, column);
break;
case SearchCriteriaOp.EQ:
- sql_function = "=";
- v = exp.operand2;
- break;
case SearchCriteriaOp.NEQ:
- sql_function = "!=";
- v = exp.operand2;
- break;
case SearchCriteriaOp.LESS:
- sql_function = "<";
- v = exp.operand2;
- break;
case SearchCriteriaOp.LEQ:
- sql_function = "<=";
- v = exp.operand2;
- break;
case SearchCriteriaOp.GREATER:
- sql_function = ">";
- v = exp.operand2;
- break;
case SearchCriteriaOp.GEQ:
- sql_function = ">=";
v = exp.operand2;
+ operator = new SqlOperator.from_search_criteria_op (
+ exp.op,
+ column,
+ collate);
break;
case SearchCriteriaOp.CONTAINS:
- sql_function = "LIKE";
+ operator = new SqlOperator ("LIKE", column);
v = "%%%s%%".printf (exp.operand2);
break;
case SearchCriteriaOp.DOES_NOT_CONTAIN:
- sql_function = "NOT LIKE";
+ operator = new SqlOperator ("NOT LIKE", column);
v = "%%%s%%".printf (exp.operand2);
break;
case SearchCriteriaOp.DERIVED_FROM:
- sql_function = "LIKE";
- v = "%s%%".printf (exp.operand2);
+ operator = new SqlFunction ("has_prefix", column);
+ v = exp.operand2;
break;
default:
warning ("Unsupported op %d", exp.op);
- break;
+ return null;
}
if (v != null) {
args.append (v);
}
- return "(%s %s ? %s)".printf (column, sql_function, collate);
+ return operator.to_string ();
}
public Gee.List<string> get_meta_data_column_by_filter (
--- /dev/null
+/*
+ * Copyright (C) 2010 Jens Georg <mail@jensge.org>.
+ *
+ * Author: Jens Georg <mail@jensge.org>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+internal class Rygel.MediaExport.SqlFunction : SqlOperator {
+ public SqlFunction (string name, string arg) {
+ base (name, arg);
+ }
+
+ public override string to_string () {
+ return "%s(%s,?)".printf (name, arg);
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2010 Jens Georg <mail@jensge.org>.
+ *
+ * Author: Jens Georg <mail@jensge.org>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using GUPnP;
+
+internal class Rygel.MediaExport.SqlOperator : GLib.Object {
+ protected string name;
+ protected string arg;
+ protected string collate;
+
+ public SqlOperator (string name,
+ string arg,
+ string collate = "") {
+ this.name = name;
+ this.arg = arg;
+ this.collate = collate;
+ }
+
+ public SqlOperator.from_search_criteria_op (SearchCriteriaOp op,
+ string arg,
+ string collate) {
+ string sql = null;
+ switch (op) {
+ case SearchCriteriaOp.EQ:
+ sql = "=";
+ break;
+ case SearchCriteriaOp.NEQ:
+ sql = "!=";
+ break;
+ case SearchCriteriaOp.LESS:
+ sql = "<";
+ break;
+ case SearchCriteriaOp.LEQ:
+ sql = "<=";
+ break;
+ case SearchCriteriaOp.GREATER:
+ sql = ">";
+ break;
+ case SearchCriteriaOp.GEQ:
+ sql = ">=";
+ break;
+ default:
+ assert_not_reached ();
+ }
+
+ this (sql, arg, collate);
+ }
+
+ public virtual string to_string () {
+ return "(%s %s ? %s)".printf (arg, name, collate);
+ }
+}
+
+