This commit is contained in:
Looly 2025-10-24 21:11:42 +08:00
parent ce3d69dd35
commit 0cbc36e225
2 changed files with 19 additions and 5 deletions

View File

@ -1,12 +1,16 @@
package cn.hutool.db; package cn.hutool.db;
import java.sql.SQLException; import cn.hutool.core.lang.Console;
import cn.hutool.core.map.MapUtil;
import static org.junit.jupiter.api.Assertions.*; import cn.hutool.db.sql.NamedSql;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import cn.hutool.core.lang.Console; import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* PostgreSQL 单元测试 * PostgreSQL 单元测试
@ -46,4 +50,14 @@ public class PostgreTest {
Entity et=db.get(Entity.create("ctest").set("id", 1)); Entity et=db.get(Entity.create("ctest").set("id", 1));
assertEquals("new111",et.getStr("t1")); assertEquals("new111",et.getStr("t1"));
} }
@Test
@Disabled
void namedSqlWithInTest() throws SQLException {
final HashMap<String, Object> paramMap = MapUtil.of("number", new int[]{1, 2, 3});
NamedSql namedSql = new NamedSql("select case when 2 = any(ARRAY[:number]) and 1 in (1) then 1 else 0 end", paramMap);
final Db db = Db.use("postgre");
final List<Entity> query = db.query(namedSql.getSql(), namedSql.getParams());
Console.log(query);
}
} }

View File

@ -59,7 +59,7 @@ pass = 123456
remarks = true remarks = true
[postgre] [postgre]
url = jdbc:postgresql://looly.centos:5432/test_hutool url = jdbc:postgresql://localhost:5432/test_hutool
user = postgres user = postgres
pass = 123456 pass = 123456
remarks = true remarks = true