added update user change user and change password
This commit is contained in:
1 parent
33e8bed178
commit
9c3a8d796a
14 files changed
+278
-45
No files matched your search
@@ -0,0 +1,44 @@
|
||||
#include "database.h"
|
||||
#include "sql.h"
|
||||
#include "user.h"
|
||||
|
||||
bool db_delete_user(const int id) {
|
||||
pthread_mutex_lock(&db_mutex);
|
||||
if (!db) {
|
||||
fprintf(stderr, "Database not initialized\n");
|
||||
pthread_mutex_unlock(&db_mutex);
|
||||
return false;
|
||||
}
|
||||
sqlite3_stmt *stmt;
|
||||
int rc;
|
||||
|
||||
rc = sqlite3_prepare_v2(db, DELETE_USER_SQL, -1, &stmt, 0);
|
||||
if (rc != SQLITE_OK) {
|
||||
fprintf(stderr, "Failed to prepare statement: %s\n", sqlite3_errmsg(db));
|
||||
pthread_mutex_unlock(&db_mutex);
|
||||
return false;
|
||||
}
|
||||
|
||||
sqlite3_bind_int(stmt, 1, id);
|
||||
|
||||
rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_DONE) {
|
||||
fprintf(stderr, "Execution failed: %s\n", sqlite3_errmsg(db));
|
||||
sqlite3_finalize(stmt);
|
||||
pthread_mutex_unlock(&db_mutex);
|
||||
return false;
|
||||
}
|
||||
|
||||
int changes = sqlite3_changes(db);
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
if (changes > 0) {
|
||||
printf("User deleted successfully. ID: %d\n", id);
|
||||
} else {
|
||||
printf("No user found with ID: %d\n", id);
|
||||
return false;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&db_mutex);
|
||||
return true;
|
||||
}
|
||||
Reference in new issue
Block a user