summaryrefslogtreecommitdiff
path: root/db.c
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-04-25 17:28:49 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2010-04-25 17:28:49 +0200
commit0d4b1caee4135b6e0dcd2aa3bd6ce2387c1c3773 (patch)
tree5fc5c7dbed604437b34f21d90e8aaac5139c08e4 /db.c
parente52bbb2a3d17cc12cab75deba113d3075b62337e (diff)
Added a tree model to display tags in tree structures.
Adding children to tags is not yet implemented.
Diffstat (limited to 'db.c')
-rw-r--r--db.c73
1 files changed, 72 insertions, 1 deletions
diff --git a/db.c b/db.c
index e6f0368..935e9c1 100644
--- a/db.c
+++ b/db.c
@@ -354,7 +354,7 @@ int db_get_wall_tags(sqlite_uint64 wallid, GArray **array) {
sqlite3_stmt *stmt;
int rc;
- rc = sqlite3_prepare_v2(db, "SELECT t.id, t.name FROM tag t JOIN walltags w ON (w.tagid = t.id AND w.wallid = ?)", -1, &stmt, NULL);
+ rc = sqlite3_prepare_v2(db, "SELECT t.id, t.name, t.parent FROM tag t JOIN walltags w ON (w.tagid = t.id AND w.wallid = ?)", -1, &stmt, NULL);
if(rc != SQLITE_OK) {
return 0;
@@ -369,6 +369,7 @@ int db_get_wall_tags(sqlite_uint64 wallid, GArray **array) {
*array = g_array_new(FALSE, FALSE, sizeof(struct tag_t));
while((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
temp.id = sqlite3_column_int64(stmt, 0);
+ temp.parent = sqlite3_column_int64(stmt, 2);
temp.name = g_strdup((const gchar*)sqlite3_column_text(stmt, 1));
g_array_append_val(*array, temp);
}
@@ -630,6 +631,76 @@ int db_get_tags_all(GArray **array) {
return 1;
}
+int db_get_top_level_tags(GArray **array) {
+ struct tag_t temp, *temp2;
+ sqlite3_stmt *stmt;
+ int rc;
+
+ rc = sqlite3_prepare_v2(db, "SELECT id, name, parent FROM tag WHERE parent IS NULL ORDER BY name", -1, &stmt, NULL);
+ if(rc != SQLITE_OK) {
+ return 0;
+ }
+
+ *array = g_array_new(FALSE, FALSE, sizeof(struct tag_t));
+ while((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
+ temp.name = g_strdup((const gchar*)sqlite3_column_text(stmt, 1));
+ temp.id = sqlite3_column_int64(stmt, 0);
+ temp.parent = sqlite3_column_int64(stmt, 2);
+ 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 tag_t, i);
+ g_free(temp2->name);
+ }
+ g_array_free(*array, TRUE);
+ return 0;
+ }
+
+ return 1;
+}
+
+int db_get_tags(GArray **array, sqlite3_uint64 parent) {
+ struct tag_t temp, *temp2;
+ sqlite3_stmt *stmt;
+ int rc;
+
+ rc = sqlite3_prepare_v2(db, "SELECT id, name, parent FROM tag WHERE parent = ? ORDER BY name", -1, &stmt, NULL);
+ if(rc != SQLITE_OK) {
+ return 0;
+ }
+
+ rc = sqlite3_bind_int64(stmt, 1, parent);
+ if(rc != SQLITE_OK) {
+ sqlite3_finalize(stmt);
+ return 0;
+ }
+
+ *array = g_array_new(FALSE, FALSE, sizeof(struct tag_t));
+ while((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
+ temp.name = g_strdup((const gchar*)sqlite3_column_text(stmt, 1));
+ temp.id = sqlite3_column_int64(stmt, 0);
+ temp.parent = sqlite3_column_int64(stmt, 2);
+ 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 tag_t, i);
+ g_free(temp2->name);
+ }
+ g_array_free(*array, TRUE);
+ return 0;
+ }
+
+ return 1;
+}
+
int db_add_wall_tag(sqlite_uint64 wallid, sqlite_uint64 tagid) {
sqlite3_stmt *stmt;
int rc;