)
36 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Convert MySQL to SQLite
6 |
7 |
8 | Convert MySQL to SQLite
9 |
10 | - Version: 2.1.1 (2014-08-09)
11 | - Max-size: 10MB
12 | - Requirements: PHP5, JavaScript
13 | - GitHub
14 |
15 |
16 | Upload a MySQL dump file.
17 | Then you will get a sql file for SQLite3.
18 |
19 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/download.php:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
45 |
47 |
48 |
49 | Back
50 | filesize = '.filesize($upfile).'';
60 | } else {
61 | echo 'Failed to send a file.';
62 | }
63 | } else {
64 | echo 'File is not selected.';
65 | }
66 | ?>
67 |
68 |
69 |
--------------------------------------------------------------------------------
/src/transfer.php:
--------------------------------------------------------------------------------
1 | false,
51 | 'pos' => $_GET['pos']
52 | );
53 | fseek($fp1, $return['pos']);
54 |
55 | // 1度に処理するのは100行まで。
56 | //
57 | for ($i=0; ($line = fgets($fp1)) && ($i < 100); $i++) {
58 | // INSERT文の処理
59 | // phpMyAdminによるダンプの場合
60 | if (preg_match('/^(INSERT INTO \`[^\`]+\` )[\s\S]*VALUES$/ui', $line, $matches)) {
61 | $i++;
62 | $line = fgets($fp1);
63 |
64 | while (preg_match('/^([\s\S]+),$/u', $line, $matches2)) {
65 | $line = $matches[1].'VALUES'.$matches2[1].";\n";
66 | my_fwrite($fp2, $line);
67 |
68 | //次のループのための準備
69 | //※ ループの条件に適さないと、1行余分に読み込んだことになる。
70 | //このため、CREATE文よりも先にこの処理を記述しなければならない。
71 | $i++;
72 | $line = fgets($fp1);
73 | }
74 | if (preg_match('/;$/u', $line)) {
75 | $line = $matches[1].'VALUES'.$line."\n";
76 | my_fwrite($fp2, $line);
77 | }
78 | //INSERT文が終わったら、INSERT文以外の変換作業へ移る。
79 | }
80 | // 端末その他によるダンプの場合
81 | elseif (preg_match('/^(INSERT INTO \`[^\`]+\` VALUES\s?)([\s\S]*\);)$/ui', $line, $matches)) {
82 | while (preg_match_all('/^(\((?:(?:\'(?:(?:(?!\\\\).)?(?:(?:\\\\\\\\)*\\\\)\'|[^\'])*\'|[0-9]+|NULL),? ?)+\)), ?([\s\S]*)/ui', $matches[2], $matches2)) {
83 | $matches[2] = $matches2[2];
84 | $line = $matches[1].$matches2[1].";\n";
85 | my_fwrite($fp2, $line);
86 | }
87 | $line = $matches[1].$matches[2]."\n";
88 | my_fwrite($fp2, $line);
89 | }
90 |
91 | // CREATE文の処理
92 | if (preg_match('/^CREATE TABLE[\s\S]*(\`[^\`]+\`)/ui', $line, $matches)) {
93 | my_fwrite($fp2, "CREATE TABLE {$matches[1]} (\n");
94 |
95 | $i++;
96 | $line = fgets($fp1);
97 |
98 | $j = 0;
99 | while (!preg_match('/^\) ENGINE=/i', $line)) {
100 |
101 | // int系をintegerへ、AUTO_INCREMENTを削除する
102 | if (!preg_match('/^\s*UNIQUE KEY/ui', $line)) {
103 | // 以下の置換で行末のカンマを削除している。CREATE文が続くなら、カンマを復活させる。
104 | if ($j > 0) fwrite($fp2, ",\n");
105 | $j++;
106 |
107 | $line = preg_replace_callback('/^(\s*`[^`]+`\s*)(int|tinyint|samllint|mediumint|bigint)(?:\([^\)]+\))?|(AUTO_INCREMENT),?\\n$|(,\\n)$/ui', 'callback_create', $line);
108 | my_fwrite($fp2, $line);
109 | }
110 | $i++;
111 | $line = fgets($fp1);
112 | }
113 | // ") ENGINE=" の文は、ENGINE以降を削除
114 | fwrite($fp2, "\n);\n");
115 | $flag_create_table = false;
116 | }
117 | $return['pos'] = ftell($fp1);
118 | }
119 | $return['feof'] = feof($fp1);
120 | fclose($fp1);
121 | fclose($fp2);
122 | echo json_encode($return);
--------------------------------------------------------------------------------