forge
Explore
Log in

Don't you dare go Hollow

Board_stroke::history clause placeholders follow positional bind order

Browse files at this commit

bc532b95e643198219e088442065d95841c89183Ahmet Kaan GümüşParent: eb3efbe
  • fix
    • board_stroke::history clause placeholders follow positional bind order
Show full message
🐛 fix: board_stroke::history clause placeholders follow positional bind order
src/db/board_stroke.rsmodified+13 -8
@@ -216,8 +216,8 @@ pub async fn clear(db: &Database, board: &BoardId, by: &UserId) -> Result<BoardS
216216 .execute(&mut *conn)
217217 .await?;
218218 if bumped.rows_affected() != 1 {
219- // Unreachable under the row lock; the guard text is the old
220- // THROW marker, kept for the audit trail.
219+ // Unreachable under the row lock; the text is the old
220+ // refusal marker, kept for the audit trail.
221221 return Err(AppError::Internal(CLEAR_REFUSED.to_string()));
222222 }
223223 let marker = sqlx::query_as!(
@@ -304,18 +304,23 @@ pub async fn history(
304304 limit: Option<i64>,
305305 offset: i64,
306306 ) -> Result<(Vec<BoardStroke>, i64), AppError> {
307- let scope = match epoch {
308- Some(_) => " AND epoch = $2",
309- None => "",
307+ // The builder binds positionally in call order, so each optional clause
308+ // takes the placeholder number its position in the bind sequence gives
309+ // it — epoch (when present) is always $2, the marker filter $3 only
310+ // when the epoch clause is there too.
311+ let (scope, kinds) = match (epoch.is_some(), marks_only) {
312+ (true, true) => (" AND epoch = $2", " AND kind != $3"),
313+ (true, false) => (" AND epoch = $2", ""),
314+ (false, true) => ("", " AND kind != $2"),
315+ (false, false) => ("", ""),
310316 };
311- let kinds = if marks_only { " AND kind != $3" } else { "" };
312317 let mut list = PagedList::new(
313318 format!("board_stroke WHERE board = $1{scope}{kinds}"),
314319 "ORDER BY id",
315320 )
316321 .bind(board.uuid());
317- if epoch.is_some() {
318- list = list.bind(epoch.unwrap_or_default());
322+ if let Some(epoch) = epoch {
323+ list = list.bind(epoch);
319324 }
320325 if marks_only {
321326 list = list.bind(KIND_CLEAR.to_string());