1 -- MySQL dump 10.13 Distrib 5.7.12, for Linux (x86_64)
3 -- Host: localhost Database: metadata
4 -- ------------------------------------------------------
5 -- Server version 5.7.12-0ubuntu1
7 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10 /*!40101 SET NAMES utf8 */;
11 /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12 /*!40103 SET TIME_ZONE='+00:00' */;
13 /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14 /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15 /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16 /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
19 -- Table structure for table `authors`
22 DROP TABLE IF EXISTS `authors`;
23 /*!40101 SET @saved_cs_client = @@character_set_client */;
24 /*!40101 SET character_set_client = utf8 */;
25 CREATE TABLE `authors` (
26 `id` int(11) NOT NULL AUTO_INCREMENT,
27 `name` varchar(255) NOT NULL,
28 `sort` varchar(255) DEFAULT NULL,
30 UNIQUE KEY `NAMEIDX` (`name`) USING BTREE,
31 KEY `SORTIDX` (`sort`) USING BTREE
32 ) ENGINE=InnoDB AUTO_INCREMENT=140889 DEFAULT CHARSET=utf8;
33 /*!40101 SET character_set_client = @saved_cs_client */;
36 -- Table structure for table `books`
39 DROP TABLE IF EXISTS `books`;
40 /*!40101 SET @saved_cs_client = @@character_set_client */;
41 /*!40101 SET character_set_client = utf8 */;
42 CREATE TABLE `books` (
43 `id` int(11) NOT NULL AUTO_INCREMENT,
44 `title` varchar(512) DEFAULT NULL,
45 `sort` varchar(512) DEFAULT NULL,
46 `timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
47 `pubdate` timestamp NULL DEFAULT NULL,
48 `series_index` decimal(10,2) DEFAULT '1.00',
49 `isbn` varchar(45) DEFAULT NULL,
50 `path` varchar(2000) DEFAULT NULL,
51 `uuid` varchar(128) DEFAULT NULL,
52 `has_cover` int(11) DEFAULT '0',
53 `last_modified` timestamp NULL DEFAULT NULL,
55 KEY `SORTIDX` (`sort`(255)),
56 KEY `TITLEIDX` (`title`(255)),
57 KEY `TIMESTAMPIDX` (`timestamp`),
58 KEY `ISBNIDX` (`isbn`)
59 ) ENGINE=InnoDB AUTO_INCREMENT=1892665 DEFAULT CHARSET=utf8;
60 /*!40101 SET character_set_client = @saved_cs_client */;
63 -- Table structure for table `books_authors_link`
66 DROP TABLE IF EXISTS `books_authors_link`;
67 /*!40101 SET @saved_cs_client = @@character_set_client */;
68 /*!40101 SET character_set_client = utf8 */;
69 CREATE TABLE `books_authors_link` (
70 `id` int(11) NOT NULL AUTO_INCREMENT,
71 `book` int(11) NOT NULL,
72 `author` int(11) NOT NULL,
74 UNIQUE KEY `book` (`book`,`author`),
75 KEY `books_authors_link_aidx` (`author`),
76 KEY `books_authors_link_bidx` (`book`),
77 CONSTRAINT `fk_books_authors_link_auth` FOREIGN KEY (`author`) REFERENCES `authors` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
78 CONSTRAINT `fk_books_authors_link_books` FOREIGN KEY (`book`) REFERENCES `books_old` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
79 ) ENGINE=InnoDB AUTO_INCREMENT=2017231 DEFAULT CHARSET=utf8;
80 /*!40101 SET character_set_client = @saved_cs_client */;
83 -- Table structure for table `books_languages_link`
86 DROP TABLE IF EXISTS `books_languages_link`;
87 /*!40101 SET @saved_cs_client = @@character_set_client */;
88 /*!40101 SET character_set_client = utf8 */;
89 CREATE TABLE `books_languages_link` (
90 `id` int(11) NOT NULL AUTO_INCREMENT,
91 `book` int(11) NOT NULL,
92 `lang_code` int(11) NOT NULL,
93 `item_order` int(11) NOT NULL DEFAULT '0',
95 UNIQUE KEY `book` (`book`,`lang_code`),
96 KEY `books_languages_link_aidx` (`lang_code`),
97 KEY `books_languages_link_bidx` (`book`),
98 CONSTRAINT `fk_books_languages_link_book` FOREIGN KEY (`book`) REFERENCES `books_old` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
99 CONSTRAINT `fk_books_languages_link_lang` FOREIGN KEY (`lang_code`) REFERENCES `languages` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
100 ) ENGINE=InnoDB AUTO_INCREMENT=1667797 DEFAULT CHARSET=utf8;
101 /*!40101 SET character_set_client = @saved_cs_client */;
104 -- Table structure for table `books_old`
107 DROP TABLE IF EXISTS `books_old`;
108 /*!40101 SET @saved_cs_client = @@character_set_client */;
109 /*!40101 SET character_set_client = utf8 */;
110 CREATE TABLE `books_old` (
111 `id` int(11) NOT NULL AUTO_INCREMENT,
112 `title` varchar(512) DEFAULT NULL,
113 `sort` varchar(512) DEFAULT NULL,
114 `timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
115 `pubdate` timestamp NULL DEFAULT NULL,
116 `series_index` decimal(4,2) DEFAULT '1.00',
117 `isbn` varchar(45) DEFAULT NULL,
118 `path` varchar(2000) DEFAULT NULL,
119 `uuid` varchar(128) DEFAULT NULL,
120 `has_cover` int(11) DEFAULT '0',
121 `last_modified` timestamp NULL DEFAULT NULL,
123 KEY `SORTIDX` (`sort`(255)),
124 KEY `TITLEIDX` (`title`(255)),
125 KEY `TIMESTAMPIDX` (`timestamp`),
126 KEY `ISBNIDX` (`isbn`)
127 ) ENGINE=InnoDB AUTO_INCREMENT=1892532 DEFAULT CHARSET=utf8;
128 /*!40101 SET character_set_client = @saved_cs_client */;
131 -- Table structure for table `books_publishers_link`
134 DROP TABLE IF EXISTS `books_publishers_link`;
135 /*!40101 SET @saved_cs_client = @@character_set_client */;
136 /*!40101 SET character_set_client = utf8 */;
137 CREATE TABLE `books_publishers_link` (
138 `id` int(11) NOT NULL AUTO_INCREMENT,
139 `book` int(11) NOT NULL,
140 `publisher` int(11) NOT NULL,
142 KEY `books_publishers_link_aidx` (`publisher`),
143 KEY `books_publishers_link_bidx` (`book`),
144 CONSTRAINT `fk_books_publishers_link_book` FOREIGN KEY (`book`) REFERENCES `books_old` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
145 CONSTRAINT `fk_books_publishers_link_pub` FOREIGN KEY (`publisher`) REFERENCES `publishers` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
146 ) ENGINE=InnoDB AUTO_INCREMENT=981343 DEFAULT CHARSET=utf8;
147 /*!40101 SET character_set_client = @saved_cs_client */;
150 -- Table structure for table `books_series_link`
153 DROP TABLE IF EXISTS `books_series_link`;
154 /*!40101 SET @saved_cs_client = @@character_set_client */;
155 /*!40101 SET character_set_client = utf8 */;
156 CREATE TABLE `books_series_link` (
157 `id` int(11) NOT NULL AUTO_INCREMENT,
158 `book` int(11) NOT NULL,
159 `series` int(11) NOT NULL,
161 KEY `books_series_link_aidx` (`series`),
162 KEY `books_series_link_bidx` (`book`),
163 CONSTRAINT `fk_books_series_link_book` FOREIGN KEY (`book`) REFERENCES `books_old` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
164 CONSTRAINT `fk_books_series_link_ser` FOREIGN KEY (`series`) REFERENCES `series` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
165 ) ENGINE=InnoDB AUTO_INCREMENT=741933 DEFAULT CHARSET=utf8;
166 /*!40101 SET character_set_client = @saved_cs_client */;
169 -- Table structure for table `books_tags_link`
172 DROP TABLE IF EXISTS `books_tags_link`;
173 /*!40101 SET @saved_cs_client = @@character_set_client */;
174 /*!40101 SET character_set_client = utf8 */;
175 CREATE TABLE `books_tags_link` (
176 `id` int(11) NOT NULL AUTO_INCREMENT,
177 `book` int(11) NOT NULL,
178 `tag` int(11) NOT NULL,
180 UNIQUE KEY `book` (`book`,`tag`),
181 KEY `books_tags_link_aidx` (`tag`),
182 KEY `books_tags_link_bidx` (`book`),
183 CONSTRAINT `fk_books_tags_link_book` FOREIGN KEY (`book`) REFERENCES `books_old` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
184 CONSTRAINT `fk_books_tags_link_tag` FOREIGN KEY (`tag`) REFERENCES `tags` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
185 ) ENGINE=InnoDB AUTO_INCREMENT=2015931 DEFAULT CHARSET=utf8;
186 /*!40101 SET character_set_client = @saved_cs_client */;
189 -- Table structure for table `comments`
192 DROP TABLE IF EXISTS `comments`;
193 /*!40101 SET @saved_cs_client = @@character_set_client */;
194 /*!40101 SET character_set_client = utf8 */;
195 CREATE TABLE `comments` (
196 `id` int(11) NOT NULL AUTO_INCREMENT,
197 `book` int(11) DEFAULT NULL,
198 `text` varchar(4000) DEFAULT NULL,
200 UNIQUE KEY `book_UNIQUE` (`book`),
201 CONSTRAINT `fk_comments_book` FOREIGN KEY (`book`) REFERENCES `books_old` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
202 ) ENGINE=InnoDB AUTO_INCREMENT=1457254 DEFAULT CHARSET=utf8;
203 /*!40101 SET character_set_client = @saved_cs_client */;
206 -- Table structure for table `data`
209 DROP TABLE IF EXISTS `data`;
210 /*!40101 SET @saved_cs_client = @@character_set_client */;
211 /*!40101 SET character_set_client = utf8 */;
212 CREATE TABLE `data` (
213 `id` int(11) NOT NULL AUTO_INCREMENT,
214 `book` int(11) NOT NULL,
215 `format` varchar(45) NOT NULL,
216 `uncompressed_size` int(11) DEFAULT NULL,
217 `name` varchar(2000) NOT NULL,
219 KEY `fk_data_book_idx` (`book`),
220 KEY `format_idx` (`format`),
221 CONSTRAINT `fk_data_book` FOREIGN KEY (`book`) REFERENCES `books_old` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
222 ) ENGINE=InnoDB AUTO_INCREMENT=1892071 DEFAULT CHARSET=utf8;
223 /*!40101 SET character_set_client = @saved_cs_client */;
226 -- Table structure for table `directories`
229 DROP TABLE IF EXISTS `directories`;
230 /*!40101 SET @saved_cs_client = @@character_set_client */;
231 /*!40101 SET character_set_client = utf8 */;
232 CREATE TABLE `directories` (
233 `id` int(11) NOT NULL AUTO_INCREMENT,
234 `path` varchar(256) NOT NULL,
235 `descr` varchar(2000) DEFAULT NULL,
237 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
238 /*!40101 SET character_set_client = @saved_cs_client */;
241 -- Table structure for table `lang_alias`
244 DROP TABLE IF EXISTS `lang_alias`;
245 /*!40101 SET @saved_cs_client = @@character_set_client */;
246 /*!40101 SET character_set_client = utf8 */;
247 CREATE TABLE `lang_alias` (
248 `alias` varchar(32) NOT NULL,
249 `lang_code` varchar(32) DEFAULT NULL,
250 PRIMARY KEY (`alias`),
251 KEY `fk_lang_alias_1_idx` (`lang_code`),
252 CONSTRAINT `fk_lang_alias_1` FOREIGN KEY (`lang_code`) REFERENCES `languages` (`lang_code`) ON DELETE NO ACTION ON UPDATE NO ACTION
253 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
254 /*!40101 SET character_set_client = @saved_cs_client */;
257 -- Table structure for table `languages`
260 DROP TABLE IF EXISTS `languages`;
261 /*!40101 SET @saved_cs_client = @@character_set_client */;
262 /*!40101 SET character_set_client = utf8 */;
263 CREATE TABLE `languages` (
264 `id` int(11) NOT NULL AUTO_INCREMENT,
265 `lang_code` varchar(10) DEFAULT NULL,
267 UNIQUE KEY `lang_code_UNIQUE` (`lang_code`)
268 ) ENGINE=InnoDB AUTO_INCREMENT=217 DEFAULT CHARSET=utf8;
269 /*!40101 SET character_set_client = @saved_cs_client */;
272 -- Table structure for table `processed_archives`
275 DROP TABLE IF EXISTS `processed_archives`;
276 /*!40101 SET @saved_cs_client = @@character_set_client */;
277 /*!40101 SET character_set_client = utf8 */;
278 CREATE TABLE `processed_archives` (
279 `id` int(11) NOT NULL AUTO_INCREMENT,
280 `filename` varchar(255) DEFAULT NULL,
282 UNIQUE KEY `filename` (`filename`)
283 ) ENGINE=InnoDB AUTO_INCREMENT=1035 DEFAULT CHARSET=utf8;
284 /*!40101 SET character_set_client = @saved_cs_client */;
287 -- Table structure for table `publishers`
290 DROP TABLE IF EXISTS `publishers`;
291 /*!40101 SET @saved_cs_client = @@character_set_client */;
292 /*!40101 SET character_set_client = utf8 */;
293 CREATE TABLE `publishers` (
294 `id` int(11) NOT NULL AUTO_INCREMENT,
295 `name` longtext NOT NULL,
298 ) ENGINE=InnoDB AUTO_INCREMENT=31291 DEFAULT CHARSET=utf8;
299 /*!40101 SET character_set_client = @saved_cs_client */;
302 -- Table structure for table `series`
305 DROP TABLE IF EXISTS `series`;
306 /*!40101 SET @saved_cs_client = @@character_set_client */;
307 /*!40101 SET character_set_client = utf8 */;
308 CREATE TABLE `series` (
309 `id` int(11) NOT NULL AUTO_INCREMENT,
310 `name` longtext NOT NULL,
313 ) ENGINE=InnoDB AUTO_INCREMENT=46699 DEFAULT CHARSET=utf8;
314 /*!40101 SET character_set_client = @saved_cs_client */;
317 -- Table structure for table `tags`
320 DROP TABLE IF EXISTS `tags`;
321 /*!40101 SET @saved_cs_client = @@character_set_client */;
322 /*!40101 SET character_set_client = utf8 */;
323 CREATE TABLE `tags` (
324 `id` int(11) NOT NULL AUTO_INCREMENT,
325 `name` longtext NOT NULL,
327 KEY `nameidx` (`name`(32))
328 ) ENGINE=InnoDB AUTO_INCREMENT=548 DEFAULT CHARSET=utf8;
329 /*!40101 SET character_set_client = @saved_cs_client */;
332 -- Table structure for table `tags_mapping`
335 DROP TABLE IF EXISTS `tags_mapping`;
336 /*!40101 SET @saved_cs_client = @@character_set_client */;
337 /*!40101 SET character_set_client = utf8 */;
338 CREATE TABLE `tags_mapping` (
339 `id` int(11) NOT NULL AUTO_INCREMENT,
340 `tag_mask` varchar(45) NOT NULL,
341 `tag_result` varchar(45) NOT NULL,
343 ) ENGINE=InnoDB AUTO_INCREMENT=347 DEFAULT CHARSET=utf8;
344 /*!40101 SET character_set_client = @saved_cs_client */;
347 -- Dumping events for database 'metadata'
351 -- Dumping routines for database 'metadata'
353 /*!50003 DROP FUNCTION IF EXISTS `CreateBook` */;
354 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
355 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
356 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
357 /*!50003 SET character_set_client = utf8 */ ;
358 /*!50003 SET character_set_results = utf8 */ ;
359 /*!50003 SET collation_connection = utf8_general_ci */ ;
360 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
361 /*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
363 CREATE DEFINER=`admin`@`%` FUNCTION `CreateBook`(title varchar(2000),pubdate datetime,series_index decimal(10,2),isbn varchar(45)) RETURNS int(11)
366 INSERT INTO books(title,sort,pubdate,series_index,isbn) VALUES (title,SortStr(title),pubdate,series_index,isbn);
367 select last_insert_id() into lID;
371 /*!50003 SET sql_mode = @saved_sql_mode */ ;
372 /*!50003 SET character_set_client = @saved_cs_client */ ;
373 /*!50003 SET character_set_results = @saved_cs_results */ ;
374 /*!50003 SET collation_connection = @saved_col_connection */ ;
375 /*!50003 DROP FUNCTION IF EXISTS `DeleteDoubleSpaces` */;
376 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
377 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
378 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
379 /*!50003 SET character_set_client = utf8 */ ;
380 /*!50003 SET character_set_results = utf8 */ ;
381 /*!50003 SET collation_connection = utf8_general_ci */ ;
382 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
383 /*!50003 SET sql_mode = '' */ ;
385 CREATE DEFINER=`admin`@`%` FUNCTION `DeleteDoubleSpaces`( title VARCHAR(250) ) RETURNS varchar(250) CHARSET utf8
388 DECLARE result VARCHAR(250);
389 SET result = REPLACE( title, ' ', ' ' );
390 WHILE (result <> title) DO
392 SET result = REPLACE( title, ' ', ' ' );
397 /*!50003 SET sql_mode = @saved_sql_mode */ ;
398 /*!50003 SET character_set_client = @saved_cs_client */ ;
399 /*!50003 SET character_set_results = @saved_cs_results */ ;
400 /*!50003 SET collation_connection = @saved_col_connection */ ;
401 /*!50003 DROP FUNCTION IF EXISTS `GetOrCreateAuthor` */;
402 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
403 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
404 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
405 /*!50003 SET character_set_client = utf8 */ ;
406 /*!50003 SET character_set_results = utf8 */ ;
407 /*!50003 SET collation_connection = utf8_general_ci */ ;
408 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
409 /*!50003 SET sql_mode = '' */ ;
411 CREATE DEFINER=`admin`@`%` FUNCTION `GetOrCreateAuthor`(pAuthor varchar(255)) RETURNS int(11)
414 select min(ID) into lID from authors where name=pAuthor;
416 insert into authors(name,sort)
417 values(pAuthor,SortAuthor(pAuthor));
418 SET lID = last_insert_id();
423 /*!50003 SET sql_mode = @saved_sql_mode */ ;
424 /*!50003 SET character_set_client = @saved_cs_client */ ;
425 /*!50003 SET character_set_results = @saved_cs_results */ ;
426 /*!50003 SET collation_connection = @saved_col_connection */ ;
427 /*!50003 DROP FUNCTION IF EXISTS `GetOrCreateLang` */;
428 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
429 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
430 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
431 /*!50003 SET character_set_client = utf8 */ ;
432 /*!50003 SET character_set_results = utf8 */ ;
433 /*!50003 SET collation_connection = utf8_general_ci */ ;
434 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
435 /*!50003 SET sql_mode = '' */ ;
437 CREATE DEFINER=`admin`@`%` FUNCTION `GetOrCreateLang`(pLang varchar(255)) RETURNS int(11)
439 declare lID integer;
\r
440 declare lLang varchar(255);
\r
441 select min(lang_code) into lLang from lang_alias where alias=pLang;
\r
442 if lLang is null then
\r
445 select min(ID) into lID from languages where lang_code=lLang;
447 insert into languages(lang_code)
449 SET lID = last_insert_id();
454 /*!50003 SET sql_mode = @saved_sql_mode */ ;
455 /*!50003 SET character_set_client = @saved_cs_client */ ;
456 /*!50003 SET character_set_results = @saved_cs_results */ ;
457 /*!50003 SET collation_connection = @saved_col_connection */ ;
458 /*!50003 DROP FUNCTION IF EXISTS `GetOrCreatePublisher` */;
459 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
460 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
461 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
462 /*!50003 SET character_set_client = utf8 */ ;
463 /*!50003 SET character_set_results = utf8 */ ;
464 /*!50003 SET collation_connection = utf8_general_ci */ ;
465 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
466 /*!50003 SET sql_mode = '' */ ;
468 CREATE DEFINER=`admin`@`%` FUNCTION `GetOrCreatePublisher`(pPub varchar(255)) RETURNS int(11)
471 select min(ID) into lID from publishers where name=pPub;
473 insert into publishers(name,sort)
474 values(pPub,SortStr(pPub));
475 SET lID = last_insert_id();
480 /*!50003 SET sql_mode = @saved_sql_mode */ ;
481 /*!50003 SET character_set_client = @saved_cs_client */ ;
482 /*!50003 SET character_set_results = @saved_cs_results */ ;
483 /*!50003 SET collation_connection = @saved_col_connection */ ;
484 /*!50003 DROP FUNCTION IF EXISTS `GetOrCreateSeries` */;
485 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
486 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
487 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
488 /*!50003 SET character_set_client = utf8 */ ;
489 /*!50003 SET character_set_results = utf8 */ ;
490 /*!50003 SET collation_connection = utf8_general_ci */ ;
491 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
492 /*!50003 SET sql_mode = '' */ ;
494 CREATE DEFINER=`admin`@`%` FUNCTION `GetOrCreateSeries`(pSeries varchar(255)) RETURNS int(11)
497 select min(ID) into lID from series where name=pSeries;
499 insert into series(name,sort)
500 values(pSeries,SortStr(pSeries));
501 SET lID = last_insert_id();
506 /*!50003 SET sql_mode = @saved_sql_mode */ ;
507 /*!50003 SET character_set_client = @saved_cs_client */ ;
508 /*!50003 SET character_set_results = @saved_cs_results */ ;
509 /*!50003 SET collation_connection = @saved_col_connection */ ;
510 /*!50003 DROP FUNCTION IF EXISTS `GetOrCreateTag` */;
511 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
512 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
513 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
514 /*!50003 SET character_set_client = utf8 */ ;
515 /*!50003 SET character_set_results = utf8 */ ;
516 /*!50003 SET collation_connection = utf8_general_ci */ ;
517 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
518 /*!50003 SET sql_mode = '' */ ;
520 CREATE DEFINER=`admin`@`%` FUNCTION `GetOrCreateTag`(pTag varchar(255)) RETURNS int(11)
523 select min(ID) into lID from tags where name=pTag;
525 insert into tags(name)
527 SET lID = last_insert_id();
532 /*!50003 SET sql_mode = @saved_sql_mode */ ;
533 /*!50003 SET character_set_client = @saved_cs_client */ ;
534 /*!50003 SET character_set_results = @saved_cs_results */ ;
535 /*!50003 SET collation_connection = @saved_col_connection */ ;
536 /*!50003 DROP FUNCTION IF EXISTS `ProcessLang` */;
537 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
538 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
539 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
540 /*!50003 SET character_set_client = utf8 */ ;
541 /*!50003 SET character_set_results = utf8 */ ;
542 /*!50003 SET collation_connection = utf8_general_ci */ ;
543 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
544 /*!50003 SET sql_mode = '' */ ;
546 CREATE DEFINER=`admin`@`%` FUNCTION `ProcessLang`(pOldLang varchar(64),pNewLang varchar(64)) RETURNS varchar(2000) CHARSET utf8
548 declare Res varchar(2000);
549 declare lOldID integer;
550 declare lNewID integer;
551 select id into lOldID from languages where lang_code=pOldLang;
552 select id into lNewID from languages where lang_code=pNewLang;
553 SET Res = CONCAT(lOldID ,' ',lNewID);
554 insert into metadata.books_languages_link(book,lang_code)
555 select book,lNewID from metadata.books_languages_link
556 where lang_code=lOldID
558 (select book from metadata.books_languages_link
559 where lang_code=lNewID);
560 delete from metadata.books_languages_link
561 where lang_code=lOldID;
562 delete from metadata.languages where id=lOldID;
566 /*!50003 SET sql_mode = @saved_sql_mode */ ;
567 /*!50003 SET character_set_client = @saved_cs_client */ ;
568 /*!50003 SET character_set_results = @saved_cs_results */ ;
569 /*!50003 SET collation_connection = @saved_col_connection */ ;
570 /*!50003 DROP FUNCTION IF EXISTS `ProcessMapping` */;
571 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
572 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
573 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
574 /*!50003 SET character_set_client = utf8 */ ;
575 /*!50003 SET character_set_results = utf8 */ ;
576 /*!50003 SET collation_connection = utf8_general_ci */ ;
577 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
578 /*!50003 SET sql_mode = '' */ ;
580 CREATE DEFINER=`admin`@`%` FUNCTION `ProcessMapping`() RETURNS int(11)
582 DECLARE counter INTEGER;
583 DECLARE done INT DEFAULT FALSE;
584 DECLARE old_tag, new_tag,dummystr VARCHAR(255);
585 DECLARE cur CURSOR FOR
586 SELECT t1.name,t2.name FROM metadata.tags t1,metadata.tags t2,metadata.tags_mapping m
587 where m.tag_result=t2.name and t1.name REGEXP m.tag_mask and t1.id<>t2.id;
588 DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
592 FETCH cur into old_tag,new_tag;
596 SELECT ProcessTags(old_tag,new_tag) INTo dummystr;
597 SET counter = counter+1;
603 /*!50003 SET sql_mode = @saved_sql_mode */ ;
604 /*!50003 SET character_set_client = @saved_cs_client */ ;
605 /*!50003 SET character_set_results = @saved_cs_results */ ;
606 /*!50003 SET collation_connection = @saved_col_connection */ ;
607 /*!50003 DROP FUNCTION IF EXISTS `ProcessTags` */;
608 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
609 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
610 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
611 /*!50003 SET character_set_client = utf8 */ ;
612 /*!50003 SET character_set_results = utf8 */ ;
613 /*!50003 SET collation_connection = utf8_general_ci */ ;
614 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
615 /*!50003 SET sql_mode = '' */ ;
617 CREATE DEFINER=`admin`@`%` FUNCTION `ProcessTags`(pOldTag varchar(64),pNewTag varchar(64)) RETURNS varchar(2000) CHARSET utf8
619 declare Res varchar(2000);
620 declare lOldID integer;
621 declare lNewID integer;
622 select id into lOldID from tags where name=pOldTag;
623 select id into lNewID from tags where name=pNewTag;
624 SET Res = CONCAT(lOldID ,' ',lNewID);
625 insert into metadata.books_tags_link(book,tag)
626 select book,lNewID from metadata.books_tags_link
629 (select book from metadata.books_tags_link
631 delete from metadata.books_tags_link
633 delete from metadata.tags where id=lOldID;
637 /*!50003 SET sql_mode = @saved_sql_mode */ ;
638 /*!50003 SET character_set_client = @saved_cs_client */ ;
639 /*!50003 SET character_set_results = @saved_cs_results */ ;
640 /*!50003 SET collation_connection = @saved_col_connection */ ;
641 /*!50003 DROP FUNCTION IF EXISTS `SortAuthor` */;
642 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
643 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
644 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
645 /*!50003 SET character_set_client = utf8 */ ;
646 /*!50003 SET character_set_results = utf8 */ ;
647 /*!50003 SET collation_connection = utf8_general_ci */ ;
648 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
649 /*!50003 SET sql_mode = '' */ ;
651 CREATE DEFINER=`admin`@`%` FUNCTION `SortAuthor`(pStr varchar(2000)) RETURNS varchar(2000) CHARSET utf8
654 RETURN REPLACE(SplitAuthor(SortStr(pStr)),'NO ORIGINAL NAME FOR ','');
657 /*!50003 SET sql_mode = @saved_sql_mode */ ;
658 /*!50003 SET character_set_client = @saved_cs_client */ ;
659 /*!50003 SET character_set_results = @saved_cs_results */ ;
660 /*!50003 SET collation_connection = @saved_col_connection */ ;
661 /*!50003 DROP FUNCTION IF EXISTS `SortStr` */;
662 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
663 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
664 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
665 /*!50003 SET character_set_client = utf8 */ ;
666 /*!50003 SET character_set_results = utf8 */ ;
667 /*!50003 SET collation_connection = utf8_general_ci */ ;
668 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
669 /*!50003 SET sql_mode = '' */ ;
671 CREATE DEFINER=`admin`@`%` FUNCTION `SortStr`(pStr varchar(2000)) RETURNS varchar(2000) CHARSET utf8
674 DECLARE i INT DEFAULT 1;
675 DECLARE v_char VARCHAR(1);
676 DECLARE v_parseStr VARCHAR(2000) DEFAULT ' ';
678 SET pStr = UPPER(pStr);
680 IF pSTR LIKE 'A %' THEN
681 SET pSTR=SUBSTR(pStr,3);
682 ELSEIF pSTR LIKE 'THE %' THEN
683 SET pSTR=SUBSTR(pStr,5);
684 ELSEIF pSTR LIKE 'EL %' THEN
685 SET pSTR=SUBSTR(pStr,4);
686 ELSEIF pSTR LIKE 'IL %' THEN
687 SET pSTR=SUBSTR(pStr,4);
688 ELSEIF pSTR LIKE 'L\'%' THEN
689 SET pSTR=SUBSTR(pStr,3);
690 ELSEIF pSTR LIKE 'LES %' THEN
691 SET pSTR=SUBSTR(pStr,5);
692 ELSEIF pSTR LIKE 'DIE %' THEN
693 SET pSTR=SUBSTR(pStr,5);
694 ELSEIF pSTR LIKE 'DER %' THEN
695 SET pSTR=SUBSTR(pStr,5);
696 ELSEIF pSTR LIKE 'DAS %' THEN
697 SET pSTR=SUBSTR(pStr,5);
698 ELSEIF pSTR LIKE 'LA %' THEN
699 SET pSTR=SUBSTR(pStr,4);
700 ELSEIF pSTR LIKE 'LOS %' THEN
701 SET pSTR=SUBSTR(pStr,5);
702 ELSEIF pSTR LIKE 'LÀ %' THEN
703 SET pSTR=SUBSTR(pStr,4);
704 ELSEIF pSTR LIKE 'LE %' THEN
705 SET pSTR=SUBSTR(pStr,4);
706 ELSEIF pSTR LIKE 'LAS %' THEN
707 SET pSTR=SUBSTR(pStr,5);
708 ELSEIF pSTR LIKE 'UN %' THEN
709 SET pSTR=SUBSTR(pStr,4);
710 ELSEIF pSTR LIKE 'UNA %' THEN
711 SET pSTR=SUBSTR(pStr,5);
712 ELSEIF pSTR LIKE 'UNO %' THEN
713 SET pSTR=SUBSTR(pStr,5);
716 WHILE (i <= LENGTH(pStr) ) DO
718 SET v_char = SUBSTR(pStr,i,1);
720 IF v_char REGEXP '^[A-Z0-9АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ ]+$' OR v_char = '-' THEN #alphanumeric
721 SET v_parseStr = CONCAT(v_parseStr,v_char);
723 ELSEIF v_char='Š' collate 'utf8_bin' THEN
724 SET v_parseStr = CONCAT(v_parseStr,'S');
726 ELSEIF v_char='Ð' collate 'utf8_bin' THEN
727 SET v_parseStr = CONCAT(v_parseStr,'Dj');
729 ELSEIF v_char='Ž' collate 'utf8_bin' THEN
730 SET v_parseStr = CONCAT(v_parseStr,'Z');
732 ELSEIF v_char='À' collate 'utf8_bin' THEN
733 SET v_parseStr = CONCAT(v_parseStr,'A');
735 ELSEIF v_char='Á' collate 'utf8_bin' THEN
736 SET v_parseStr = CONCAT(v_parseStr,'A');
738 ELSEIF v_char='Â' collate 'utf8_bin' THEN
739 SET v_parseStr = CONCAT(v_parseStr,'A');
741 ELSEIF v_char='Ã' collate 'utf8_bin' THEN
742 SET v_parseStr = CONCAT(v_parseStr,'A');
744 ELSEIF v_char='Ä' collate 'utf8_bin' THEN
745 SET v_parseStr = CONCAT(v_parseStr,'A');
747 ELSEIF v_char='Å' collate 'utf8_bin' THEN
748 SET v_parseStr = CONCAT(v_parseStr,'A');
750 ELSEIF v_char='Æ' collate 'utf8_bin' THEN
751 SET v_parseStr = CONCAT(v_parseStr,'A');
753 ELSEIF v_char='Ç' collate 'utf8_bin' THEN
754 SET v_parseStr = CONCAT(v_parseStr,'C');
756 ELSEIF v_char='È' collate 'utf8_bin' THEN
757 SET v_parseStr = CONCAT(v_parseStr,'E');
759 ELSEIF v_char='É' collate 'utf8_bin' THEN
760 SET v_parseStr = CONCAT(v_parseStr,'E');
762 ELSEIF v_char='Ê' collate 'utf8_bin' THEN
763 SET v_parseStr = CONCAT(v_parseStr,'E');
765 ELSEIF v_char='Ë' collate 'utf8_bin' THEN
766 SET v_parseStr = CONCAT(v_parseStr,'E');
768 ELSEIF v_char='Ì' collate 'utf8_bin' THEN
769 SET v_parseStr = CONCAT(v_parseStr,'I');
771 ELSEIF v_char='Í' collate 'utf8_bin' THEN
772 SET v_parseStr = CONCAT(v_parseStr,'I');
774 ELSEIF v_char='Î' collate 'utf8_bin' THEN
775 SET v_parseStr = CONCAT(v_parseStr,'I');
777 ELSEIF v_char='Ï' collate 'utf8_bin' THEN
778 SET v_parseStr = CONCAT(v_parseStr,'I');
780 ELSEIF v_char='Ñ' collate 'utf8_bin' THEN
781 SET v_parseStr = CONCAT(v_parseStr,'N');
783 ELSEIF v_char='Ò' THEN
784 SET v_parseStr = CONCAT(v_parseStr,'O');
786 ELSEIF v_char='Ó' collate 'utf8_bin' THEN
787 SET v_parseStr = CONCAT(v_parseStr,'O');
789 ELSEIF v_char='Ô' collate 'utf8_bin' THEN
790 SET v_parseStr = CONCAT(v_parseStr,'O');
792 ELSEIF v_char='Õ' collate 'utf8_bin' THEN
793 SET v_parseStr = CONCAT(v_parseStr,'O');
795 ELSEIF v_char='Ö' collate 'utf8_bin' THEN
796 SET v_parseStr = CONCAT(v_parseStr,'O');
798 ELSEIF v_char='Ø' collate 'utf8_bin' THEN
799 SET v_parseStr = CONCAT(v_parseStr,'O');
801 ELSEIF v_char='Ù' collate 'utf8_bin' THEN
802 SET v_parseStr = CONCAT(v_parseStr,'U');
804 ELSEIF v_char='Ú' collate 'utf8_bin' THEN
805 SET v_parseStr = CONCAT(v_parseStr,'U');
807 ELSEIF v_char='Û' collate 'utf8_bin' THEN
808 SET v_parseStr = CONCAT(v_parseStr,'U');
810 ELSEIF v_char='Ü' collate 'utf8_bin' THEN
811 SET v_parseStr = CONCAT(v_parseStr,'U');
813 ELSEIF v_char='Ý' collate 'utf8_bin' THEN
814 SET v_parseStr = CONCAT(v_parseStr,'Y');
816 ELSEIF v_char='Þ' collate 'utf8_bin' THEN
817 SET v_parseStr = CONCAT(v_parseStr,'B');
819 ELSEIF v_char='ß' collate 'utf8_bin' THEN
820 SET v_parseStr = CONCAT(v_parseStr,'SS');
822 ELSEIF v_char='Ł' collate 'utf8_bin' THEN
823 SET v_parseStr = CONCAT(v_parseStr,'L');
825 ELSEIF v_char='Ĥ' collate 'utf8_bin' THEN
826 SET v_parseStr = CONCAT(v_parseStr,'H');
828 ELSEIF v_char='Č' collate 'utf8_bin' THEN
829 SET v_parseStr = CONCAT(v_parseStr,'C');
833 IF v_char='Ґ' collate 'utf8_bin' THEN
834 SET v_parseStr = CONCAT(v_parseStr,'Г');
836 ELSEIF v_char='І' collate 'utf8_bin' THEN
837 SET v_parseStr = CONCAT(v_parseStr,'И');
839 ELSEIF v_char='Є' collate 'utf8_bin' THEN
840 SET v_parseStr = CONCAT(v_parseStr,'Е');
842 ELSEIF v_char='Ї' collate 'utf8_bin' THEN
843 SET v_parseStr = CONCAT(v_parseStr,'Й');
845 ELSEIF v_char='Ў' collate 'utf8_bin' THEN
846 SET v_parseStr = CONCAT(v_parseStr,'У');
848 ELSEIF v_char='Ђ' collate 'utf8_bin' THEN
849 SET v_parseStr = CONCAT(v_parseStr,'ДЖ');
851 ELSEIF v_char='Џ' collate 'utf8_bin' THEN
852 SET v_parseStr = CONCAT(v_parseStr,'ДЖ');
854 ELSEIF v_char='Ѓ' collate 'utf8_bin' THEN
855 SET v_parseStr = CONCAT(v_parseStr,'Г');
857 ELSEIF v_char='Љ' collate 'utf8_bin' THEN
858 SET v_parseStr = CONCAT(v_parseStr,'ЛЬ');
860 ELSEIF v_char='Њ' collate 'utf8_bin' THEN
861 SET v_parseStr = CONCAT(v_parseStr,'HЬ');
863 ELSEIF v_char='Ћ' collate 'utf8_bin' THEN
864 SET v_parseStr = CONCAT(v_parseStr,'Ч');
869 SET v_parseStr = CONCAT(v_parseStr,'S');
875 SET v_parseStr=trim(DeleteDoubleSpaces(v_parseStr));
879 /*!50003 SET sql_mode = @saved_sql_mode */ ;
880 /*!50003 SET character_set_client = @saved_cs_client */ ;
881 /*!50003 SET character_set_results = @saved_cs_results */ ;
882 /*!50003 SET collation_connection = @saved_col_connection */ ;
883 /*!50003 DROP FUNCTION IF EXISTS `SplitAuthor` */;
884 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
885 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
886 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
887 /*!50003 SET character_set_client = utf8 */ ;
888 /*!50003 SET character_set_results = utf8 */ ;
889 /*!50003 SET collation_connection = utf8_general_ci */ ;
890 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
891 /*!50003 SET sql_mode = '' */ ;
893 CREATE DEFINER=`admin`@`%` FUNCTION `SplitAuthor`(pStr VARCHAR(2000)) RETURNS varchar(2000) CHARSET utf8
895 DECLARE lLastName VARCHAR(2000);
896 DECLARE lStr VARCHAR(2000);
897 DECLARE lLastNameLen INTEGER;
898 DECLARE lFirstName VARCHAR(2000);
900 SET lLastName=substring_index(lStr,' ',-1);
901 IF lLastName<>lStr THEN
902 SET lLastNameLen=char_length(lLastName);
903 SET lFirstName=trim(substring(pStr,1,char_length(lStr)-lLastNameLen-1));
904 RETURN concat(lLastName,' ',lFirstName);
910 /*!50003 SET sql_mode = @saved_sql_mode */ ;
911 /*!50003 SET character_set_client = @saved_cs_client */ ;
912 /*!50003 SET character_set_results = @saved_cs_results */ ;
913 /*!50003 SET collation_connection = @saved_col_connection */ ;
914 /*!50003 DROP PROCEDURE IF EXISTS `DropTag` */;
915 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
916 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
917 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
918 /*!50003 SET character_set_client = utf8 */ ;
919 /*!50003 SET character_set_results = utf8 */ ;
920 /*!50003 SET collation_connection = utf8_general_ci */ ;
921 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
922 /*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;
924 CREATE DEFINER=`admin`@`%` PROCEDURE `DropTag`(pOldTag varchar(64))
926 declare lOldID integer;
927 select id into lOldID from tags where name=pOldTag;
928 delete from metadata.books_tags_link
930 delete from metadata.tags where id=lOldID;
933 /*!50003 SET sql_mode = @saved_sql_mode */ ;
934 /*!50003 SET character_set_client = @saved_cs_client */ ;
935 /*!50003 SET character_set_results = @saved_cs_results */ ;
936 /*!50003 SET collation_connection = @saved_col_connection */ ;
937 /*!50003 DROP PROCEDURE IF EXISTS `ProcessLangAliases` */;
938 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
939 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
940 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
941 /*!50003 SET character_set_client = utf8 */ ;
942 /*!50003 SET character_set_results = utf8 */ ;
943 /*!50003 SET collation_connection = utf8_general_ci */ ;
944 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
945 /*!50003 SET sql_mode = '' */ ;
947 CREATE DEFINER=`admin`@`%` PROCEDURE `ProcessLangAliases`()
949 DECLARE done INT DEFAULT FALSE;
\r
950 DECLARE alias,lang,dummystr VARCHAR(255);
\r
951 DECLARE cur CURSOR FOR
952 SELECT a.alias,a.lang_code FROM metadata.languages l,metadata.lang_alias a where l.lang_code=a.alias;
\r
953 DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
\r
956 FETCH cur into alias,lang;
\r
960 SELECT ProcessLang(alias,lang) INTO dummystr;
\r
965 /*!50003 SET sql_mode = @saved_sql_mode */ ;
966 /*!50003 SET character_set_client = @saved_cs_client */ ;
967 /*!50003 SET character_set_results = @saved_cs_results */ ;
968 /*!50003 SET collation_connection = @saved_col_connection */ ;
969 /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
971 /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
972 /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
973 /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
974 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
975 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
976 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
977 /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
979 -- Dump completed on 2016-05-19 19:39:15