setup db function
This commit is contained in:
parent
5392d6c936
commit
5027238879
21
src/db.c
21
src/db.c
@ -1,3 +1,24 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "include/db.h"
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include <sqlite3.h>
|
||||
|
||||
#ifndef DB_H
|
||||
#define DB_H
|
||||
|
||||
@ -5,9 +7,11 @@ typedef struct {
|
||||
char *title, *subtitle, *isbn;
|
||||
char *authors, *subjects, *langs;
|
||||
char *date_added, *pub_date;
|
||||
char *image_url;
|
||||
char *image_code;
|
||||
|
||||
int year_of_pub, page_len;
|
||||
} book_t;
|
||||
|
||||
void setup_db(sqlite3* db);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user