2 * Copyright (C) 20010 Nokia Corporation.
4 * Author: Zeeshan Ali <zeenix@gmail.com>
6 * This file is part of Rygel.
8 * Rygel is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * Rygel is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 * Represents Tracker SPARQL Selection query
28 public class Rygel.Tracker.SelectionQuery : Query {
29 public ArrayList<string> variables;
30 public ArrayList<string> filters;
32 public string order_by;
36 public string[,] result;
38 public SelectionQuery (ArrayList<string> variables,
39 QueryTriplets triplets,
40 ArrayList<string>? filters,
41 string? order_by = null,
46 if (filters != null) {
47 this.filters = filters;
49 this.filters = new ArrayList<string> ();
52 this.variables = variables;
53 this.order_by = order_by;
55 this.max_count = max_count;
58 public SelectionQuery.clone (SelectionQuery query) {
59 this (copy_str_list (query.variables),
60 new QueryTriplets.clone (query.triplets),
61 copy_str_list (query.filters),
67 public override async void execute (ResourcesIface resources)
69 var str = this.to_string ();
71 debug ("Executing SPARQL query: %s", str);
73 result = yield resources.sparql_query (str);
76 public override string to_string () {
77 var query = "SELECT ";
79 foreach (var variable in this.variables) {
80 query += " " + variable;
83 query += " WHERE { " + base.to_string ();
85 if (this.filters.size > 0) {
87 for (var i = 0; i < this.filters.size; i++) {
88 query += this.filters[i];
90 if (i < this.filters.size - 1) {
99 if (this.order_by != null) {
100 query += " ORDER BY " + order_by;
103 if (this.offset > 0) {
104 query += " OFFSET " + this.offset.to_string ();
107 if (this.max_count > 0) {
108 query += " LIMIT " + this.max_count.to_string ();
114 private static ArrayList<string> copy_str_list (Gee.List<string> str_list) {
115 var copy = new ArrayList<string> ();
117 copy.add_all (str_list);