commit | author | age
|
ced309
|
1 |
<?php |
JK |
2 |
if(php_sapi_name() !== 'cli') die(); |
|
3 |
|
|
4 |
include('stops.php'); |
|
5 |
include('common.php'); |
|
6 |
|
|
7 |
$pdo = new PDO('sqlite:stops_temp.db'); |
|
8 |
|
|
9 |
$pdo->query('DROP TABLE IF EXISTS stop_search'); |
|
10 |
$pdo->query('CREATE TABLE stop_search ( |
|
11 |
word VARCHAR(60), |
cbce8b
|
12 |
id VARCHAR(255) |
ced309
|
13 |
)'); |
cbce8b
|
14 |
|
JK |
15 |
function processStops($st, $stops) { |
|
16 |
foreach($stops as $id => $name) { |
|
17 |
foreach(split_stop_name($name) as $word) { |
|
18 |
$st->execute([$word, $id]); |
|
19 |
$st->closeCursor(); |
|
20 |
} |
|
21 |
} |
|
22 |
} |
ced309
|
23 |
|
JK |
24 |
$pdo->beginTransaction(); |
|
25 |
$st = $pdo->prepare('INSERT INTO stop_search (word, id) VALUES (?, ?)'); |
cbce8b
|
26 |
processStops($st, $stops); |
ced309
|
27 |
$pdo->commit(); |
JK |
28 |
|
|
29 |
$pdo->query('CREATE INDEX stop_search_word ON stop_search (word COLLATE NOCASE)'); |
|
30 |
|
|
31 |
rename('stops_temp.db', 'stops.db'); |