fix: 11141-JDBC override parameter for resolving TZ Cast Errors (#12821)
This commit is contained in:
parent
5b3f29a6bc
commit
c8f88ed977
|
|
@ -989,6 +989,15 @@ public class PostgresPlugin extends BasePlugin {
|
|||
urlBuilder.append(authentication.getDatabaseName());
|
||||
}
|
||||
|
||||
/**
|
||||
* JDBC connection parameter to auto resolve argument type when using prepared statements. Please note that this auto deduction of type happens only when
|
||||
* the argument is bound using `setString()` method. In our case, it means that we have identified the argument data type as String.
|
||||
* Quoting from doc:
|
||||
* If stringtype is set to unspecified, parameters will be sent to the server as untyped values, and the server will attempt to infer an appropriate type.
|
||||
* Ref: https://jdbc.postgresql.org/documentation/83/connect.html
|
||||
*/
|
||||
urlBuilder.append("?stringtype=unspecified");
|
||||
|
||||
/*
|
||||
* - Ideally, it is never expected to be null because the SSL dropdown is set to a initial value.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1300,6 +1300,50 @@ public class PostgresPluginTest {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreparedStatementWithTimeZoneTimeStamp() {
|
||||
DatasourceConfiguration dsConfig = createDatasourceConfiguration();
|
||||
|
||||
ActionConfiguration actionConfiguration = new ActionConfiguration();
|
||||
actionConfiguration.setBody("UPDATE public.\"users\" set " +
|
||||
"created_on_tz = {{createdTS}}\n" +
|
||||
" where id = 3;");
|
||||
|
||||
List<Property> pluginSpecifiedTemplates = new ArrayList<>();
|
||||
pluginSpecifiedTemplates.add(new Property("preparedStatement", "true"));
|
||||
actionConfiguration.setPluginSpecifiedTemplates(pluginSpecifiedTemplates);
|
||||
|
||||
ExecuteActionDTO executeActionDTO = new ExecuteActionDTO();
|
||||
List<Param> params = new ArrayList<>();
|
||||
params.add(new Param("createdTS", "2022-04-11T05:30:00Z"));
|
||||
|
||||
executeActionDTO.setParams(params);
|
||||
|
||||
Mono<HikariDataSource> connectionCreateMono = pluginExecutor.datasourceCreate(dsConfig).cache();
|
||||
|
||||
Mono<ActionExecutionResult> resultMono = connectionCreateMono
|
||||
.flatMap(pool -> pluginExecutor.executeParameterized(pool, executeActionDTO, dsConfig, actionConfiguration));
|
||||
|
||||
StepVerifier.create(resultMono)
|
||||
.assertNext(result -> {
|
||||
assertTrue(result.getIsExecutionSuccess());
|
||||
})
|
||||
.verifyComplete();
|
||||
|
||||
actionConfiguration.setBody("SELECT * FROM public.\"users\" where id = 3;");
|
||||
resultMono = connectionCreateMono
|
||||
.flatMap(pool -> pluginExecutor.executeParameterized(pool, executeActionDTO, dsConfig, actionConfiguration));
|
||||
|
||||
StepVerifier.create(resultMono)
|
||||
.assertNext(result -> {
|
||||
assertTrue(result.getIsExecutionSuccess());
|
||||
|
||||
final JsonNode node = ((ArrayNode) result.getBody()).get(0);
|
||||
assertEquals(node.get("created_on_tz").asText(), "2022-04-11T05:30:00Z"); //UTC time
|
||||
})
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
public void testReadOnlyMode() {
|
||||
DatasourceConfiguration dsConfig = createDatasourceConfiguration();
|
||||
dsConfig.getConnection().setMode(com.appsmith.external.models.Connection.Mode.READ_ONLY);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user