mybatis: MyBatis on Spring Boot 4.2.0 - annotation and XML mappers, result maps, dynamic SQL, PageHelper, @MybatisTest, seven real transcripts
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b3obqqePfZ9m2Jk5Ub
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
fc8bc933d5
commit
8d8c28e2e5
@@ -0,0 +1,59 @@
|
||||
## no filters: <where> disappears completely
|
||||
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p ORDER BY p.id
|
||||
==> Parameters:
|
||||
<== Total: 45
|
||||
|
||||
## only active = true: <where> appears, no stray AND
|
||||
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p WHERE p.active = ? ORDER BY p.id
|
||||
==> Parameters: true(Boolean)
|
||||
<== Total: 41
|
||||
|
||||
## name contains '1', price between 20 and 60
|
||||
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p WHERE p.name LIKE ? AND p.price >= ? AND p.price <= ? ORDER BY p.id
|
||||
==> Parameters: %1%(String), 20(BigDecimal), 60(BigDecimal)
|
||||
<== Total: 10
|
||||
|
||||
## categories 1 and 3, sorted by price desc (choose/when)
|
||||
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p WHERE p.category_id IN (?,?) ORDER BY p.price DESC, p.id
|
||||
==> Parameters: 1(Long), 3(Long)
|
||||
<== Total: 30
|
||||
|
||||
## empty category list is ignored, not turned into IN () (sorted by name so it is a new statement, not a cache hit)
|
||||
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p ORDER BY p.name, p.id
|
||||
==> Parameters:
|
||||
<== Total: 45
|
||||
|
||||
## findByIds([2, 4, 6]) -> foreach
|
||||
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p WHERE p.id IN ( ? , ? , ? ) ORDER BY p.id
|
||||
==> Parameters: 2(Long), 4(Long), 6(Long)
|
||||
<== Total: 3
|
||||
|
||||
## findByIds([]) -> foreach over an empty list produces 'IN' with nothing after it
|
||||
exception: BadSqlGrammarException
|
||||
root cause: JdbcSQLSyntaxErrorException - Syntax error in SQL statement "SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p\000a WHERE p.id IN\000a \000a [*]ORDER BY p.id"; expected "("; SQL statement:
|
||||
|
||||
## updateSelective with only stock set -> <set> writes just that column
|
||||
==> Preparing: UPDATE product SET stock = ? WHERE id = ?
|
||||
==> Parameters: 99(Integer), 2(Long)
|
||||
<== Updates: 1
|
||||
|
||||
## updateSelective with nothing set -> <set> has no content, the SQL is broken
|
||||
root cause: JdbcSQLSyntaxErrorException - Syntax error in SQL statement "UPDATE product\000a \000a [*]WHERE id = ?"; expected "., AS, SET"; SQL statement:
|
||||
|
||||
## insertAll -> one INSERT with two value tuples
|
||||
==> Preparing: INSERT INTO product(name, price, stock, active, category_id) VALUES (?, ?, ?, ?, ?) , (?, ?, ?, ?, ?)
|
||||
==> Parameters: A(String), 1.00(BigDecimal), 1(Integer), true(Boolean), 1(Long), B(String), 2.00(BigDecimal), 2(Integer), true(Boolean), 1(Long)
|
||||
<== Updates: 2
|
||||
generated ids written back: [46, 47]
|
||||
|
||||
## ${q} with q = zzz' OR '1'='1' OR name LIKE '
|
||||
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p WHERE p.name LIKE '%zzz' OR '1'='1' OR name LIKE '%' ORDER BY p.id
|
||||
==> Parameters:
|
||||
<== Total: 45
|
||||
rows returned: 45
|
||||
|
||||
## #{q} with q = zzz' OR '1'='1' OR name LIKE '
|
||||
==> Preparing: SELECT p.id, p.name, p.price, p.stock, p.active, p.category_id FROM product p WHERE p.name LIKE CONCAT('%', ?, '%') ORDER BY p.id
|
||||
==> Parameters: zzz' OR '1'='1' OR name LIKE '(String)
|
||||
<== Total: 0
|
||||
rows returned: 0
|
||||
Reference in New Issue
Block a user