Skip to content

Commit 915af59

Browse files
committed
New db format for librusec and additional field in ruks output mode
1 parent b7b00b7 commit 915af59

File tree

2 files changed

+56
-24
lines changed

2 files changed

+56
-24
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
1414

1515
# Project version number
1616
set(PRJ_VERSION_MAJOR 9)
17-
set(PRJ_VERSION_MINOR 0)
17+
set(PRJ_VERSION_MINOR 1)
1818
configure_file("${PROJECT_SOURCE_DIR}/cmake/version.h.in" "${PROJECT_BINARY_DIR}/version.h")
1919
include_directories("${PROJECT_BINARY_DIR}")
2020

lib2inpx/lib2inpx.cpp

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static fb2_preference g_fb2_preference = eIgnoreFB2;
8080
enum processing_type { eFB2 = 0, eUSR, eAll };
8181
static processing_type g_process = eFB2;
8282

83-
enum database_format { eDefault = 0, e20100206, e20100317, e20100411, e20111106 };
83+
enum database_format { eDefault = 0, e20100206, e20100317, e20100411, e20111106, e20170531 };
8484
static database_format g_format = eDefault;
8585

8686
enum inpx_format { e1X = 0, e2X, eRUKS };
@@ -400,20 +400,20 @@ void get_book_author(const mysql_connection& mysql, const string& book_id, strin
400400

401401
string str;
402402

403-
if ((e20100206 == g_format) || (e20100317 == g_format) || (e20100411 == g_format) || (e20111106 == g_format)) {
403+
if (eDefault != g_format) {
404404
str = "SELECT `aid` FROM `libavtor` WHERE bid=";
405405
} else {
406406
str = "SELECT `AvtorId` FROM `libavtor` WHERE BookId=";
407407
}
408408

409409
str += book_id;
410-
str += (e20100411 == g_format) || ((e20111106 == g_format)) ? " AND role=\"a\";" : ";";
410+
str += ((e20100411 == g_format) || (e20111106 == g_format) || (e20170531 == g_format)) ? " AND role=\"a\";" : ";";
411411

412412
mysql.query(str);
413413

414414
if ((e20100206 == g_format) || (e20100317 == g_format) || (e20100411 == g_format)) {
415415
str = "SELECT `FirstName`,`MiddleName`,`LastName` FROM libavtorname WHERE aid=";
416-
} else if (e20111106 == g_format) {
416+
} else if ((e20111106 == g_format) || (e20170531 == g_format)) {
417417
str = "SELECT `FirstName`,`MiddleName`,`LastName` FROM libavtors WHERE aid=";
418418
} else {
419419
str = "SELECT `FirstName`,`MiddleName`,`LastName` FROM libavtorname WHERE AvtorId=";
@@ -423,7 +423,7 @@ void get_book_author(const mysql_connection& mysql, const string& book_id, strin
423423
while (record = avtor_ids.fetch_row()) {
424424
string good_author_id(record[0]);
425425

426-
if (e20111106 == g_format) {
426+
if ((e20111106 == g_format) || (e20170531 == g_format)) {
427427
mysql.query(string("SELECT `main` FROM libavtors WHERE aid=") + good_author_id + ";");
428428
{
429429
mysql_results ids(mysql);
@@ -503,7 +503,7 @@ void get_book_genres(const mysql_connection& mysql, const string& book_id, strin
503503
str = "SELECT GenreCode FROM libgenrelist WHERE gid=";
504504
} else if (e20100411 == g_format) {
505505
str = "SELECT code FROM libgenrelist WHERE gid=";
506-
} else if (e20111106 == g_format) {
506+
} else if ((e20111106 == g_format) || (e20170531 == g_format)) {
507507
str = "SELECT code FROM libgenres WHERE gid=";
508508
} else {
509509
str = "SELECT GenreCode FROM libgenrelist WHERE GenreId=";
@@ -538,7 +538,7 @@ void get_book_squence(const mysql_connection& mysql, const string& book_id, stri
538538

539539
if (e20100206 == g_format) {
540540
str = "SELECT `sid`,`SeqNumb` FROM libseq WHERE bid=" + book_id;
541-
} else if ((e20100317 == g_format) || (e20100411 == g_format) || (e20111106 == g_format)) {
541+
} else if ((e20100317 == g_format) || (e20100411 == g_format) || (e20111106 == g_format) || (e20170531 == g_format)) {
542542
str = "SELECT `sid`,`sn` FROM libseq WHERE bid=" + book_id;
543543
} else {
544544
str = "SELECT `SeqId`,`SeqNumb` FROM libseq WHERE BookId=" + book_id;
@@ -561,15 +561,15 @@ void get_book_squence(const mysql_connection& mysql, const string& book_id, stri
561561

562562
if ((e20100206 == g_format) || (e20100317 == g_format) || (e20100411 == g_format)) {
563563
str = "SELECT SeqName FROM libseqname WHERE sid=";
564-
} else if (e20111106 == g_format) {
564+
} else if ((e20111106 == g_format) || (e20170531 == g_format)) {
565565
str = "SELECT SeqName FROM libseqs WHERE sid=";
566566
} else {
567567
str = "SELECT SeqName FROM libseqname WHERE SeqId=";
568568
}
569569

570570
str = str + seq_id;
571571

572-
if (e20111106 == g_format) {
572+
if ((e20111106 == g_format) || (e20170531 == g_format)) {
573573
if (g_series_type == eAuthorST) {
574574
str += " AND type='a'";
575575
} else if (g_series_type == ePublisherST) {
@@ -637,6 +637,10 @@ void process_book(const mysql_connection& mysql, MYSQL_ROW record, const string&
637637
if ((g_inpx_format == eRUKS) && (record[8] != NULL)) {
638638
book_md5 = record[8];
639639
}
640+
string book_replaced;
641+
if ((g_inpx_format == eRUKS) && (g_format == e20170531) && (record[9] != NULL)) {
642+
book_replaced = record[9];
643+
}
640644

641645
string book_file(cleanse(file_name));
642646

@@ -713,6 +717,8 @@ void process_book(const mysql_connection& mysql, MYSQL_ROW record, const string&
713717
if (g_inpx_format == eRUKS) {
714718
inp += book_md5;
715719
inp += sep;
720+
inp += book_replaced;
721+
inp += sep;
716722
}
717723
inp += "\r\n";
718724
}
@@ -877,30 +883,54 @@ void process_local_archives(const mysql_connection& mysql, const zip& zz, const
877883
if (fb2) {
878884
if ((g_process == eAll) || ((g_process == eFB2))) {
879885
name_to_bookid(uz.current(), book_id, ext);
880-
if ((e20100206 == g_format) || (e20100317 == g_format) || (e20100411 == g_format) || (e20111106 == g_format)) {
886+
if (eDefault != g_format) {
881887
raw_stmt = "SELECT `bid`,`Title`,`FileSize`,`FileType`,`Deleted`,`Time`,`Lang`,`keywords`%s FROM libbook WHERE bid=%s;";
882888
} else {
883889
raw_stmt = "SELECT `BookId`,`Title`,`FileSize`,`FileType`,`Deleted`,`Time`,`Lang`,`keywords`%s FROM libbook WHERE BookId=%s;";
884890
}
885-
stmt = tmp_str(raw_stmt, (g_inpx_format == eRUKS) ? ",`md5`" : "", book_id.c_str());
891+
if (g_inpx_format != eRUKS) {
892+
stmt = tmp_str(raw_stmt, "", book_id.c_str());
893+
} else {
894+
if (e20170531 == g_format) {
895+
stmt = tmp_str(raw_stmt, ",`md5`,`ReplacedBy`", book_id.c_str());
896+
} else {
897+
stmt = tmp_str(raw_stmt, ",`md5`", book_id.c_str());
898+
}
899+
}
886900
} else {
887901
fdummy = true;
888902
}
889903
} else {
890904
if ((g_process == eAll) || ((g_process == eUSR))) {
891905
name_to_bookid(uz.current(), book_id, ext);
892-
if (is_numeric(book_id) && ((e20100411 == g_format) || (e20111106 == g_format))) {
906+
if (is_numeric(book_id) && ((e20100411 == g_format) || (e20111106 == g_format) || (e20170531 == g_format))) {
893907
raw_stmt = "SELECT `bid`,`Title`,`FileSize`,`FileType`,`Deleted`,`Time`,`Lang`,`keywords`%s FROM libbook WHERE bid=%s;";
894-
stmt = tmp_str(raw_stmt, (g_inpx_format == eRUKS) ? ",`md5`" : "", book_id.c_str());
908+
if (g_inpx_format != eRUKS) {
909+
stmt = tmp_str(raw_stmt, "", book_id.c_str());
910+
} else {
911+
if (e20170531 == g_format) {
912+
stmt = tmp_str(raw_stmt, ",`md5`,`ReplacedBy`", book_id.c_str());
913+
} else {
914+
stmt = tmp_str(raw_stmt, ",`md5`", book_id.c_str());
915+
}
916+
}
895917
} else {
896-
if ((e20100206 == g_format) || (e20100317 == g_format) || (e20100411 == g_format) || (e20111106 == g_format)) {
918+
if (eDefault != g_format) {
897919
raw_stmt = "SELECT B.bid, B.Title, B.FileSize, B.FileType, B.Deleted, B.Time, B.Lang, B.KeyWords%s "
898920
"FROM libbook B, libfilename F WHERE B.bid = F.bid AND F.FileName = \"%s\";";
899921
} else {
900922
raw_stmt = "SELECT B.BookId, B.Title, B.FileSize, B.FileType, B.Deleted, B.Time, B.Lang, "
901923
"B.KeyWords%s FROM libbook B, libfilename F WHERE B.BookId = F.BookID AND F.FileName = \"%s\";";
902924
}
903-
stmt = tmp_str(raw_stmt, (g_inpx_format == eRUKS) ? ", B.md5" : "", uz.current().c_str());
925+
if (g_inpx_format != eRUKS) {
926+
stmt = tmp_str(raw_stmt, "", uz.current().c_str());
927+
} else {
928+
if (e20170531 == g_format) {
929+
stmt = tmp_str(raw_stmt, ", B.md5, B.ReplacedBy", uz.current().c_str());
930+
} else {
931+
stmt = tmp_str(raw_stmt, ", B.md5", uz.current().c_str());
932+
}
933+
}
904934
}
905935
} else {
906936
fdummy = true;
@@ -997,10 +1027,10 @@ void process_database(const mysql_connection& mysql, const zip& zz)
9971027
const char* raw_stmt = (eDefault == g_format) ? "SELECT `BookId`,`Title`,`FileSize`,`FileType`,`Deleted`,`Time`,`Lang`,`keywords`%s FROM libbook %s ORDER BY BookId;"
9981028
: "SELECT `bid`,`Title`,`FileSize`,`FileType`,`Deleted`,`Time`,`Lang`,`keywords`%s FROM libbook %s ORDER BY bid;";
9991029

1000-
const char* md5 = (g_inpx_format == eRUKS) ? ",`md5`" : "";
1030+
const char* extra = (g_inpx_format == eRUKS) ? ((e20170531 == g_format) ? ",`md5`,`ReplacedBy`" : ",`md5`") : "";
10011031
const char* where = (g_process == eFB2) ? "WHERE FileType = 'fb2'" : ((g_process == eUSR) ? "WHERE FileType != 'fb2'" : "");
10021032

1003-
stmt = tmp_str(raw_stmt, md5, where);
1033+
stmt = tmp_str(raw_stmt, extra, where);
10041034

10051035
long current = 0;
10061036
long records = 0;
@@ -1012,7 +1042,7 @@ void process_database(const mysql_connection& mysql, const zip& zz)
10121042

10131043
long last_filename_id = -1;
10141044

1015-
if ((e20100411 == g_format) || (e20111106 == g_format)) {
1045+
if ((e20100411 == g_format) || (e20111106 == g_format) || (e20170531 == g_format)) {
10161046
if (filenames_table_exist(mysql)) {
10171047
last_filename_id = get_last_filename_id(mysql);
10181048

@@ -1034,7 +1064,7 @@ void process_database(const mysql_connection& mysql, const zip& zz)
10341064
if (0 == strcasecmp(record[3], ext.c_str())) {
10351065
file_name = record[0];
10361066
} else {
1037-
if ((e20100411 == g_format) || (e20111106 == g_format)) {
1067+
if ((e20100411 == g_format) || (e20111106 == g_format) || (e20170531 == g_format)) {
10381068
if ((last_filename_id < 0) || (last_filename_id < atol(record[0]))) {
10391069
file_name = record[0];
10401070
ext = record[3];
@@ -1127,7 +1157,7 @@ int main(int argc, char* argv[])
11271157
("inpx", po::value< string >(), "Full name of output file (default: <program_path>/data/<db_name>_<db_dump_date>.inpx)")
11281158
("comment", po::value< string >(), "File name of template (UTF-8) for INPX comment")
11291159
("update", po::value< string >(), "Starting with \"<arg>.zip\" produce \"daily_update.zip\" (Works only for \"fb2\")")
1130-
("db-format", po::value< string >(), "Database format, change date (YYYY-MM-DD). Supported: 2010-02-06, 2010-03-17, 2010-04-11, 2011-11-06. (Default - old librusec format before 2010-02-06)")
1160+
("db-format", po::value< string >(), "Database format, change date (YYYY-MM-DD). Supported: 2010-02-06, 2010-03-17, 2010-04-11, 2011-11-06, 2017-05-31. (Default - old librusec format before 2010-02-06)")
11311161
("clean-authors", "Clean duplicate authors (librusec)")
11321162
("clean-aliases", "Fix libavtoraliase table (flibusta)")
11331163
("inpx-format", po::value< string >(), "INPX format, Supported: 1.x, 2.x, ruks (Default - new MyHomeLib format 2.x)")
@@ -1252,6 +1282,8 @@ int main(int argc, char* argv[])
12521282
g_format = e20100411;
12531283
} else if (0 == strcasecmp(opt.c_str(), "2011-11-06")) {
12541284
g_format = e20111106;
1285+
} else if (0 == strcasecmp(opt.c_str(), "2017-05-31")) {
1286+
g_format = e20170531;
12551287
} else {
12561288
wcout << endl << "Warning: unknown database format, will use default!" << endl << flush;
12571289
g_format = eDefault;
@@ -1300,7 +1332,7 @@ int main(int argc, char* argv[])
13001332
}
13011333

13021334
if (vm.count("clean-aliases"))
1303-
if (e20111106 != g_format) {
1335+
if ((e20111106 != g_format) && (e20170531 != g_format)) {
13041336
g_clean_aliases = true;
13051337
}
13061338

@@ -1441,7 +1473,7 @@ int main(int argc, char* argv[])
14411473
}
14421474

14431475
{
1444-
string table_name = (e20111106 == g_format) ? "libavtors" : "libavtorname";
1476+
string table_name = ((e20111106 == g_format) || (e20170531 == g_format)) ? "libavtors" : "libavtorname";
14451477

14461478
mysql_connection mysql(g_outdir.c_str(), g_db_name.c_str(), db_name.c_str());
14471479

@@ -1514,7 +1546,7 @@ int main(int argc, char* argv[])
15141546
}
15151547

15161548
// Starting from 03/19/2017 flibusta stopped exporting lib.libavtoraliase.sql
1517-
if (e20111106 != g_format) {
1549+
if ((e20111106 != g_format) && (e20170531 != g_format)) {
15181550
g_have_alias_table = authoraliases_table_exist(mysql);
15191551
if (!g_have_alias_table) {
15201552
wcout << endl << "Warning: absent \"lib.libavtoraliase.sql\"! For some authors names could be incorrect..." << endl << flush;

0 commit comments

Comments
 (0)