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=141003 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 `series_index` decimal(10,2) DEFAULT '1.00',
48 `isbn` varchar(45) DEFAULT NULL,
49 `path` varchar(2000) DEFAULT NULL,
50 `uuid` varchar(128) DEFAULT NULL,
51 `has_cover` int(11) DEFAULT '0',
52 `last_modified` timestamp NULL DEFAULT NULL,
53 `pubdate` datetime 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=1893115 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` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
79 ) ENGINE=InnoDB AUTO_INCREMENT=2017688 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 KEY `books_languages_link_aidx` (`lang_code`),
96 KEY `books_languages_link_bidx` (`book`),
97 CONSTRAINT `fk_books_languages_link_book` FOREIGN KEY (`book`) REFERENCES `books` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
98 CONSTRAINT `fk_books_languages_link_lang` FOREIGN KEY (`lang_code`) REFERENCES `languages` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
99 ) ENGINE=InnoDB AUTO_INCREMENT=1668113 DEFAULT CHARSET=utf8;
100 /*!40101 SET character_set_client = @saved_cs_client */;
103 -- Table structure for table `books_publishers_link`
106 DROP TABLE IF EXISTS `books_publishers_link`;
107 /*!40101 SET @saved_cs_client = @@character_set_client */;
108 /*!40101 SET character_set_client = utf8 */;
109 CREATE TABLE `books_publishers_link` (
110 `id` int(11) NOT NULL AUTO_INCREMENT,
111 `book` int(11) NOT NULL,
112 `publisher` int(11) NOT NULL,
114 KEY `books_publishers_link_aidx` (`publisher`),
115 KEY `fk_books_publishers_link_book_idx` (`book`),
116 CONSTRAINT `fk_books_publishers_link_book` FOREIGN KEY (`book`) REFERENCES `books` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
117 CONSTRAINT `fk_books_publishers_link_pub` FOREIGN KEY (`publisher`) REFERENCES `publishers` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
118 ) ENGINE=InnoDB AUTO_INCREMENT=981535 DEFAULT CHARSET=utf8;
119 /*!40101 SET character_set_client = @saved_cs_client */;
122 -- Table structure for table `books_series_link`
125 DROP TABLE IF EXISTS `books_series_link`;
126 /*!40101 SET @saved_cs_client = @@character_set_client */;
127 /*!40101 SET character_set_client = utf8 */;
128 CREATE TABLE `books_series_link` (
129 `id` int(11) NOT NULL AUTO_INCREMENT,
130 `book` int(11) NOT NULL,
131 `series` int(11) NOT NULL,
133 KEY `books_series_link_aidx` (`series`),
134 KEY `fk_books_series_link_book_idx` (`book`),
135 CONSTRAINT `fk_books_series_link_book` FOREIGN KEY (`book`) REFERENCES `books` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
136 CONSTRAINT `fk_books_series_link_ser` FOREIGN KEY (`series`) REFERENCES `series` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
137 ) ENGINE=InnoDB AUTO_INCREMENT=742109 DEFAULT CHARSET=utf8;
138 /*!40101 SET character_set_client = @saved_cs_client */;
141 -- Table structure for table `books_tags_link`
144 DROP TABLE IF EXISTS `books_tags_link`;
145 /*!40101 SET @saved_cs_client = @@character_set_client */;
146 /*!40101 SET character_set_client = utf8 */;
147 CREATE TABLE `books_tags_link` (
148 `id` int(11) NOT NULL AUTO_INCREMENT,
149 `book` int(11) NOT NULL,
150 `tag` int(11) NOT NULL,
152 KEY `books_tags_link_aidx` (`tag`),
153 KEY `books_tags_link_bidx` (`book`),
154 CONSTRAINT `fk_books_tags_link_book` FOREIGN KEY (`book`) REFERENCES `books` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION,
155 CONSTRAINT `fk_books_tags_link_tag` FOREIGN KEY (`tag`) REFERENCES `tags` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
156 ) ENGINE=InnoDB AUTO_INCREMENT=2016387 DEFAULT CHARSET=utf8;
157 /*!40101 SET character_set_client = @saved_cs_client */;
160 -- Table structure for table `comments`
163 DROP TABLE IF EXISTS `comments`;
164 /*!40101 SET @saved_cs_client = @@character_set_client */;
165 /*!40101 SET character_set_client = utf8 */;
166 CREATE TABLE `comments` (
167 `id` int(11) NOT NULL AUTO_INCREMENT,
168 `book` int(11) DEFAULT NULL,
169 `text` varchar(21000) DEFAULT NULL,
171 KEY `fk_comments_book_idx` (`book`),
172 CONSTRAINT `fk_comments_book` FOREIGN KEY (`book`) REFERENCES `books` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
173 ) ENGINE=InnoDB AUTO_INCREMENT=1457394 DEFAULT CHARSET=utf8;
174 /*!40101 SET character_set_client = @saved_cs_client */;
177 -- Table structure for table `data`
180 DROP TABLE IF EXISTS `data`;
181 /*!40101 SET @saved_cs_client = @@character_set_client */;
182 /*!40101 SET character_set_client = utf8 */;
183 CREATE TABLE `data` (
184 `id` int(11) NOT NULL AUTO_INCREMENT,
185 `book` int(11) NOT NULL,
186 `format` varchar(45) NOT NULL,
187 `uncompressed_size` int(11) DEFAULT NULL,
188 `name` varchar(2000) NOT NULL,
190 KEY `fk_data_book_idx` (`book`),
191 KEY `format_idx` (`format`),
192 CONSTRAINT `fk_data_book` FOREIGN KEY (`book`) REFERENCES `books` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
193 ) ENGINE=InnoDB AUTO_INCREMENT=1892214 DEFAULT CHARSET=utf8;
194 /*!40101 SET character_set_client = @saved_cs_client */;
197 -- Table structure for table `directories`
200 DROP TABLE IF EXISTS `directories`;
201 /*!40101 SET @saved_cs_client = @@character_set_client */;
202 /*!40101 SET character_set_client = utf8 */;
203 CREATE TABLE `directories` (
204 `id` int(11) NOT NULL AUTO_INCREMENT,
205 `path` varchar(256) NOT NULL,
206 `descr` varchar(2000) DEFAULT NULL,
208 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
209 /*!40101 SET character_set_client = @saved_cs_client */;
212 -- Table structure for table `lang_alias`
215 DROP TABLE IF EXISTS `lang_alias`;
216 /*!40101 SET @saved_cs_client = @@character_set_client */;
217 /*!40101 SET character_set_client = utf8 */;
218 CREATE TABLE `lang_alias` (
219 `alias` varchar(32) NOT NULL,
220 `lang_code` varchar(32) DEFAULT NULL,
221 PRIMARY KEY (`alias`),
222 KEY `fk_lang_alias_1_idx` (`lang_code`),
223 CONSTRAINT `fk_lang_alias_1` FOREIGN KEY (`lang_code`) REFERENCES `languages` (`lang_code`) ON DELETE NO ACTION ON UPDATE NO ACTION
224 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
225 /*!40101 SET character_set_client = @saved_cs_client */;
228 -- Table structure for table `languages`
231 DROP TABLE IF EXISTS `languages`;
232 /*!40101 SET @saved_cs_client = @@character_set_client */;
233 /*!40101 SET character_set_client = utf8 */;
234 CREATE TABLE `languages` (
235 `id` int(11) NOT NULL AUTO_INCREMENT,
236 `lang_code` varchar(10) DEFAULT NULL,
238 UNIQUE KEY `lang_code_UNIQUE` (`lang_code`)
239 ) ENGINE=InnoDB AUTO_INCREMENT=232 DEFAULT CHARSET=utf8;
240 /*!40101 SET character_set_client = @saved_cs_client */;
243 -- Table structure for table `processed_archives`
246 DROP TABLE IF EXISTS `processed_archives`;
247 /*!40101 SET @saved_cs_client = @@character_set_client */;
248 /*!40101 SET character_set_client = utf8 */;
249 CREATE TABLE `processed_archives` (
250 `id` int(11) NOT NULL AUTO_INCREMENT,
251 `filename` varchar(255) DEFAULT NULL,
253 UNIQUE KEY `filename` (`filename`)
254 ) ENGINE=InnoDB AUTO_INCREMENT=1035 DEFAULT CHARSET=utf8;
255 /*!40101 SET character_set_client = @saved_cs_client */;
258 -- Table structure for table `publishers`
261 DROP TABLE IF EXISTS `publishers`;
262 /*!40101 SET @saved_cs_client = @@character_set_client */;
263 /*!40101 SET character_set_client = utf8 */;
264 CREATE TABLE `publishers` (
265 `id` int(11) NOT NULL AUTO_INCREMENT,
266 `name` longtext NOT NULL,
269 ) ENGINE=InnoDB AUTO_INCREMENT=31351 DEFAULT CHARSET=utf8;
270 /*!40101 SET character_set_client = @saved_cs_client */;
273 -- Table structure for table `series`
276 DROP TABLE IF EXISTS `series`;
277 /*!40101 SET @saved_cs_client = @@character_set_client */;
278 /*!40101 SET character_set_client = utf8 */;
279 CREATE TABLE `series` (
280 `id` int(11) NOT NULL AUTO_INCREMENT,
281 `name` longtext NOT NULL,
284 ) ENGINE=InnoDB AUTO_INCREMENT=46776 DEFAULT CHARSET=utf8;
285 /*!40101 SET character_set_client = @saved_cs_client */;
288 -- Table structure for table `tags`
291 DROP TABLE IF EXISTS `tags`;
292 /*!40101 SET @saved_cs_client = @@character_set_client */;
293 /*!40101 SET character_set_client = utf8 */;
294 CREATE TABLE `tags` (
295 `id` int(11) NOT NULL AUTO_INCREMENT,
296 `name` longtext NOT NULL,
298 KEY `nameidx` (`name`(32))
299 ) ENGINE=InnoDB AUTO_INCREMENT=548 DEFAULT CHARSET=utf8;
300 /*!40101 SET character_set_client = @saved_cs_client */;
303 -- Table structure for table `tags_mapping`
306 DROP TABLE IF EXISTS `tags_mapping`;
307 /*!40101 SET @saved_cs_client = @@character_set_client */;
308 /*!40101 SET character_set_client = utf8 */;
309 CREATE TABLE `tags_mapping` (
310 `id` int(11) NOT NULL AUTO_INCREMENT,
311 `tag_mask` varchar(45) NOT NULL,
312 `tag_result` varchar(45) NOT NULL,
314 ) ENGINE=InnoDB AUTO_INCREMENT=347 DEFAULT CHARSET=utf8;
315 /*!40101 SET character_set_client = @saved_cs_client */;
318 -- Dumping events for database 'metadata'
322 -- Dumping routines for database 'metadata'
324 /*!50003 DROP FUNCTION IF EXISTS `CreateBook` */;
325 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
326 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
327 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
328 /*!50003 SET character_set_client = utf8 */ ;
329 /*!50003 SET character_set_results = utf8 */ ;
330 /*!50003 SET collation_connection = utf8_general_ci */ ;
331 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
332 /*!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' */ ;
334 CREATE DEFINER=`admin`@`%` FUNCTION `CreateBook`(title varchar(2000),pubdate datetime,series_index decimal(10,2),isbn varchar(45)) RETURNS int(11)
337 INSERT INTO books(title,sort,pubdate,series_index,isbn) VALUES (title,SortStr(title),pubdate,series_index,isbn);
338 select last_insert_id() into lID;
342 /*!50003 SET sql_mode = @saved_sql_mode */ ;
343 /*!50003 SET character_set_client = @saved_cs_client */ ;
344 /*!50003 SET character_set_results = @saved_cs_results */ ;
345 /*!50003 SET collation_connection = @saved_col_connection */ ;
346 /*!50003 DROP FUNCTION IF EXISTS `DeleteDoubleSpaces` */;
347 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
348 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
349 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
350 /*!50003 SET character_set_client = utf8 */ ;
351 /*!50003 SET character_set_results = utf8 */ ;
352 /*!50003 SET collation_connection = utf8_general_ci */ ;
353 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
354 /*!50003 SET sql_mode = '' */ ;
356 CREATE DEFINER=`admin`@`%` FUNCTION `DeleteDoubleSpaces`( title VARCHAR(250) ) RETURNS varchar(250) CHARSET utf8
359 DECLARE result VARCHAR(250);
360 SET result = REPLACE( title, ' ', ' ' );
361 WHILE (result <> title) DO
363 SET result = REPLACE( title, ' ', ' ' );
368 /*!50003 SET sql_mode = @saved_sql_mode */ ;
369 /*!50003 SET character_set_client = @saved_cs_client */ ;
370 /*!50003 SET character_set_results = @saved_cs_results */ ;
371 /*!50003 SET collation_connection = @saved_col_connection */ ;
372 /*!50003 DROP FUNCTION IF EXISTS `GetOrCreateAuthor` */;
373 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
374 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
375 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
376 /*!50003 SET character_set_client = utf8 */ ;
377 /*!50003 SET character_set_results = utf8 */ ;
378 /*!50003 SET collation_connection = utf8_general_ci */ ;
379 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
380 /*!50003 SET sql_mode = '' */ ;
382 CREATE DEFINER=`admin`@`%` FUNCTION `GetOrCreateAuthor`(pAuthor varchar(255)) RETURNS int(11)
385 select min(ID) into lID from authors where name=pAuthor;
387 insert into authors(name,sort)
388 values(pAuthor,SortAuthor(pAuthor));
389 SET lID = last_insert_id();
394 /*!50003 SET sql_mode = @saved_sql_mode */ ;
395 /*!50003 SET character_set_client = @saved_cs_client */ ;
396 /*!50003 SET character_set_results = @saved_cs_results */ ;
397 /*!50003 SET collation_connection = @saved_col_connection */ ;
398 /*!50003 DROP FUNCTION IF EXISTS `GetOrCreateLang` */;
399 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
400 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
401 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
402 /*!50003 SET character_set_client = utf8 */ ;
403 /*!50003 SET character_set_results = utf8 */ ;
404 /*!50003 SET collation_connection = utf8_general_ci */ ;
405 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
406 /*!50003 SET sql_mode = '' */ ;
408 CREATE DEFINER=`admin`@`%` FUNCTION `GetOrCreateLang`(pLang varchar(255)) RETURNS int(11)
410 declare lID integer;
\r
411 declare lLang varchar(255);
\r
412 select min(lang_code) into lLang from lang_alias where alias=pLang;
\r
413 if lLang is null then
\r
416 select min(ID) into lID from languages where lang_code=lLang;
418 insert into languages(lang_code)
420 SET lID = last_insert_id();
425 /*!50003 SET sql_mode = @saved_sql_mode */ ;
426 /*!50003 SET character_set_client = @saved_cs_client */ ;
427 /*!50003 SET character_set_results = @saved_cs_results */ ;
428 /*!50003 SET collation_connection = @saved_col_connection */ ;
429 /*!50003 DROP FUNCTION IF EXISTS `GetOrCreatePublisher` */;
430 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
431 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
432 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
433 /*!50003 SET character_set_client = utf8 */ ;
434 /*!50003 SET character_set_results = utf8 */ ;
435 /*!50003 SET collation_connection = utf8_general_ci */ ;
436 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
437 /*!50003 SET sql_mode = '' */ ;
439 CREATE DEFINER=`admin`@`%` FUNCTION `GetOrCreatePublisher`(pPub varchar(255)) RETURNS int(11)
442 select min(ID) into lID from publishers where name=pPub;
444 insert into publishers(name,sort)
445 values(pPub,SortStr(pPub));
446 SET lID = last_insert_id();
451 /*!50003 SET sql_mode = @saved_sql_mode */ ;
452 /*!50003 SET character_set_client = @saved_cs_client */ ;
453 /*!50003 SET character_set_results = @saved_cs_results */ ;
454 /*!50003 SET collation_connection = @saved_col_connection */ ;
455 /*!50003 DROP FUNCTION IF EXISTS `GetOrCreateSeries` */;
456 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
457 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
458 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
459 /*!50003 SET character_set_client = utf8 */ ;
460 /*!50003 SET character_set_results = utf8 */ ;
461 /*!50003 SET collation_connection = utf8_general_ci */ ;
462 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
463 /*!50003 SET sql_mode = '' */ ;
465 CREATE DEFINER=`admin`@`%` FUNCTION `GetOrCreateSeries`(pSeries varchar(255)) RETURNS int(11)
468 select min(ID) into lID from series where name=pSeries;
470 insert into series(name,sort)
471 values(pSeries,SortStr(pSeries));
472 SET lID = last_insert_id();
477 /*!50003 SET sql_mode = @saved_sql_mode */ ;
478 /*!50003 SET character_set_client = @saved_cs_client */ ;
479 /*!50003 SET character_set_results = @saved_cs_results */ ;
480 /*!50003 SET collation_connection = @saved_col_connection */ ;
481 /*!50003 DROP FUNCTION IF EXISTS `GetOrCreateTag` */;
482 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
483 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
484 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
485 /*!50003 SET character_set_client = utf8 */ ;
486 /*!50003 SET character_set_results = utf8 */ ;
487 /*!50003 SET collation_connection = utf8_general_ci */ ;
488 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
489 /*!50003 SET sql_mode = '' */ ;
491 CREATE DEFINER=`admin`@`%` FUNCTION `GetOrCreateTag`(pTag varchar(255)) RETURNS int(11)
494 select min(ID) into lID from tags where name=pTag;
496 insert into tags(name)
498 SET lID = last_insert_id();
503 /*!50003 SET sql_mode = @saved_sql_mode */ ;
504 /*!50003 SET character_set_client = @saved_cs_client */ ;
505 /*!50003 SET character_set_results = @saved_cs_results */ ;
506 /*!50003 SET collation_connection = @saved_col_connection */ ;
507 /*!50003 DROP FUNCTION IF EXISTS `ProcessLang` */;
508 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
509 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
510 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
511 /*!50003 SET character_set_client = utf8 */ ;
512 /*!50003 SET character_set_results = utf8 */ ;
513 /*!50003 SET collation_connection = utf8_general_ci */ ;
514 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
515 /*!50003 SET sql_mode = '' */ ;
517 CREATE DEFINER=`admin`@`%` FUNCTION `ProcessLang`(pOldLang varchar(64),pNewLang varchar(64)) RETURNS varchar(2000) CHARSET utf8
519 declare Res varchar(2000);
520 declare lOldID integer;
521 declare lNewID integer;
522 select id into lOldID from languages where lang_code=pOldLang;
523 select id into lNewID from languages where lang_code=pNewLang;
524 SET Res = CONCAT(lOldID ,' ',lNewID);
525 insert into metadata.books_languages_link(book,lang_code)
526 select book,lNewID from metadata.books_languages_link
527 where lang_code=lOldID
529 (select book from metadata.books_languages_link
530 where lang_code=lNewID);
531 delete from metadata.books_languages_link
532 where lang_code=lOldID;
533 delete from metadata.languages where id=lOldID;
537 /*!50003 SET sql_mode = @saved_sql_mode */ ;
538 /*!50003 SET character_set_client = @saved_cs_client */ ;
539 /*!50003 SET character_set_results = @saved_cs_results */ ;
540 /*!50003 SET collation_connection = @saved_col_connection */ ;
541 /*!50003 DROP FUNCTION IF EXISTS `ProcessMapping` */;
542 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
543 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
544 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
545 /*!50003 SET character_set_client = utf8 */ ;
546 /*!50003 SET character_set_results = utf8 */ ;
547 /*!50003 SET collation_connection = utf8_general_ci */ ;
548 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
549 /*!50003 SET sql_mode = '' */ ;
551 CREATE DEFINER=`admin`@`%` FUNCTION `ProcessMapping`() RETURNS int(11)
553 DECLARE counter INTEGER;
554 DECLARE done INT DEFAULT FALSE;
555 DECLARE old_tag, new_tag,dummystr VARCHAR(255);
556 DECLARE cur CURSOR FOR
557 SELECT t1.name,t2.name FROM metadata.tags t1,metadata.tags t2,metadata.tags_mapping m
558 where m.tag_result=t2.name and t1.name REGEXP m.tag_mask and t1.id<>t2.id;
559 DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
563 FETCH cur into old_tag,new_tag;
567 SELECT ProcessTags(old_tag,new_tag) INTo dummystr;
568 SET counter = counter+1;
574 /*!50003 SET sql_mode = @saved_sql_mode */ ;
575 /*!50003 SET character_set_client = @saved_cs_client */ ;
576 /*!50003 SET character_set_results = @saved_cs_results */ ;
577 /*!50003 SET collation_connection = @saved_col_connection */ ;
578 /*!50003 DROP FUNCTION IF EXISTS `ProcessTags` */;
579 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
580 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
581 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
582 /*!50003 SET character_set_client = utf8 */ ;
583 /*!50003 SET character_set_results = utf8 */ ;
584 /*!50003 SET collation_connection = utf8_general_ci */ ;
585 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
586 /*!50003 SET sql_mode = '' */ ;
588 CREATE DEFINER=`admin`@`%` FUNCTION `ProcessTags`(pOldTag varchar(64),pNewTag varchar(64)) RETURNS varchar(2000) CHARSET utf8
590 declare Res varchar(2000);
591 declare lOldID integer;
592 declare lNewID integer;
593 select id into lOldID from tags where name=pOldTag;
594 select id into lNewID from tags where name=pNewTag;
595 SET Res = CONCAT(lOldID ,' ',lNewID);
596 insert into metadata.books_tags_link(book,tag)
597 select book,lNewID from metadata.books_tags_link
600 (select book from metadata.books_tags_link
602 delete from metadata.books_tags_link
604 delete from metadata.tags where id=lOldID;
608 /*!50003 SET sql_mode = @saved_sql_mode */ ;
609 /*!50003 SET character_set_client = @saved_cs_client */ ;
610 /*!50003 SET character_set_results = @saved_cs_results */ ;
611 /*!50003 SET collation_connection = @saved_col_connection */ ;
612 /*!50003 DROP FUNCTION IF EXISTS `SortAuthor` */;
613 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
614 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
615 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
616 /*!50003 SET character_set_client = utf8 */ ;
617 /*!50003 SET character_set_results = utf8 */ ;
618 /*!50003 SET collation_connection = utf8_general_ci */ ;
619 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
620 /*!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' */ ;
622 CREATE DEFINER=`admin`@`%` FUNCTION `SortAuthor`(pStr varchar(2000)) RETURNS varchar(2000) CHARSET utf8
625 DECLARE lRes VARCHAR(2000);
626 SELECT MAX(SORT) INTO lRes FROM authors WHERE Name=pStr;
628 SET lRes=SortStr(pStr);
632 IF REPLACE(lRes,' ','')='' THEN
635 SET lRes=REPLACE(SplitAuthor(SortStr(pStr)),'NO ORIGINAL NAME FOR ','');
640 /*!50003 SET sql_mode = @saved_sql_mode */ ;
641 /*!50003 SET character_set_client = @saved_cs_client */ ;
642 /*!50003 SET character_set_results = @saved_cs_results */ ;
643 /*!50003 SET collation_connection = @saved_col_connection */ ;
644 /*!50003 DROP FUNCTION IF EXISTS `SortStr` */;
645 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
646 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
647 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
648 /*!50003 SET character_set_client = utf8 */ ;
649 /*!50003 SET character_set_results = utf8 */ ;
650 /*!50003 SET collation_connection = utf8_general_ci */ ;
651 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
652 /*!50003 SET sql_mode = '' */ ;
654 CREATE DEFINER=`admin`@`%` FUNCTION `SortStr`(pStr varchar(2000)) RETURNS varchar(2000) CHARSET utf8
657 DECLARE i INT DEFAULT 1;
658 DECLARE v_char VARCHAR(1);
659 DECLARE v_parseStr VARCHAR(2000) DEFAULT ' ';
661 SET pStr = UPPER(pStr);
663 IF pSTR LIKE 'A %' THEN
664 SET pSTR=SUBSTR(pStr,3);
665 ELSEIF pSTR LIKE 'THE %' THEN
666 SET pSTR=SUBSTR(pStr,5);
667 ELSEIF pSTR LIKE 'EL %' THEN
668 SET pSTR=SUBSTR(pStr,4);
669 ELSEIF pSTR LIKE 'IL %' THEN
670 SET pSTR=SUBSTR(pStr,4);
671 ELSEIF pSTR LIKE 'L\'%' THEN
672 SET pSTR=SUBSTR(pStr,3);
673 ELSEIF pSTR LIKE 'LES %' THEN
674 SET pSTR=SUBSTR(pStr,5);
675 ELSEIF pSTR LIKE 'DIE %' THEN
676 SET pSTR=SUBSTR(pStr,5);
677 ELSEIF pSTR LIKE 'DER %' THEN
678 SET pSTR=SUBSTR(pStr,5);
679 ELSEIF pSTR LIKE 'DAS %' THEN
680 SET pSTR=SUBSTR(pStr,5);
681 ELSEIF pSTR LIKE 'LA %' THEN
682 SET pSTR=SUBSTR(pStr,4);
683 ELSEIF pSTR LIKE 'LOS %' THEN
684 SET pSTR=SUBSTR(pStr,5);
685 ELSEIF pSTR LIKE 'LÀ %' THEN
686 SET pSTR=SUBSTR(pStr,4);
687 ELSEIF pSTR LIKE 'LE %' THEN
688 SET pSTR=SUBSTR(pStr,4);
689 ELSEIF pSTR LIKE 'LAS %' THEN
690 SET pSTR=SUBSTR(pStr,5);
691 ELSEIF pSTR LIKE 'UN %' THEN
692 SET pSTR=SUBSTR(pStr,4);
693 ELSEIF pSTR LIKE 'UNA %' THEN
694 SET pSTR=SUBSTR(pStr,5);
695 ELSEIF pSTR LIKE 'UNO %' THEN
696 SET pSTR=SUBSTR(pStr,5);
699 WHILE (i <= LENGTH(pStr) ) DO
701 SET v_char = SUBSTR(pStr,i,1);
703 IF v_char REGEXP '^[A-Z0-9АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ ]+$' OR v_char = '-' THEN #alphanumeric
704 SET v_parseStr = CONCAT(v_parseStr,v_char);
706 ELSEIF v_char='Š' collate 'utf8_bin' THEN
707 SET v_parseStr = CONCAT(v_parseStr,'S');
709 ELSEIF v_char='Ð' collate 'utf8_bin' THEN
710 SET v_parseStr = CONCAT(v_parseStr,'Dj');
712 ELSEIF v_char='Ž' collate 'utf8_bin' THEN
713 SET v_parseStr = CONCAT(v_parseStr,'Z');
715 ELSEIF v_char='À' collate 'utf8_bin' THEN
716 SET v_parseStr = CONCAT(v_parseStr,'A');
718 ELSEIF v_char='Á' collate 'utf8_bin' THEN
719 SET v_parseStr = CONCAT(v_parseStr,'A');
721 ELSEIF v_char='Â' collate 'utf8_bin' THEN
722 SET v_parseStr = CONCAT(v_parseStr,'A');
724 ELSEIF v_char='Ã' collate 'utf8_bin' THEN
725 SET v_parseStr = CONCAT(v_parseStr,'A');
727 ELSEIF v_char='Ä' collate 'utf8_bin' THEN
728 SET v_parseStr = CONCAT(v_parseStr,'A');
730 ELSEIF v_char='Å' collate 'utf8_bin' THEN
731 SET v_parseStr = CONCAT(v_parseStr,'A');
733 ELSEIF v_char='Æ' collate 'utf8_bin' THEN
734 SET v_parseStr = CONCAT(v_parseStr,'A');
736 ELSEIF v_char='Ç' collate 'utf8_bin' THEN
737 SET v_parseStr = CONCAT(v_parseStr,'C');
739 ELSEIF v_char='È' collate 'utf8_bin' THEN
740 SET v_parseStr = CONCAT(v_parseStr,'E');
742 ELSEIF v_char='É' collate 'utf8_bin' THEN
743 SET v_parseStr = CONCAT(v_parseStr,'E');
745 ELSEIF v_char='Ê' collate 'utf8_bin' THEN
746 SET v_parseStr = CONCAT(v_parseStr,'E');
748 ELSEIF v_char='Ë' collate 'utf8_bin' THEN
749 SET v_parseStr = CONCAT(v_parseStr,'E');
751 ELSEIF v_char='Ì' collate 'utf8_bin' THEN
752 SET v_parseStr = CONCAT(v_parseStr,'I');
754 ELSEIF v_char='Í' collate 'utf8_bin' THEN
755 SET v_parseStr = CONCAT(v_parseStr,'I');
757 ELSEIF v_char='Î' collate 'utf8_bin' THEN
758 SET v_parseStr = CONCAT(v_parseStr,'I');
760 ELSEIF v_char='Ï' collate 'utf8_bin' THEN
761 SET v_parseStr = CONCAT(v_parseStr,'I');
763 ELSEIF v_char='Ñ' collate 'utf8_bin' THEN
764 SET v_parseStr = CONCAT(v_parseStr,'N');
766 ELSEIF v_char='Ò' THEN
767 SET v_parseStr = CONCAT(v_parseStr,'O');
769 ELSEIF v_char='Ó' collate 'utf8_bin' THEN
770 SET v_parseStr = CONCAT(v_parseStr,'O');
772 ELSEIF v_char='Ô' collate 'utf8_bin' THEN
773 SET v_parseStr = CONCAT(v_parseStr,'O');
775 ELSEIF v_char='Õ' collate 'utf8_bin' THEN
776 SET v_parseStr = CONCAT(v_parseStr,'O');
778 ELSEIF v_char='Ö' collate 'utf8_bin' THEN
779 SET v_parseStr = CONCAT(v_parseStr,'O');
781 ELSEIF v_char='Ø' collate 'utf8_bin' THEN
782 SET v_parseStr = CONCAT(v_parseStr,'O');
784 ELSEIF v_char='Ù' collate 'utf8_bin' THEN
785 SET v_parseStr = CONCAT(v_parseStr,'U');
787 ELSEIF v_char='Ú' collate 'utf8_bin' THEN
788 SET v_parseStr = CONCAT(v_parseStr,'U');
790 ELSEIF v_char='Û' collate 'utf8_bin' THEN
791 SET v_parseStr = CONCAT(v_parseStr,'U');
793 ELSEIF v_char='Ü' collate 'utf8_bin' THEN
794 SET v_parseStr = CONCAT(v_parseStr,'U');
796 ELSEIF v_char='Ý' collate 'utf8_bin' THEN
797 SET v_parseStr = CONCAT(v_parseStr,'Y');
799 ELSEIF v_char='Þ' collate 'utf8_bin' THEN
800 SET v_parseStr = CONCAT(v_parseStr,'B');
802 ELSEIF v_char='ß' collate 'utf8_bin' THEN
803 SET v_parseStr = CONCAT(v_parseStr,'SS');
805 ELSEIF v_char='Ł' collate 'utf8_bin' THEN
806 SET v_parseStr = CONCAT(v_parseStr,'L');
808 ELSEIF v_char='Ĥ' collate 'utf8_bin' THEN
809 SET v_parseStr = CONCAT(v_parseStr,'H');
811 ELSEIF v_char='Č' collate 'utf8_bin' THEN
812 SET v_parseStr = CONCAT(v_parseStr,'C');
816 IF v_char='Ґ' collate 'utf8_bin' THEN
817 SET v_parseStr = CONCAT(v_parseStr,'Г');
819 ELSEIF v_char='І' collate 'utf8_bin' THEN
820 SET v_parseStr = CONCAT(v_parseStr,'И');
822 ELSEIF v_char='Є' collate 'utf8_bin' THEN
823 SET v_parseStr = CONCAT(v_parseStr,'Е');
825 ELSEIF v_char='Ї' collate 'utf8_bin' THEN
826 SET v_parseStr = CONCAT(v_parseStr,'Й');
828 ELSEIF v_char='Ў' collate 'utf8_bin' THEN
829 SET v_parseStr = CONCAT(v_parseStr,'У');
831 ELSEIF v_char='Ђ' collate 'utf8_bin' THEN
832 SET v_parseStr = CONCAT(v_parseStr,'ДЖ');
834 ELSEIF v_char='Џ' collate 'utf8_bin' THEN
835 SET v_parseStr = CONCAT(v_parseStr,'ДЖ');
837 ELSEIF v_char='Ѓ' collate 'utf8_bin' THEN
838 SET v_parseStr = CONCAT(v_parseStr,'Г');
840 ELSEIF v_char='Љ' collate 'utf8_bin' THEN
841 SET v_parseStr = CONCAT(v_parseStr,'ЛЬ');
843 ELSEIF v_char='Њ' collate 'utf8_bin' THEN
844 SET v_parseStr = CONCAT(v_parseStr,'HЬ');
846 ELSEIF v_char='Ћ' collate 'utf8_bin' THEN
847 SET v_parseStr = CONCAT(v_parseStr,'Ч');
852 SET v_parseStr = CONCAT(v_parseStr,'S');
858 SET v_parseStr=trim(DeleteDoubleSpaces(v_parseStr));
862 /*!50003 SET sql_mode = @saved_sql_mode */ ;
863 /*!50003 SET character_set_client = @saved_cs_client */ ;
864 /*!50003 SET character_set_results = @saved_cs_results */ ;
865 /*!50003 SET collation_connection = @saved_col_connection */ ;
866 /*!50003 DROP FUNCTION IF EXISTS `SplitAuthor` */;
867 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
868 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
869 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
870 /*!50003 SET character_set_client = utf8 */ ;
871 /*!50003 SET character_set_results = utf8 */ ;
872 /*!50003 SET collation_connection = utf8_general_ci */ ;
873 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
874 /*!50003 SET sql_mode = '' */ ;
876 CREATE DEFINER=`admin`@`%` FUNCTION `SplitAuthor`(pStr VARCHAR(2000)) RETURNS varchar(2000) CHARSET utf8
878 DECLARE lLastName VARCHAR(2000);
879 DECLARE lStr VARCHAR(2000);
880 DECLARE lLastNameLen INTEGER;
881 DECLARE lFirstName VARCHAR(2000);
883 SET lLastName=substring_index(lStr,' ',-1);
884 IF lLastName<>lStr THEN
885 SET lLastNameLen=char_length(lLastName);
886 SET lFirstName=trim(substring(pStr,1,char_length(lStr)-lLastNameLen-1));
887 RETURN concat(lLastName,' ',lFirstName);
893 /*!50003 SET sql_mode = @saved_sql_mode */ ;
894 /*!50003 SET character_set_client = @saved_cs_client */ ;
895 /*!50003 SET character_set_results = @saved_cs_results */ ;
896 /*!50003 SET collation_connection = @saved_col_connection */ ;
897 /*!50003 DROP PROCEDURE IF EXISTS `DropTag` */;
898 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
899 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
900 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
901 /*!50003 SET character_set_client = utf8 */ ;
902 /*!50003 SET character_set_results = utf8 */ ;
903 /*!50003 SET collation_connection = utf8_general_ci */ ;
904 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
905 /*!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' */ ;
907 CREATE DEFINER=`admin`@`%` PROCEDURE `DropTag`(pOldTag varchar(64))
909 declare lOldID integer;
910 select id into lOldID from tags where name=pOldTag;
911 delete from metadata.books_tags_link
913 delete from metadata.tags where id=lOldID;
916 /*!50003 SET sql_mode = @saved_sql_mode */ ;
917 /*!50003 SET character_set_client = @saved_cs_client */ ;
918 /*!50003 SET character_set_results = @saved_cs_results */ ;
919 /*!50003 SET collation_connection = @saved_col_connection */ ;
920 /*!50003 DROP PROCEDURE IF EXISTS `ProcessLangAliases` */;
921 /*!50003 SET @saved_cs_client = @@character_set_client */ ;
922 /*!50003 SET @saved_cs_results = @@character_set_results */ ;
923 /*!50003 SET @saved_col_connection = @@collation_connection */ ;
924 /*!50003 SET character_set_client = utf8 */ ;
925 /*!50003 SET character_set_results = utf8 */ ;
926 /*!50003 SET collation_connection = utf8_general_ci */ ;
927 /*!50003 SET @saved_sql_mode = @@sql_mode */ ;
928 /*!50003 SET sql_mode = '' */ ;
930 CREATE DEFINER=`admin`@`%` PROCEDURE `ProcessLangAliases`()
932 DECLARE done INT DEFAULT FALSE;
\r
933 DECLARE alias,lang,dummystr VARCHAR(255);
\r
934 DECLARE cur CURSOR FOR
935 SELECT a.alias,a.lang_code FROM metadata.languages l,metadata.lang_alias a where l.lang_code=a.alias;
\r
936 DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
\r
939 FETCH cur into alias,lang;
\r
943 SELECT ProcessLang(alias,lang) INTO dummystr;
\r
948 /*!50003 SET sql_mode = @saved_sql_mode */ ;
949 /*!50003 SET character_set_client = @saved_cs_client */ ;
950 /*!50003 SET character_set_results = @saved_cs_results */ ;
951 /*!50003 SET collation_connection = @saved_col_connection */ ;
952 /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
954 /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
955 /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
956 /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
957 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
958 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
959 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
960 /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
962 -- Dump completed on 2016-05-19 23:04:13