use autoincrement

This commit is contained in:
raxracks 2024-02-29 13:18:52 +00:00
parent af2ebeb43f
commit d647aad6bc

View file

@ -11,11 +11,12 @@ void on_ready(struct discord *client, const struct discord_ready *msg) {
}
void on_message(struct discord *client, const struct discord_message *msg) {
if(msg->type == DISCORD_MESSAGE_REPLY) {
log_info("%s", msg->content);
if(msg->type == DISCORD_MESSAGE_REPLY && msg->content != NULL) {
char buf[1024];
sprintf(buf, "INSERT INTO messages(id, message, reply)"
"VALUES('%" PRIu64 "', '%s', '%s')",
msg->id, msg->referenced_message->content, msg->content);
sprintf(buf, "INSERT INTO messages(message, reply)"
"VALUES('%s', '%s')",
msg->referenced_message->content, msg->content);
char* error;
if(sqlite3_exec(db, buf, NULL, NULL, &error)) {
@ -30,7 +31,7 @@ int main(void) {
char* error;
if(sqlite3_exec(db,
"CREATE TABLE IF NOT EXISTS messages("
"id TEXT PRIMARY KEY,"
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
"message TEXT NOT NULL,"
"reply TEXT NOT NULL"
");", NULL, NULL, &error)) {