Implement bindXXX functions on rust and java side

This commit is contained in:
김선우
2025-02-07 11:25:23 +09:00
parent d574e2c277
commit 21d6f33c6b
3 changed files with 306 additions and 16 deletions

View File

@@ -1,7 +1,9 @@
package org.github.tursodatabase.core;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Properties;
@@ -41,9 +43,80 @@ class LimboStatementTest {
final LimboResultSet rs = stmt.getResultSet();
final String[] columnNames = rs.getColumnNames();
assertEquals(columnNames[0], "name");
assertEquals(columnNames[1], "age");
assertEquals(columnNames[2], "country");
assertEquals("name", columnNames[0]);
assertEquals("age", columnNames[1]);
assertEquals("country", columnNames[2]);
}
@Test
void test_bindNull() throws Exception {
runSql("CREATE TABLE test (col1 TEXT);");
LimboStatement stmt = connection.prepare("INSERT INTO test (col1) VALUES (?);");
stmt.bindNull(1);
stmt.execute();
stmt.close();
LimboStatement selectStmt = connection.prepare("SELECT col1 FROM test;");
selectStmt.execute();
assertNull(selectStmt.getResultSet().get(1));
selectStmt.close();
}
@Test
void test_bindLong() throws Exception {
runSql("CREATE TABLE test (col1 BIGINT);");
LimboStatement stmt = connection.prepare("INSERT INTO test (col1) VALUES (?);");
stmt.bindLong(1, 123456789L);
stmt.execute();
stmt.close();
LimboStatement selectStmt = connection.prepare("SELECT col1 FROM test;");
selectStmt.execute();
assertEquals(123456789L, selectStmt.getResultSet().get(1));
selectStmt.close();
}
@Test
void test_bindDouble() throws Exception {
runSql("CREATE TABLE test (col1 DOUBLE);");
LimboStatement stmt = connection.prepare("INSERT INTO test (col1) VALUES (?);");
stmt.bindDouble(1, 3.14);
stmt.execute();
stmt.close();
LimboStatement selectStmt = connection.prepare("SELECT col1 FROM test;");
selectStmt.execute();
assertEquals(3.14, selectStmt.getResultSet().get(1));
selectStmt.close();
}
@Test
void test_bindText() throws Exception {
runSql("CREATE TABLE test (col1 TEXT);");
LimboStatement stmt = connection.prepare("INSERT INTO test (col1) VALUES (?);");
stmt.bindText(1, "hello");
stmt.execute();
stmt.close();
LimboStatement selectStmt = connection.prepare("SELECT col1 FROM test;");
selectStmt.execute();
assertEquals("hello", selectStmt.getResultSet().get(1));
selectStmt.close();
}
@Test
void test_bindBlob() throws Exception {
runSql("CREATE TABLE test (col1 BLOB);");
LimboStatement stmt = connection.prepare("INSERT INTO test (col1) VALUES (?);");
byte[] blob = {1, 2, 3, 4, 5};
stmt.bindBlob(1, blob);
stmt.execute();
stmt.close();
LimboStatement selectStmt = connection.prepare("SELECT col1 FROM test;");
selectStmt.execute();
assertArrayEquals(blob, (byte[]) selectStmt.getResultSet().get(1));
selectStmt.close();
}
private void runSql(String sql) throws Exception {