diff options
Diffstat (limited to 'db.c')
-rw-r--r-- | db.c | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -521,6 +521,47 @@ int db_get_walls_by_tags(GArray *tags, GArray **array) { return 1; } +int db_get_walls_untagged(GArray **array) { + sqlite3_stmt *stmt; + int rc; + struct wallpaper_t temp, *temp2; + + rc = sqlite3_prepare_v2(db, "SELECT w.id, w.filepath, w.date, w.size, w.width, w.height " + "FROM wallpaper w WHERE NOT (SELECT COUNT(*) FROM walltags t WHERE t.wallid = w.id)", + -1, &stmt, NULL); + if(rc != SQLITE_OK) { + return 0; + } + + *array = g_array_new(FALSE, FALSE, sizeof(struct wallpaper_t)); + while((rc = sqlite3_step(stmt)) == SQLITE_ROW) { + temp.filepath = g_strdup((const gchar*)sqlite3_column_text(stmt, 1)); + temp.id = sqlite3_column_int64(stmt, 0); + if(sizeof(time_t) == 8) { + temp.date = sqlite3_column_int64(stmt, 2); + } else { + temp.date = sqlite3_column_int(stmt, 2); + } + temp.size = sqlite3_column_int(stmt, 3); + temp.width = sqlite3_column_int(stmt, 4); + temp.height = sqlite3_column_int(stmt, 5); + g_array_append_val(*array, temp); + } + + sqlite3_finalize(stmt); + + if(rc != SQLITE_DONE) { + for(int i = 0; i < (*array)->len; i++) { + temp2 = &g_array_index(*array, struct wallpaper_t, i); + g_free(temp2->filepath); + } + g_array_free(*array, TRUE); + return 0; + } + + return 1; +} + sqlite_uint64 db_add_tag(const char *name, sqlite_uint64 parent) { sqlite3_stmt *stmt; int rc; |