Skip to content

Comments

Fix parameter order bug in WHERE clause with :in operator#147

Merged
tamurashingo merged 2 commits intodevelopfrom
fix/parameter-order-bug
Feb 4, 2026
Merged

Fix parameter order bug in WHERE clause with :in operator#147
tamurashingo merged 2 commits intodevelopfrom
fix/parameter-order-bug

Conversation

@tamurashingo
Copy link
Owner

Summary

Fixed a bug where SQL parameters were incorrectly ordered when WHERE clause contained both :in operator and other comparison operators. The :in values were placed first, followed by other parameters, which was opposite to their appearance order in the WHERE clause.

Changes

  • Modified generate-query method in src/model/query.lisp to maintain parameter order
  • Changed parameter processing from 2-phase (collect :in first, then regular) to single-phase (collect all in order)
  • Added test cases to verify correct parameter ordering for single table queries, JOIN queries, and multiple IN clauses

Test Results

All tests pass with parameters in correct WHERE clause order:

  • Single table: WHERE (col1 = ? AND col2 = ? AND col3 IN (?, ?, ?))("val1" "val2" 1 2 3)
  • Multiple IN clauses: WHERE (col1 = ? AND col2 IN (?, ?) AND col3 = ? AND col4 IN (?, ?, ?))("val1" 100 200 5 10 20 30)

Related Issue

fix #146

- Add test case to reproduce parameter order bug
- Single table query test: parameters with :in are placed first incorrectly
- JOIN query test: parameters with :in are placed first incorrectly
- Expected: parameters in WHERE clause order
- Actual: :in values first, then other parameters
- Add migration for test tables (todo, tag, todo_tags)
- Add test to clails-test.asd
- Add CLAILS_MIGRATION_DIR_0013 to CI configuration
Fixed the issue where parameters in WHERE clause with :in operator
were ordered incorrectly. Previously, :in values were added first,
followed by regular parameters, which was opposite to their
appearance order in the WHERE clause.

Changes:
- Modified generate-query method in src/model/query.lisp
- Collect all parameter specs (both :in-expansion and regular) in order
- Process parameters sequentially to maintain WHERE clause order
- Add test case for multiple IN clauses with mixed parameters

Test results:
- Single table query: parameters in correct order
- JOIN query: parameters in correct order
- Multiple IN clauses: parameters in correct order
@tamurashingo tamurashingo merged commit b7041d4 into develop Feb 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: WHERE clause parameter order is incorrect when using :IN with other parameters

1 participant