Skip to content

Commit f0178d2

Browse files
committed
* db: support postgres enum type
Signed-off-by: neo <1100909+neowu@users.noreply.github.com>
1 parent 730ef9f commit f0178d2

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Change log
22

3+
### 9.2.3 (7/2/2025 - )
4+
5+
* db: support postgres enum type
6+
37
### 9.2.2 (5/21/2025 - 6/26/2025)
48

59
* http_client: support proxy

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ apply(plugin = "project")
77

88
subprojects {
99
group = "core.framework"
10-
version = "9.2.2"
10+
version = "9.2.3"
1111
repositories {
1212
maven {
1313
url = uri("https://neowu.github.io/maven-repo/")

core-ng/src/main/java/core/framework/internal/db/DatabaseImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ void track(long elapsed, int readRows, int writeRows, int queries) {
314314
}
315315

316316
void validateSQL(String sql) {
317+
if (sql.startsWith("CREATE ")) return; // ignore DDL
318+
317319
// validate asterisk
318320
// execute() could have select part, e.g. insert into select
319321
int index = sql.indexOf('*');

core-ng/src/main/java/core/framework/internal/db/DatabaseOperation.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,13 @@ private void setParams(PreparedStatement statement, Object... params) throws SQL
217217
private void setParam(PreparedStatement statement, int index, Object param) throws SQLException {
218218
switch (param) {
219219
case String value -> statement.setString(index, value);
220-
case Enum<?> value -> statement.setString(index, enumMapper.getDBValue(value));
220+
case Enum<?> value -> {
221+
if (dialect == Dialect.POSTGRESQL) {
222+
statement.setObject(index, enumMapper.getDBValue(value), Types.OTHER);
223+
} else {
224+
statement.setString(index, enumMapper.getDBValue(value));
225+
}
226+
}
221227
case LocalDate value -> statement.setObject(index, value, Types.DATE);
222228
case LocalDateTime value -> statement.setObject(index, value, Types.TIMESTAMP);
223229
case ZonedDateTime value -> {

core-ng/src/test/java/core/framework/internal/db/DatabaseImplTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ void validateSQL() {
127127
.hasMessageContaining("sql must not contain single quote(')");
128128
}
129129

130+
@Test
131+
void validateSQLWithDDL() {
132+
database.validateSQL("""
133+
CREATE TYPE status AS ENUM ('ACTIVE', 'INACTIVE')""");
134+
}
135+
130136
@Test
131137
void validateSQLWithAsterisk() {
132138
database.validateSQL("select column * 10 from table");

0 commit comments

Comments
 (0)