Exemple #1
0
function convert_authors($mysql_db, $sqlite_db, $min)
{
    $sqlite_db->query("begin transaction;");
    $sqlite_db->query("DELETE FROM authors");
    $sqltest = "\n\tSELECT libavtorname.aid, libavtorname.FirstName, libavtorname.LastName, libavtorname.MiddleName, COUNT(libavtor.bid) as Number\n\tFROM libavtors AS libavtorname INNER JOIN (\n\t  SELECT DISTINCT libavtor.aid, libavtor.bid\n\t  FROM libavtor INNER JOIN libbook ON libbook.bid=libavtor.bid AND libavtor.role = 'a'\n\t) AS libavtor ON libavtorname.aid=libavtor.aid \n    WHERE libavtorname.aid>{$min}\n\tGROUP BY libavtorname.aid, libavtorname.FirstName, libavtorname.LastName, libavtorname.MiddleName\n  ";
    $char_list = 'А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ы Э Ю Я A B C D E F G H I J K L M N O P Q R S T U V W X Y Z';
    $query = $mysql_db->query($sqltest);
    while ($row = $query->fetch_array()) {
        $full_name = trim($row['LastName']) . " " . trim($row['FirstName']) . " " . trim($row['MiddleName']);
        $full_name = str_replace("  ", " ", $full_name);
        $search_name = strtolowerEx($full_name);
        $letter = utf8_substr($full_name, 0, 1);
        $letter = strtoupperEx($letter, 0, 1);
        if (strpos($char_list, $letter) === false) {
            $letter = "#";
        }
        echo "Auth: " . $row['aid'] . " - " . $letter . " - " . $full_name . " - " . $search_name . "\n";
        $sql = "INSERT INTO authors (id, number, letter, full_name, search_name, first_name, middle_name, last_name) VALUES(?,?,?,?,?,?,?,?)";
        $insert = $sqlite_db->prepare($sql);
        if ($insert === false) {
            $err = $dbh->errorInfo();
            die($err[2]);
        }
        $err = $insert->execute(array($row['aid'], $row['Number'], $letter, $full_name, $search_name, trim($row['FirstName']), trim($row['MiddleName']), trim($row['LastName'])));
        if ($err === false) {
            $err = $dbh->errorInfo();
            die($err[2]);
        }
        $insert->closeCursor();
    }
    $sqlite_db->query("commit;");
}
Exemple #2
0
function letter($string)
{
    $char_list = 'А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ы Э Ю Я A B C D E F G H I J K L M N O P Q R S T U V W X Y Z';
    $letter = utf8_substr($string, 0, 1);
    $letter = strtoupperEx($letter, 0, 1);
    if (strpos($char_list, $letter) === false) {
        $letter = "#";
    }
    return $letter;
}
Exemple #3
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");
}