mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-27 16:24:07 +02:00
sqlite works
This commit is contained in:
parent
d537e0a709
commit
819cf738dc
@ -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)
|
||||
);
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user