diff --git a/slige/runtime/prepare.sql b/slige/runtime/prepare.sql index f8e9899..0422ab9 100644 --- a/slige/runtime/prepare.sql +++ b/slige/runtime/prepare.sql @@ -3,19 +3,19 @@ CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY, email TEXT NOT NULL, password_hash TEXT NOT NULL, - balanceInDkkCent INTEGER NOT NULL + balance_dkk_cent INTEGER NOT NULL ); CREATE TABLE IF NOT EXISTS products ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, - priceInDkkCent INTEGER NOT NULL + price_dkk_cent INTEGER NOT NULL ); CREATE TABLE IF NOT EXISTS product_prices ( id INTEGER PRIMARY KEY, product INTEGER NOT NULL, - priceInDkkCent INTEGER NOT NULL, + price_dkk_cent INTEGER NOT NULL, FOREIGN KEY(product) REFERENCES products(id) ); diff --git a/slige/runtime/src/main.c b/slige/runtime/src/main.c index 03d342c..bf8c7f3 100644 --- a/slige/runtime/src/main.c +++ b/slige/runtime/src/main.c @@ -64,39 +64,36 @@ l0_return: json_value_free(body); } +static inline void insert_test_user(sqlite3* db) +{ + sqlite3_stmt* stmt; + sqlite3_prepare_v2(db, + "INSERT INTO users (email, password_hash, balance_dkk_cent) " + "VALUES (?, ?, ?)", + -1, &stmt, NULL); + + char email[] = "testuser@email.com"; + char password[] = "1234"; + StrHash password_hash = str_hash(password); + char* password_hash_str = str_hash_to_string(password_hash); + + sqlite3_bind_text(stmt, 1, email, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 2, password_hash_str, -1, SQLITE_STATIC); + sqlite3_bind_int(stmt, 3, 123); + + int res = sqlite3_step(stmt); + if (res != SQLITE_DONE) { + fprintf(stderr, "error: could not insert test user: %s\n", + sqlite3_errmsg(db)); + } + + sqlite3_finalize(stmt); +} + HttpServer* server; int main(void) { - - char password[] = "Merc1234"; - - const char* other_password = "Merc1234"; - - { - StrHash password_hash = str_hash(password); - char* password_hash_str = str_hash_to_string(password_hash); - printf("'%s'\n", password_hash_str); - - bool other_is_equal = str_hash_is_equal(password_hash, other_password); - printf("is_equal = %s\n", other_is_equal ? "true" : "false"); - - free(password_hash_str); - } - - { - StrHash password_hash = str_hash(password); - char* password_hash_str = str_hash_to_string(password_hash); - printf("'%s'\n", password_hash_str); - - bool other_is_equal = str_hash_is_equal(password_hash, other_password); - printf("is_equal = %s\n", other_is_equal ? "true" : "false"); - - free(password_hash_str); - } - - return 0; - sqlite3* db; int res = sqlite3_open("database.db", &db); if (res != SQLITE_OK) { @@ -104,6 +101,8 @@ int main(void) return -1; } + insert_test_user(db); + Cx cx = { .number = 1 }; server = http_server_new((HttpServerOpts) { diff --git a/slige/runtime/src/str_util.c b/slige/runtime/src/str_util.c index 0f9e243..8986876 100644 --- a/slige/runtime/src/str_util.c +++ b/slige/runtime/src/str_util.c @@ -48,6 +48,7 @@ char* string_copy(const String* string) copy[string->size] = '\0'; return copy; } + static inline StrHash str_hash_with_salt(const char* str, const uint8_t* salt) { if (strlen(str) >= MAX_HASH_INPUT_LEN - 1) {