added error handling for search

main
fuzzykitten 2025-06-05 13:22:27 -04:00
parent 5aee05fcde
commit 81b15d641c
1 changed files with 20 additions and 12 deletions

View File

@ -64,7 +64,8 @@ function fulltext_search($db, $settings, $text)
} }
$text = implode(' ', $new_text); $text = implode(' ', $new_text);
$results = array();
$db->exec('DROP TABLE search'); $db->exec('DROP TABLE search');
$db->exec('CREATE VIRTUAL TABLE IF NOT EXISTS search $db->exec('CREATE VIRTUAL TABLE IF NOT EXISTS search
@ -74,17 +75,24 @@ function fulltext_search($db, $settings, $text)
SELECT sub, text, name, post_id, org_id, shadow SELECT sub, text, name, post_id, org_id, shadow
FROM threads'); FROM threads');
$statement = $db->prepare("SELECT DISTINCT sub, text, name, post_id, org_id try {
FROM search $db->enableExceptions(true);
WHERE text MATCH ? $statement = $db->prepare("SELECT DISTINCT sub, text, name,
AND shadow = 'no' post_id, org_id
ORDER BY rank"); FROM search
WHERE text MATCH ?
$statement->bindParam(1, $text); AND shadow = 'no'
$result = $statement->execute(); ORDER BY rank");
$results = array(); $statement->bindParam(1, $text);
$result = $statement->execute();
} catch (Exception $fault) {
echo "The search: \"$text\" produced an error: "
. $fault->getMessage()
. " <br>Please go back to try again.";
quit($db, '');
}
while ($row = $result->fetchArray(SQLITE3_NUM)) { while ($row = $result->fetchArray(SQLITE3_NUM)) {
$search = array(); $search = array();
$search['0'] = "{$row[0]}"; $search['0'] = "{$row[0]}";