added field change and get and updated tests
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 10s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Successful in 15s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Successful in 12s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 10s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Successful in 15s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Successful in 12s
This commit is contained in:
1 parent
27ba0ab45e
commit
56d670c9b6
10 files changed
+225
-69
No files matched your search
@@ -1,9 +1,9 @@
|
||||
#include "user.h"
|
||||
#include "database.h"
|
||||
#include "sql.h"
|
||||
#include "user.h"
|
||||
|
||||
User *db_get_user_by_id(const int id) {
|
||||
User *user = nullptr;
|
||||
User *user = nullptr;
|
||||
pthread_mutex_lock(&db_mutex);
|
||||
if (!db) {
|
||||
fprintf(stderr, "Database not initialized\n");
|
||||
@@ -11,12 +11,11 @@ User *db_get_user_by_id(const int id) {
|
||||
return nullptr;
|
||||
}
|
||||
sqlite3_stmt *stmt;
|
||||
int rc =
|
||||
sqlite3_prepare_v2(db, SELECT_USER_BY_ID_SQL, -1, &stmt, nullptr);
|
||||
int rc = sqlite3_prepare_v2(db, SELECT_USER_BY_ID_SQL, -1, &stmt, nullptr);
|
||||
if (rc != SQLITE_OK) {
|
||||
fprintf(stderr, "Cannot prepare statement: %s\n", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
exit(1);
|
||||
pthread_mutex_unlock(&db_mutex);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sqlite3_bind_int(stmt, 1, id);
|
||||
@@ -36,9 +35,10 @@ User *db_get_user_by_id(const int id) {
|
||||
fprintf(stderr, "Error reading data: %s\n", sqlite3_errmsg(db));
|
||||
free_user(user);
|
||||
sqlite3_finalize(stmt);
|
||||
pthread_mutex_unlock(&db_mutex);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&db_mutex);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user