Fix bugs: null, dates
This commit is contained in:
parent
6e6a9f310e
commit
0ac0010532
30
db.c
30
db.c
@ -40,7 +40,7 @@ enum stmt {
|
||||
static const char *const stmts[STMT__MAX] = {
|
||||
/* STMT_BOOK */
|
||||
"SELECT books.id AS id,title, series_index, series.name AS series_name, series.id AS series_id, \
|
||||
timestamp,pubdate, isbn,lccn,path,uuid,has_cover, \
|
||||
strftime('%s', timestamp), strftime('%Y', pubdate), isbn,lccn,path,uuid,has_cover, \
|
||||
languages.lang_code,format,uncompressed_size,data.name AS data_name, publishers.name AS pubname FROM books \
|
||||
LEFT OUTER JOIN books_languages_link ON books_languages_link.book = books.id \
|
||||
LEFT OUTER JOIN languages ON languages.id = books_languages_link.lang_code \
|
||||
@ -75,6 +75,14 @@ struct bookauth {
|
||||
struct bookauth *p;
|
||||
};
|
||||
|
||||
static char *
|
||||
strornull(struct ksqlstmt *stmt, int col)
|
||||
{
|
||||
if (ksql_stmt_isnull(stmt, col))
|
||||
return(NULL);
|
||||
return(kstrdup(ksql_stmt_str(stmt, col)));
|
||||
}
|
||||
|
||||
static void
|
||||
db_series_unfill(Series *p)
|
||||
{
|
||||
@ -269,7 +277,6 @@ db_book_load(struct kreq *r, int64_t id)
|
||||
struct bookauth *item = NULL;
|
||||
BookFull *book;
|
||||
|
||||
fputs(stmts[STMT_BOOK], stderr);
|
||||
ksql_stmt_alloc(r->arg, &stmt,
|
||||
stmts[STMT_BOOK],
|
||||
STMT_BOOK);
|
||||
@ -278,22 +285,21 @@ db_book_load(struct kreq *r, int64_t id)
|
||||
ksql_stmt_free(stmt);
|
||||
return(NULL);
|
||||
}
|
||||
fputs("stmt ok", stderr);
|
||||
book = kcalloc(1, sizeof(BookFull));
|
||||
db_book_fill(&book->ba.b, stmt);
|
||||
|
||||
book->timestamp = ksql_stmt_int(stmt, 5);
|
||||
book->pubdate = ksql_stmt_int(stmt, 6);
|
||||
book->isbn = kstrdup(ksql_stmt_str(stmt, 7));
|
||||
book->lccn = kstrdup(ksql_stmt_str(stmt, 8));
|
||||
book->path = kstrdup(ksql_stmt_str(stmt, 9));
|
||||
book->uuid = kstrdup(ksql_stmt_str(stmt, 10));
|
||||
book->isbn = strornull(stmt, 7);
|
||||
book->lccn = strornull(stmt, 8);
|
||||
book->path = strornull(stmt, 9);
|
||||
book->uuid = strornull(stmt, 10);
|
||||
book->has_cover = ksql_stmt_int(stmt, 11);
|
||||
book->lang = kstrdup(ksql_stmt_str(stmt, 12));
|
||||
book->format = kstrdup(ksql_stmt_str(stmt, 13));
|
||||
book->dataname = kstrdup(ksql_stmt_str(stmt, 14));
|
||||
book->unz_size = ksql_stmt_int(stmt, 15);
|
||||
book->publisher = kstrdup(ksql_stmt_str(stmt, 16));
|
||||
book->lang = strornull(stmt, 12);
|
||||
book->format = strornull(stmt, 13);
|
||||
book->unz_size = ksql_stmt_int(stmt, 14);
|
||||
book->dataname = strornull(stmt, 15);
|
||||
book->publisher = strornull(stmt, 16);
|
||||
|
||||
ksql_stmt_free(stmt);
|
||||
|
||||
|
7
main.c
7
main.c
@ -144,13 +144,11 @@ static void
|
||||
putbookfull(struct kjsonreq *req, BookFull *b)
|
||||
{
|
||||
char tsstr[30];
|
||||
char pubdatestr[30];
|
||||
|
||||
putbook(req, &b->ba.b);
|
||||
kutil_epoch2str(b->timestamp, tsstr, sizeof(tsstr));
|
||||
kutil_epoch2str(b->pubdate, pubdatestr, sizeof(pubdatestr));
|
||||
kjson_putstringp(req, "timestamp", tsstr);
|
||||
kjson_putstringp(req, "pubdate", pubdatestr);
|
||||
kjson_putintp(req, "pubdate", b->pubdate);
|
||||
kjson_putstringp(req, "isbn", b->isbn);
|
||||
kjson_putstringp(req, "lccn", b->lccn);
|
||||
kjson_putstringp(req, "path", b->path);
|
||||
@ -160,7 +158,8 @@ putbookfull(struct kjsonreq *req, BookFull *b)
|
||||
kjson_putstringp(req, "format", b->format);
|
||||
kjson_putstringp(req, "data", b->dataname);
|
||||
kjson_putintp(req, "uncompressed_size", b->unz_size);
|
||||
kjson_putstringp(req, "publisher", b->publisher);
|
||||
if (NULL != b->publisher)
|
||||
kjson_putstringp(req, "publisher", b->publisher);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user