#pragma once #include "package.h" #include #define HASH_LEN 32 enum lm_query_index { QUERY_CREATE_PACKAGE_TABLE = 0, QUERY_INSERT_PACKAGE_SINGLE = 1, QUERY_SELECT_PACKAGE_SINGLE = 2, QUERY_DELETE_PACKAGE_SINGLE = 3, QUERY_SELECT_PACKAGE_ALL = 4, QUERY_CREATE_FILE_TABLE = 5, QUERY_INSERT_FILE_SINGLE = 6, QUERY_DELETE_FILE_ALL = 7, QUERY_SELECT_FILE_SINGLE = 8, QUERY_SELECT_FILE_ALL = 9, QUERY_UPDATE_FILE_1 = 10, QUERY_UPDATE_FILE_2 = 11, }; enum lm_columns { FILES_COLUMN_PATH = 1, FILES_COLUMN_HASH = 2, FILES_COLUMN_KEEP = 3, FILES_COLUMN_PACKAGE = 4, PACKAGES_COLUMN_NAME = 1, PACKAGES_COLUMN_DESC = 2, PACKAGES_COLUMN_VERSION = 3, PACKAGES_COLUMN_SIZE = 4, PACKAGES_COLUMN_DEPENDS = 5, }; extern char *queries[]; typedef struct lm_database { sqlite3 *packages_db; sqlite3_stmt *packages_st; sqlite3 *files_db; sqlite3_stmt *files_st; lm_pkg_t *pkg; char *dir; } lm_database_t; lm_database_t *lm_database_new(char *path); void lm_database_free(lm_database_t *db); bool lm_database_step_all(sqlite3_stmt *st); bool lm_database_package_find( lm_database_t *db, lm_pkg_t *pkg, char *name); // finds a package by its name, package stored in *pkg bool lm_database_package_next(lm_database_t *db, lm_pkg_t *pkg); // gets the next package in the database bool lm_database_package_add(lm_database_t *db, lm_pkg_t *pkg); // adds a package to the database bool lm_database_package_del(lm_database_t *db, lm_pkg_t *pkg); // delete a package from the database void lm_database_package_next_free( lm_database_t *db, lm_pkg_t *pkg); // frees resources used for lm_database_package_next size_t lm_database_files_count( lm_database_t *db, lm_pkg_t *pkg); // returns the count of files associated with a package bool lm_database_files_contains( lm_database_t *db, lm_pkg_t *pkg, char *path); // check if a package contains the given file bool lm_database_files_matches( lm_database_t *db, char *path, char *hash); // checks if the given file matches with the given hash bool lm_database_files_iskeep(lm_database_t *db, char *path); // checks if the given file is marked as keep bool lm_database_files_next( lm_database_t *db, lm_pkg_t *pkg, char **path, char **hash, bool *keep); // gets the next file of the package bool lm_database_files_add( lm_database_t *db, lm_pkg_t *pkg, char *path, char *hash); // adds a file to the files database bool lm_database_files_del(lm_database_t *db, lm_pkg_t *pkg); // dels all files of belonging to a package void lm_database_files_next_free(lm_database_t *db, lm_pkg_t *pkg, char **path, char **hash, bool *keep); // frees resources used for lm_database_files_next bool lm_database_changes_update(lm_database_t *db, lm_pkg_t *pkg, char *file); char *lm_database_changes_get(lm_database_t *db, lm_pkg_t *pkg); bool lm_database_changes_del(lm_database_t *db, lm_pkg_t *pkg);