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,10 +53,7 @@ try {
|
|||||||
$countStmt->execute($countParams);
|
$countStmt->execute($countParams);
|
||||||
$total = (int)$countStmt->fetchColumn();
|
$total = (int)$countStmt->fetchColumn();
|
||||||
|
|
||||||
// Paginated rows
|
// Paginated rows — LIMIT/OFFSET interpolated as ints (MariaDB rejects bound params here)
|
||||||
$dataParams = $params;
|
|
||||||
$dataParams[] = $limit;
|
|
||||||
$dataParams[] = $offset;
|
|
||||||
$dataStmt = $ragDb->prepare(
|
$dataStmt = $ragDb->prepare(
|
||||||
"SELECT d.id, d.title, d.category, d.source_url, d.language, d.updated_at,
|
"SELECT d.id, d.title, d.category, d.source_url, d.language, d.updated_at,
|
||||||
COUNT(c.id) AS chunk_count
|
COUNT(c.id) AS chunk_count
|
||||||
@@ -65,9 +62,9 @@ try {
|
|||||||
WHERE $whereStr
|
WHERE $whereStr
|
||||||
GROUP BY d.id
|
GROUP BY d.id
|
||||||
ORDER BY d.updated_at DESC
|
ORDER BY d.updated_at DESC
|
||||||
LIMIT ? OFFSET ?"
|
LIMIT $limit OFFSET $offset"
|
||||||
);
|
);
|
||||||
$dataStmt->execute($dataParams);
|
$dataStmt->execute($params);
|
||||||
$documents = $dataStmt->fetchAll(PDO::FETCH_ASSOC);
|
$documents = $dataStmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
// Normalise chunk_count to int
|
// Normalise chunk_count to int
|
||||||
|
|||||||
@@ -59,10 +59,9 @@ try {
|
|||||||
AND d.source_url NOT LIKE ?
|
AND d.source_url NOT LIKE ?
|
||||||
$catClause
|
$catClause
|
||||||
ORDER BY score DESC
|
ORDER BY score DESC
|
||||||
LIMIT ?";
|
LIMIT $limit";
|
||||||
$params = [$query, 1, $query, $excludeLike];
|
$params = [$query, 1, $query, $excludeLike];
|
||||||
if ($category !== null) $params[] = $category;
|
if ($category !== null) $params[] = $category;
|
||||||
$params[] = $limit;
|
|
||||||
$stmt = $ragDb->prepare($sql);
|
$stmt = $ragDb->prepare($sql);
|
||||||
$stmt->execute($params);
|
$stmt->execute($params);
|
||||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
@@ -80,11 +79,10 @@ try {
|
|||||||
AND d.source_url NOT LIKE ?
|
AND d.source_url NOT LIKE ?
|
||||||
$catClause
|
$catClause
|
||||||
ORDER BY (d.title LIKE ?) DESC
|
ORDER BY (d.title LIKE ?) DESC
|
||||||
LIMIT ?";
|
LIMIT $limit";
|
||||||
$params = [1, $like, $like, $excludeLike];
|
$params = [1, $like, $like, $excludeLike];
|
||||||
if ($category !== null) $params[] = $category;
|
if ($category !== null) $params[] = $category;
|
||||||
$params[] = $like;
|
$params[] = $like;
|
||||||
$params[] = $limit;
|
|
||||||
$stmt = $ragDb->prepare($sql);
|
$stmt = $ragDb->prepare($sql);
|
||||||
$stmt->execute($params);
|
$stmt->execute($params);
|
||||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|||||||
Reference in New Issue
Block a user