diff options
-rw-r--r-- | db.c | 43 | ||||
-rw-r--r-- | db.h | 2 |
2 files changed, 32 insertions, 13 deletions
@@ -22,6 +22,7 @@ static int db_create_tables() { "create table wallpaper (" " id integer not null," " dirid integer not null," + " date integer not null," " filepath text not null," " size integer not null," " width integer not null," @@ -30,6 +31,7 @@ static int db_create_tables() { ");" "create table tag (" " id integer not null," + " parent integer null," " name varchar(100) not null," " primary key (id)" ");" @@ -221,7 +223,7 @@ sqlite_uint64 db_add_wallpaper(const char *filepath, sqlite_uint64 dirid, int si sqlite3_stmt *stmt; int rc; - rc = sqlite3_prepare_v2(db, "INSERT INTO wallpaper (dirid, filepath, size, width, height) VALUES (?, ?, ?, ?, ?)", -1, &stmt, NULL); + rc = sqlite3_prepare_v2(db, "INSERT INTO wallpaper (dirid, date, filepath, size, width, height) VALUES (?, datetime('now'), ?, ?, ?, ?)", -1, &stmt, NULL); if(rc != SQLITE_OK) { return 0; @@ -318,7 +320,7 @@ int db_get_wallpaper_data(sqlite_uint64 id, struct wallpaper_t *wall) { sqlite3_stmt *stmt; int rc; - rc = sqlite3_prepare_v2(db, "SELECT id, filepath, size, width, height FROM wallpaper WHERE id = ? LIMIT 1", -1, &stmt, NULL); + rc = sqlite3_prepare_v2(db, "SELECT id, filepath, date, size, width, height FROM wallpaper WHERE id = ? LIMIT 1", -1, &stmt, NULL); if(rc != SQLITE_OK) { return 0; } @@ -333,9 +335,14 @@ int db_get_wallpaper_data(sqlite_uint64 id, struct wallpaper_t *wall) { if(rc == SQLITE_ROW) { wall->filepath = g_strdup((const gchar*)sqlite3_column_text(stmt, 1)); wall->id = sqlite3_column_int64(stmt, 0); - wall->size = sqlite3_column_int(stmt, 2); - wall->width = sqlite3_column_int(stmt, 3); - wall->height = sqlite3_column_int(stmt, 4); + if(sizeof(time_t) == 8) { + wall->date = sqlite3_column_int64(stmt, 2); + } else { + wall->date = sqlite3_column_int(stmt, 2); + } + wall->size = sqlite3_column_int(stmt, 3); + wall->width = sqlite3_column_int(stmt, 4); + wall->height = sqlite3_column_int(stmt, 5); } sqlite3_finalize(stmt); @@ -385,7 +392,7 @@ int db_get_wallpapers(sqlite_uint64 dirid, GArray **array) { sqlite3_stmt *stmt; int rc; - rc = sqlite3_prepare_v2(db, "SELECT id, filepath, size, width, height FROM wallpaper WHERE dirid = ? ORDER BY filepath", -1, &stmt, NULL); + rc = sqlite3_prepare_v2(db, "SELECT id, filepath, date, size, width, height FROM wallpaper WHERE dirid = ? ORDER BY filepath", -1, &stmt, NULL); if(rc != SQLITE_OK) { return 0; @@ -401,9 +408,14 @@ int db_get_wallpapers(sqlite_uint64 dirid, GArray **array) { 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); - temp.size = sqlite3_column_int(stmt, 2); - temp.width = sqlite3_column_int(stmt, 3); - temp.height = sqlite3_column_int(stmt, 4); + 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); } @@ -449,7 +461,7 @@ int db_get_walls_by_tags(GArray *tags, GArray **array) { struct wallpaper_t temp, *temp2; join = gen_joinstring(tags->len); - query = g_strdup_printf("SELECT w.id, w.filepath, w.size, w.width, w.height " + query = g_strdup_printf("SELECT w.id, w.filepath, w.date, w.size, w.width, w.height " "FROM wallpaper w JOIN walltags t ON (t.wallid = w.id) WHERE t.tagid IN (%s)", join); g_free(join); @@ -478,9 +490,14 @@ int db_get_walls_by_tags(GArray *tags, GArray **array) { 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); - temp.size = sqlite3_column_int(stmt, 2); - temp.width = sqlite3_column_int(stmt, 3); - temp.height = sqlite3_column_int(stmt, 4); + 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); } @@ -3,6 +3,7 @@ #include <glib.h> #include <sqlite3.h> +#include <time.h> struct directory_t { gchar *name; @@ -12,6 +13,7 @@ struct directory_t { struct wallpaper_t { gchar *filepath; sqlite_uint64 id; + time_t date; int size; int width; int height; |