use sqlite3_mprintf and %q

This commit is contained in:
raxracks 2024-02-29 22:45:11 +00:00
parent 84c89564a0
commit 6a70d74ff3

View file

@ -12,13 +12,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 && msg->content != NULL) {
char buf[1024];
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)) {
if(sqlite3_exec(db, sqlite3_mprintf(
"INSERT INTO messages(message, reply)"
"VALUES('%q', '%q')",
msg->referenced_message->content, msg->content),
NULL, NULL, &error)) {
log_error(error);
}
}