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