Fix MariaDB LIMIT/OFFSET bound-parameter error in corpus API
MariaDB rejects ? placeholders for LIMIT/OFFSET when emulate_prepares=false. Interpolate $limit and $offset as ints directly into SQL strings in both corpus-documents.php and corpus-search.php BM25 paths. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -53,11 +53,8 @@ try {
|
||||
$countStmt->execute($countParams);
|
||||
$total = (int)$countStmt->fetchColumn();
|
||||
|
||||
// Paginated rows
|
||||
$dataParams = $params;
|
||||
$dataParams[] = $limit;
|
||||
$dataParams[] = $offset;
|
||||
$dataStmt = $ragDb->prepare(
|
||||
// Paginated rows — LIMIT/OFFSET interpolated as ints (MariaDB rejects bound params here)
|
||||
$dataStmt = $ragDb->prepare(
|
||||
"SELECT d.id, d.title, d.category, d.source_url, d.language, d.updated_at,
|
||||
COUNT(c.id) AS chunk_count
|
||||
FROM documents d
|
||||
@@ -65,9 +62,9 @@ try {
|
||||
WHERE $whereStr
|
||||
GROUP BY d.id
|
||||
ORDER BY d.updated_at DESC
|
||||
LIMIT ? OFFSET ?"
|
||||
LIMIT $limit OFFSET $offset"
|
||||
);
|
||||
$dataStmt->execute($dataParams);
|
||||
$dataStmt->execute($params);
|
||||
$documents = $dataStmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Normalise chunk_count to int
|
||||
|
||||
@@ -59,10 +59,9 @@ try {
|
||||
AND d.source_url NOT LIKE ?
|
||||
$catClause
|
||||
ORDER BY score DESC
|
||||
LIMIT ?";
|
||||
LIMIT $limit";
|
||||
$params = [$query, 1, $query, $excludeLike];
|
||||
if ($category !== null) $params[] = $category;
|
||||
$params[] = $limit;
|
||||
$stmt = $ragDb->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
@@ -80,11 +79,10 @@ try {
|
||||
AND d.source_url NOT LIKE ?
|
||||
$catClause
|
||||
ORDER BY (d.title LIKE ?) DESC
|
||||
LIMIT ?";
|
||||
LIMIT $limit";
|
||||
$params = [1, $like, $like, $excludeLike];
|
||||
if ($category !== null) $params[] = $category;
|
||||
$params[] = $like;
|
||||
$params[] = $limit;
|
||||
$stmt = $ragDb->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
Reference in New Issue
Block a user