Esempio n. 1
0
function convert_auth($mysql_db, $sqlite_db)
{
    $sqlite_db->query("begin transaction");
    $sqltest = "SELECT auth.aid, auth.name, book.num FROM auth \n\t\tINNER JOIN (SELECT aid, COUNT(bid) AS num FROM book GROUP BY aid) AS book ON book.aid=auth.aid";
    $query = $mysql_db->query($sqltest);
    while ($row = $query->fetch_array()) {
        echo $row['aid'] . " - " . $row['name'] . "\n";
        $full_name = trim($row['name']);
        $search_name = strtolowerEx($full_name);
        $letter = utf8_substr($full_name, 0, 1);
        $letter = strtoupperEx($letter, 0, 1);
        $sql = "INSERT INTO authors (id, number, letter, full_name, last_name, search_name) VALUES(?,?,?,?,?,?)";
        $insert = $sqlite_db->prepare($sql);
        $insert->execute(array($row['aid'], $row['num'], $letter, $full_name, $full_name, $search_name));
        $insert->closeCursor();
    }
    $query->close();
    $sqlite_db->query("commit");
}
Esempio n. 2
0
function convert_books($mysql_db, $sqlite_db, $min)
{
    $sqlite_db->query("begin transaction;");
    $sqlite_db->query("DELETE FROM books");
    $sqltest = "\n    SELECT \n      libbook.bid, FileSize, Title, Deleted, FileType, md5, DATE_FORMAT(libbook.Time,'%y%m%d') as Time, Lang, Year,\n      CASE WHEN aid IS NULL THEN 0 ELSE aid END AS aid,\n      CONCAT(libbook.bid, '.', libbook.FileType) AS FileName\n    FROM libbook \n      LEFT JOIN libavtor ON libbook.bid = libavtor.bid AND libavtor.role = 'a' AND libavtor.aid<>0\n    WHERE libbook.bid>{$min}\n  ";
    $query = $mysql_db->query($sqltest);
    while ($row = $query->fetch_array()) {
        echo "Book: " . $row['Time'] . " - " . $row['bid'] . " - " . $row['FileType'] . " - " . $row['aid'] . " - " . $row['Title'] . "\n";
        $id = $row['bid'];
        $genres = "";
        $subsql = "SELECT code FROM libgenre LEFT JOIN libgenrelist ON libgenre.gid = libgenrelist.gid WHERE bid={$id}";
        $subquery = $mysql_db->query($subsql);
        while ($subrow = $subquery->fetch_array()) {
            $genres = $genres . GenreCode($subrow['code']);
        }
        $deleted = NULL;
        if ($row['Deleted'] == 1) {
            $deleted = 1;
        }
        $file_type = trim($row['FileType']);
        $file_type = trim($file_type, ".");
        $file_type = strtolower($file_type);
        $file_type = strtolowerEx($file_type);
        $lang = $row['Lang'];
        $lang = strtolower($lang);
        $lang = strtolowerEx($lang);
        $rate = book_rate($mysql_db, $id);
        $sql = "INSERT INTO books (id, id_author, title, deleted, file_name, file_size, file_type, genres, created, lang, year, rate, md5sum) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";
        $insert = $sqlite_db->prepare($sql);
        if ($insert === false) {
            $err = $sqlite_db->errorInfo();
            die($err[2]);
        }
        $err = $insert->execute(array($id, $row['aid'], trim($row['Title']), $deleted, $row['FileName'], $row['FileSize'], $file_type, $genres, $row['Time'], $lang, $row['Year'], $rate, $row['md5']));
        if ($err === false) {
            $err = $sqlite_db->errorInfo();
            die($err[2]);
        }
        $insert->closeCursor();
    }
    $sqlite_db->query("commit;");
}