Compare commits
3 Commits
5392d6c936
...
7d8c8c6a80
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7d8c8c6a80 | ||
![]() |
66c9c45c93 | ||
![]() |
5027238879 |
2
Makefile
2
Makefile
@ -1,7 +1,7 @@
|
|||||||
CC=gcc
|
CC=gcc
|
||||||
CFLAGS= -c -g -Wall
|
CFLAGS= -c -g -Wall
|
||||||
|
|
||||||
LDLIBS = -lcurl -lcjson
|
LDLIBS = -lcurl -lcjson -lsqlite3
|
||||||
|
|
||||||
TARGET := isbn-lookup
|
TARGET := isbn-lookup
|
||||||
|
|
||||||
|
34
src/db.c
34
src/db.c
@ -1,3 +1,37 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sqlite3.h>
|
||||||
|
|
||||||
#include "include/db.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#include <sqlite3.h>
|
||||||
|
|
||||||
#ifndef DB_H
|
#ifndef DB_H
|
||||||
#define DB_H
|
#define DB_H
|
||||||
|
|
||||||
@ -5,9 +7,11 @@ typedef struct {
|
|||||||
char *title, *subtitle, *isbn;
|
char *title, *subtitle, *isbn;
|
||||||
char *authors, *subjects, *langs;
|
char *authors, *subjects, *langs;
|
||||||
char *date_added, *pub_date;
|
char *date_added, *pub_date;
|
||||||
char *image_url;
|
char *image_code;
|
||||||
|
|
||||||
int year_of_pub, page_len;
|
int year_of_pub, page_len;
|
||||||
} book_t;
|
} book_t;
|
||||||
|
|
||||||
|
void setup_db(sqlite3* db);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user