#include "actions.h" #include #include "str_fields_check.h" #include #include #include void sqlite_single_statement(sqlite3* db_hand, const std::string& req_statement) { sqlite3_stmt* stmt_obj = NULL; int ret = sqlite3_prepare16_v2(db_hand, req_statement.c_str(), -1, &stmt_obj, NULL); een9_ASSERT(ret == 0, "Can't compile request expression"); struct Guard1{sqlite3_stmt*& r; ~Guard1(){if (sqlite3_finalize(r) != 0) {abort();}}} guard1{stmt_obj}; while (true) { ret = sqlite3_step(stmt_obj); if (ret == SQLITE_DONE) break; if (ret != SQLITE_ROW) { printf("sqlite_row error!!!\n"); printf("%s\n", sqlite3_errmsg(db_hand)); break; } int cc = sqlite3_column_count(stmt_obj); std::vector types(cc); for (int i = 0; i < cc; i++) { types[i] = sqlite3_column_type(stmt_obj, i); } printf("Column: |"); for (int i = 0; i < cc; i++) { switch (types[i]) { #define ccase(tname) case SQLITE_ ## tname: printf(" " #tname " |"); break; ccase(INTEGER) ccase(FLOAT) ccase(BLOB) ccase(NULL) case SQLITE3_TEXT: printf(" TEXT |"); break; } } printf("\n"); } printf("Request steps are done\n"); } void initialize_website(const json::JSON& config, const std::string& root_pw) { printf("Initialization...\n"); een9_ASSERT(check_password(root_pw), "Bad root password"); std::string db_path; int ret; ret = find_db_sqlite_file_path(config, db_path); een9_ASSERT(ret == 0, "Invalid settings[\"database\"] field"); een9_ASSERT(!een9::isRegularFile(db_path), "Database file exists prior to initialization. " "Can't preceed withut harming existing data"); // sqlite3* db_hand = NULL; // ret = sqlite3_open(db_path.c_str(), &db_hand); // een9_ASSERT(ret == 0, "Can't open database"); // struct Guard1{sqlite3*& dhp; ~Guard1(){if (sqlite3_close(dhp) != 0) {abort();}}} guard1{db_hand}; // sqlite_single_statement(db_hand, "CREATE TABLE tb(a INT, b INT);"); // todo: actually write something }