diff --git a/include/libspm.h b/include/libspm.h index 7e115ec..11dfd6f 100755 --- a/include/libspm.h +++ b/include/libspm.h @@ -48,6 +48,13 @@ struct package }; +//test +int list_installed(); +int count_installed(); +int get_installed(int index); + +//end test + // package info diff --git a/src/list.c b/src/list.c new file mode 100644 index 0000000..1abc204 --- /dev/null +++ b/src/list.c @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include "sqlite3.h" // SQLite database library + +// Include necessary headers +#include "libspm.h" +#include "cutils.h" + +//should probably add there to the header when we are done + +//will print the content of INSTALLED_DB +int list_installed() + { + msg(INFO, "listing installed packages from %s", getenv(INSTALLED_DB)); + if(0 == 1) + { + sqlite3_stmt *stmt; + int rc; + + // Prepare the SQL query + const char *sql = "idfk"; + rc = sqlite3_prepare_v2(getenv(INSTALLED_DB), sql, -1, &stmt, NULL); + if (rc != SQLITE_OK) { + msg(ERROR, "SQL error: %s -- %d", sqlite3_errmsg(INSTALLED_DB), rc); + return 1; + } + + // Bind the value for the parameter in the SQL query + sqlite3_bind_text(stmt, 1, "idk", -1, SQLITE_STATIC); + + // Execute the PRINT statement or smth. + rc = sqlite3_step(stmt); + if (rc != SQLITE_DONE) { + msg(ERROR, "Error executing PRINT statement or smth: %s\n", sqlite3_errmsg(INSTALLED_DB)); + return -1; + } + + // Finalize the statement. + rc = sqlite3_finalize(stmt); + if (rc != SQLITE_OK) { + msg(ERROR, "Error finalizing PRINT statement or smth: %s\n", sqlite3_errmsg(INSTALLED_DB)); + return -1; + } + + return 0; + } + + } + +//will return the ammount of packages installed INSTALLED_DB +int count_installed() + { + int count = 1; + + // do sql magic here + + msg(INFO, "there are %d installed packages", count); + + return count; + } + +//will print the content of INSTALLED_DB at a specific index +int get_installed(int index) + { + int count = 0; + char* out = "test"; + //out = sql magic + + msg(INFO, "%s is installed at %d", out, index); + + return count; + + }