Compare commits

..

No commits in common. "7d8c8c6a805c12af0ba48a780a04e141bb98570d" and "5392d6c936d6e7be12b20c71f300beeaea5245f6" have entirely different histories.

3 changed files with 2 additions and 40 deletions

View File

@ -1,7 +1,7 @@
CC=gcc CC=gcc
CFLAGS= -c -g -Wall CFLAGS= -c -g -Wall
LDLIBS = -lcurl -lcjson -lsqlite3 LDLIBS = -lcurl -lcjson
TARGET := isbn-lookup TARGET := isbn-lookup

View File

@ -1,37 +1,3 @@
#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);
}
}

View File

@ -1,5 +1,3 @@
#include <sqlite3.h>
#ifndef DB_H #ifndef DB_H
#define DB_H #define DB_H
@ -7,11 +5,9 @@ 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_code; char *image_url;
int year_of_pub, page_len; int year_of_pub, page_len;
} book_t; } book_t;
void setup_db(sqlite3* db);
#endif #endif