fix(jdbc): support non-transactional grid edits
This commit is contained in:
parent
163a588af8
commit
b150a8e99a
|
|
@ -62,6 +62,15 @@ const DATABASE_CAPABILITY_OVERRIDES: Partial<Record<DatabaseType, Partial<Databa
|
|||
transaction: true,
|
||||
},
|
||||
},
|
||||
jdbc: {
|
||||
tableData: {
|
||||
insert: false,
|
||||
updateRequiresPrimaryKey: true,
|
||||
deleteRequiresPrimaryKey: true,
|
||||
requiresTransactionalTableForExistingRows: false,
|
||||
transaction: false,
|
||||
},
|
||||
},
|
||||
neo4j: {
|
||||
syntheticKey: "neo4j-element-id",
|
||||
},
|
||||
|
|
|
|||
|
|
@ -65,6 +65,14 @@ test("describes table editing capabilities for special database engines", () =>
|
|||
transaction: false,
|
||||
});
|
||||
|
||||
assert.deepEqual(getDatabaseCapability("jdbc").tableData, {
|
||||
insert: false,
|
||||
updateRequiresPrimaryKey: true,
|
||||
deleteRequiresPrimaryKey: true,
|
||||
requiresTransactionalTableForExistingRows: false,
|
||||
transaction: false,
|
||||
});
|
||||
|
||||
assert.equal(getDatabaseCapability("oracle").syntheticKey, "oracle-rowid");
|
||||
assert.equal(getDatabaseCapability("neo4j").syntheticKey, "neo4j-element-id");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ test("allows Hive table data editing even without declared primary keys", () =>
|
|||
test("does not use transactional grid saves for Hive", () => {
|
||||
assert.equal(supportsDataGridTransaction("hive"), false);
|
||||
assert.equal(supportsDataGridTransaction("trino"), false);
|
||||
assert.equal(supportsDataGridTransaction("jdbc"), false);
|
||||
assert.equal(supportsDataGridTransaction("postgres"), true);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ public final class DbxJdbcPlugin {
|
|||
applyExecutionContext(connection, conn, database, schema);
|
||||
try (Statement statement = conn.createStatement()) {
|
||||
statement.setMaxRows(MAX_ROWS + 1);
|
||||
boolean hasResultSet = statement.execute(sql);
|
||||
boolean hasResultSet = statement.execute(trimStatementSql(sql));
|
||||
ObjectNode result = MAPPER.createObjectNode();
|
||||
ArrayNode columns = MAPPER.createArrayNode();
|
||||
ArrayNode rows = MAPPER.createArrayNode();
|
||||
|
|
@ -243,6 +243,10 @@ public final class DbxJdbcPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
private static String trimStatementSql(String sql) {
|
||||
return sql == null ? "" : sql.trim().replaceFirst(";\\s*$", "");
|
||||
}
|
||||
|
||||
private static void applyExecutionContext(JsonNode connection, Connection conn, String database, String schema) throws SQLException {
|
||||
if (driverQuirks(connection).skipExecutionContext()) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -47,6 +47,19 @@ final class DbxJdbcPluginTest {
|
|||
assertEquals("APP", response.path("result").path("rows").path(0).path(0).asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void executeQueryTrimsSingleTrailingSemicolon() throws Exception {
|
||||
JsonNode response = request("executeQuery", """
|
||||
{
|
||||
"connection": %s,
|
||||
"sql": "SELECT 1 AS n;"
|
||||
}
|
||||
""".formatted(CONNECTION));
|
||||
|
||||
assertFalse(response.has("error"), response.toString());
|
||||
assertEquals(1, response.path("result").path("rows").path(0).path(0).asInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void driverQuirksDetectYashanJdbcUrl() throws Exception {
|
||||
JsonNode yashan = MAPPER.readTree("""
|
||||
|
|
|
|||
Loading…
Reference in New Issue