Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: setDate select query #227

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,11 @@ public void setDate(int i, Date date)
if (date == null) {
batchInsertUtils.ifPresent(insertUtils -> insertUtils.setPlaceHolderValue(i, null));
} else {
batchInsertUtils.ifPresent(insertUtils -> insertUtils.setPlaceHolderValue(i, toDateLiteral(date)));
if (originalSql.toLowerCase().startsWith("select")) {
batchInsertUtils.ifPresent(insertUtils -> insertUtils.setPlaceHolderValue(i, String.format("%s%s%s", "'", date, "'")));
} else {
batchInsertUtils.ifPresent(insertUtils -> insertUtils.setPlaceHolderValue(i, toDateLiteral(date)));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public void testQueryUpdateCount()
}
}


@Test(groups = {"IT"})
public void testBasicWithProperties() throws SQLException {
Properties p = new Properties();
Expand All @@ -185,6 +186,7 @@ public void testBasicWithProperties() throws SQLException {
p.setProperty("max_rows_per_page", "100");
p.setProperty("user", "databend");
p.setProperty("password", "databend");

//INFO databend_query::servers::http::v1::http_query_handlers: receive http query: HttpQueryRequest { session_id: None, session: Some(HttpSessionConf { database: Some("test_basic_driver"), keep_server_session_secs: None, settings: None }), sql: "SELECT 1", pagination: PaginationConf { wait_time_secs: 10, max_rows_in_buffer: 100, max_rows_per_page: 100 }, string_fields: true, stage_attachment: None }
try (Connection connection = createConnection("test_basic_driver", p)) {
PaginationOptions options = connection.unwrap(DatabendConnection.class).getPaginationOptions();
Expand Down Expand Up @@ -265,10 +267,12 @@ public void testResultException() {
public void testSelectWithPreparement()
throws SQLException {
try (Connection connection = createConnection()) {
connection.createStatement().execute("create or replace table test_basic_driver.table_time(t timestamp)");
connection.createStatement().execute("insert into test_basic_driver.table_time values('2021-01-01 00:00:00')");
PreparedStatement statement = connection.prepareStatement("SELECT * from test_basic_driver.table_time where t < ?");
connection.createStatement().execute("create or replace table test_basic_driver.table_time(t timestamp, d date, ts timestamp)");
connection.createStatement().execute("insert into test_basic_driver.table_time values('2021-01-01 00:00:00', '2021-01-01', '2021-01-01 00:00:00')");
PreparedStatement statement = connection.prepareStatement("SELECT * from test_basic_driver.table_time where t < ? and d < ? and ts < ?");
statement.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
statement.setDate(2, new Date(System.currentTimeMillis()));
statement.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
ResultSet r = statement.executeQuery();
r.next();
Assert.assertEquals(r.getString(1), "2021-01-01 00:00:00.000000");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ public void testSelectWithClusterKey() throws SQLException {
try (PreparedStatement statement = conn.prepareStatement(selectSQL)) {
ResultSet rs = statement.executeQuery();
while (rs.next()) {
Assertions.assertEquals("NaN", rs.getString(5));
Assertions.assertEquals("0.0", rs.getString(5));
}
}
}
Expand Down
Loading