From 021f74591d5a99287443517c618c1ed514334986 Mon Sep 17 00:00:00 2001 From: gramanas Date: Thu, 20 Sep 2018 20:09:08 +0300 Subject: Add list tree support --- src/dblayer.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/dblayer.c') diff --git a/src/dblayer.c b/src/dblayer.c index 2e19c5a..f97b70c 100644 --- a/src/dblayer.c +++ b/src/dblayer.c @@ -451,3 +451,49 @@ int list_get_programs(DB *db, cklist *ckl) { return 1; } + +int list_get_path_program_tree(DB *db, cklist *ckl) { + sqlite3_stmt *stmt; + int rc; + + char sql[STR_M]; + dbh_form_query_select_programs(sql); + + rc = sqlite3_prepare_v2(db->ptr, sql, -1, &stmt, 0); + if (rc != SQLITE_OK) { + return -2; + } + + while (sqlite3_step(stmt) == SQLITE_ROW) { + char programName[STR_M]; + strcat(programName, (char *)sqlite3_column_text(stmt, 0)); + strcat(programName, ":"); + list_add(ckl, programName); + sqlite3_stmt *stmt2; + int rc2; + + char sql2[STR_L]; + + char condition[STR_M] = TBL_PROGRAM; + strcat(condition, "."); + strcat(condition, COL_PROGRAM_NAME); + + dbh_form_query_select_from_joined_eq(sql2, COL_CONFIG_PATH, condition); + + rc2 = sqlite3_prepare_v2(db->ptr, sql2, -1, &stmt2, 0); + if (rc2 != SQLITE_OK) { + return -2; + } + + sqlite3_bind_text(stmt2, 1, (char *)sqlite3_column_text(stmt, 0), -1, 0); + while (sqlite3_step(stmt2) == SQLITE_ROW) { + char treePath[STR_L] = "|- "; + strcat(treePath, (char *)sqlite3_column_text(stmt2, 0)); + list_add(ckl, treePath); + } + sqlite3_finalize(stmt2); + } + sqlite3_finalize(stmt); + + return 1; +} -- cgit v1.2.3