mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-16 14:44:21 +01:00
Implement bindXXX functions on rust and java side
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user