38 lines
844 B
C
38 lines
844 B
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <sqlite3.h>
|
|
|
|
#include "include/db.h"
|
|
|
|
static int get_num_rows(sqlite3* db)
|
|
{
|
|
int rows = 0;
|
|
|
|
sqlite3_stmt* msg;
|
|
sqlite3_prepare(db, "SELECT * FROM books;", -1, &msg, NULL);
|
|
while (sqlite3_step(msg) == SQLITE_ROW)
|
|
rows++;
|
|
sqlite3_finalize(msg);
|
|
|
|
return rows;
|
|
}
|
|
|
|
void setup_db(sqlite3* db)
|
|
{
|
|
int err;
|
|
char* err_buf = 0;
|
|
|
|
err = sqlite3_exec(db,
|
|
"CREATE TABLE IF NOT EXISTS books (id UNSIGNED INT PRIMARY KEY, \
|
|
title TEXT, subtitle TEXT, isbn TEXT, authors TEXT, subjects TEXT, \
|
|
langs TEXT, date_added TEXT, date_completed TEXT, pub_date TEXT, \
|
|
image_code TEXT, year_of_pub YEAR, page_len UNSIGNED INT);",
|
|
0, 0, &err_buf);
|
|
if (err != SQLITE_OK) {
|
|
fprintf(stderr, "sqlite3_exec: %s\n", err_buf);
|
|
sqlite3_free(err_buf);
|
|
sqlite3_close(db);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
}
|