Board_stroke::history clause placeholders follow positional bind order
Browse files at this commitbc532b95e643198219e088442065d95841c89183Parent: eb3efbe- fix
- board_stroke::history clause placeholders follow positional bind order
1 changed file +13 -8
- src/db/board_stroke.rs +13 -8
src/db/board_stroke.rsmodified+13 -8
| @@ -216,8 +216,8 @@ pub async fn clear(db: &Database, board: &BoardId, by: &UserId) -> Result<BoardS | ||
| 216 | 216 | .execute(&mut *conn) |
| 217 | 217 | .await?; |
| 218 | 218 | 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. | |
| 221 | 221 | return Err(AppError::Internal(CLEAR_REFUSED.to_string())); |
| 222 | 222 | } |
| 223 | 223 | let marker = sqlx::query_as!( |
| @@ -304,18 +304,23 @@ pub async fn history( | ||
| 304 | 304 | limit: Option<i64>, |
| 305 | 305 | offset: i64, |
| 306 | 306 | ) -> 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) => ("", ""), | |
| 310 | 316 | }; |
| 311 | - let kinds = if marks_only { " AND kind != $3" } else { "" }; | |
| 312 | 317 | let mut list = PagedList::new( |
| 313 | 318 | format!("board_stroke WHERE board = $1{scope}{kinds}"), |
| 314 | 319 | "ORDER BY id", |
| 315 | 320 | ) |
| 316 | 321 | .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); | |
| 319 | 324 | } |
| 320 | 325 | if marks_only { |
| 321 | 326 | list = list.bind(KIND_CLEAR.to_string()); |