aboutsummaryrefslogtreecommitdiff
path: root/db.c
diff options
context:
space:
mode:
Diffstat (limited to 'db.c')
-rw-r--r--db.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/db.c b/db.c
index cf75ec6..a6391a6 100644
--- a/db.c
+++ b/db.c
@@ -17,7 +17,7 @@ addatt(struct att *att)
sqlite3_stmt *stmt;
if(sqlite3_prepare(db, "INSERT INTO atts"
- " (post, name, description, mime, data)"
+ " (post, name, desc, mime, data)"
" VALUES (?, ?, ?, ?, ?)",
-1, &stmt, 0) != SQLITE_OK)
goto err;
@@ -30,7 +30,7 @@ addatt(struct att *att)
!= SQLITE_OK)
goto err;
- if(sqlite3_bind_text(stmt, 3, att->description, -1, SQLITE_STATIC)
+ if(sqlite3_bind_text(stmt, 3, att->desc, -1, SQLITE_STATIC)
!= SQLITE_OK)
goto err;
@@ -53,6 +53,44 @@ err:
}
int
+addpost(struct post *post)
+{
+ sqlite3_stmt *stmt;
+
+ if(sqlite3_prepare(db, "INSERT INTO posts"
+ " (parent, user, created, subject, text)"
+ " VALUES (?, ?, ?, ?, ?)",
+ -1, &stmt, 0) != SQLITE_OK)
+ goto err;
+
+ if(sqlite3_bind_int(stmt, 1, post->parent) != SQLITE_OK)
+ goto err;
+
+ if(sqlite3_bind_int(stmt, 2, post->user) != SQLITE_OK)
+ goto err;
+
+ if(sqlite3_bind_int(stmt, 3, post->created) != SQLITE_OK)
+ goto err;
+
+ if(sqlite3_bind_text(stmt, 4, post->subject, -1, SQLITE_STATIC)
+ != SQLITE_OK)
+ goto err;
+
+ if(sqlite3_bind_text(stmt, 5, post->text, -1, SQLITE_STATIC)
+ != SQLITE_OK)
+ goto err;
+
+ if(sqlite3_step(stmt) != SQLITE_DONE)
+ goto err;
+
+ sqlite3_finalize(stmt);
+ return 1;
+err:
+ sqlite3_finalize(stmt);
+ return 0;
+}
+
+int
adduser(struct user *user)
{
sqlite3_stmt *stmt;
@@ -141,7 +179,7 @@ nextatt(sqlite3_stmt *stmt)
att->id = sqlite3_column_int(stmt, 0);
att->post = sqlite3_column_int(stmt, 1);
att->name = strdupn(sqlite3_column_text(stmt, 2));
- att->description = strdupn(sqlite3_column_text(stmt, 3));
+ att->desc = strdupn(sqlite3_column_text(stmt, 3));
att->mime = strdupn(sqlite3_column_text(stmt, 4));
att->bytes = sqlite3_column_bytes(stmt, 5);