projects
/
cinaest
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
d7b36c8
)
Catalog plugin: use StringBuilder to build SQL query
author
Philipp Zabel
<philipp.zabel@gmail.com>
Thu, 8 Jul 2010 19:34:19 +0000
(21:34 +0200)
committer
Philipp Zabel
<philipp.zabel@gmail.com>
Wed, 14 Jul 2010 21:34:08 +0000
(23:34 +0200)
src/plugins/catalog-sqlite.vala
patch
|
blob
|
history
diff --git
a/src/plugins/catalog-sqlite.vala
b/src/plugins/catalog-sqlite.vala
index
b8d5105
..
be05605
100644
(file)
--- a/
src/plugins/catalog-sqlite.vala
+++ b/
src/plugins/catalog-sqlite.vala
@@
-181,7
+181,12
@@
class CatalogSqlite : Object {
private Cancellable? _cancellable;
public async int query (string table, MovieFilter filter, MovieSource.ReceiveMovieFunction callback, int limit, Cancellable? cancellable) {
private Cancellable? _cancellable;
public async int query (string table, MovieFilter filter, MovieSource.ReceiveMovieFunction callback, int limit, Cancellable? cancellable) {
- var sql = "SELECT Title, Year, Rating, Genres FROM %s".printf (table);
+ var sql = new StringBuilder ();
+ sql.append ("SELECT Title, Year, Rating, Genres");
+ if (table == "Watched")
+ sql.append (", Date");
+ sql.append (" FROM ");
+ sql.append (table);
var sep = " WHERE ";
Statement stmt;
int rc;
var sep = " WHERE ";
Statement stmt;
int rc;
@@
-191,32
+196,39
@@
class CatalogSqlite : Object {
db.progress_handler (1000, progress_handler);
if (filter.title != null && filter.title != "") {
db.progress_handler (1000, progress_handler);
if (filter.title != null && filter.title != "") {
- if ("*" in filter.title)
- sql += sep + "Title GLOB \"%s (*)\"".printf (filter.title);
- else
- sql += sep + "Title LIKE \"%s%%\"".printf (filter.title);
+ if ("*" in filter.title) {
+ sql.append (sep);
+ sql.append_printf ("Title GLOB \"%s\"", filter.title);
+ } else {
+ sql.append (sep);
+ sql.append_printf ("Title LIKE \"%s%%\"", filter.title);
+ }
sep = " AND ";
}
if (filter.year_min > 0) {
sep = " AND ";
}
if (filter.year_min > 0) {
- sql += sep + "Year >= %d".printf (filter.year_min);
+ sql.append (sep);
+ sql.append_printf ("Year >= %d", filter.year_min);
sep = " AND ";
}
if (filter.year_max > 0) {
sep = " AND ";
}
if (filter.year_max > 0) {
- sql += sep + "Year <= %d".printf (filter.year_max);
+ sql.append (sep);
+ sql.append_printf ("Year <= %d", filter.year_max);
sep = " AND ";
}
if (filter.rating_min > 0) {
sep = " AND ";
}
if (filter.rating_min > 0) {
- sql += sep + "Rating >= %d".printf (filter.rating_min);
+ sql.append (sep);
+ sql.append_printf ("Rating >= %d", filter.rating_min);
sep = " AND ";
}
if (filter.genres.field != 0) {
sep = " AND ";
}
if (filter.genres.field != 0) {
- sql += sep + "Genres&%d = %d".printf (filter.genres.field, filter.genres.field);
+ sql.append (sep);
+ sql.append_printf ("Genres&%d = %d", filter.genres.field, filter.genres.field);
}
}
- sql += " LIMIT %d;".printf (limit);
+ sql.append_printf (" LIMIT %d;", limit);
- stdout.printf("SQL: \"%s\"\n", sql);
+ stdout.printf("SQL: \"%s\"\n", sql.str);
- rc = db.prepare_v2 (sql, -1, out stmt);
+ rc = db.prepare_v2 (sql.str, -1, out stmt);
if (rc != Sqlite.OK) {
stderr.printf ("SQL error: %d, %s\n", rc, db.errmsg ());
db.progress_handler (0, null);
if (rc != Sqlite.OK) {
stderr.printf ("SQL error: %d, %s\n", rc, db.errmsg ());
db.progress_handler (0, null);