Implement prepare

This commit is contained in:
김선우
2025-01-17 22:48:04 +09:00
parent b77bf879f7
commit 9765eaba52
6 changed files with 36 additions and 51 deletions

View File

@@ -78,31 +78,6 @@ public abstract class AbstractDB {
*/
public abstract long connect() throws SQLException;
// /**
// * Compiles an SQL statement.
// *
// * @param stmt The SQL statement to compile.
// * @throws SQLException if a database access error occurs.
// */
// public final void prepare(CoreStatement stmt) throws SQLException {
// if (stmt.sql == null) {
// throw new SQLException("Statement must not be null");
// }
//
// // TODO: check whether closing the pointer and replacing stamt.pointer should work atomically using locks etc
// final SafeStatementPointer pointer = stmt.getStmtPointer();
// if (pointer != null) {
// pointer.close();
// }
//
// final SafeStatementPointer newPointer = stmt.connection.prepare(stmt.sql);
// stmt.setStmtPointer(newPointer);
// final boolean added = statementPointerSet.add(newPointer);
// if (!added) {
// throw new IllegalStateException("The pointer is already added to statements set");
// }
// }
/**
* Destroys a statement.
*

View File

@@ -93,7 +93,7 @@ public final class LimboDB extends AbstractDB {
byte[] filePathBytes = stringToUtf8ByteArray(filePath);
if (filePathBytes == null) {
throw LimboExceptionUtils.buildLimboException(LimboErrorCode.LIMBO_ETC.code, "File name cannot be converted to byteArray. File name: " + filePath);
throw LimboExceptionUtils.buildLimboException(LimboErrorCode.LIMBO_ETC.code, "File path cannot be converted to byteArray. File name: " + filePath);
}
dbPointer = openUtf8(filePathBytes, openFlags);
@@ -102,7 +102,11 @@ public final class LimboDB extends AbstractDB {
@Override
public long connect() throws SQLException {
return connect0(ByteArrayUtils.stringToUtf8ByteArray(filePath), dbPointer);
byte[] filePathBytes = stringToUtf8ByteArray(filePath);
if (filePathBytes == null) {
throw LimboExceptionUtils.buildLimboException(LimboErrorCode.LIMBO_ETC.code, "File path cannot be converted to byteArray. File name: " + filePath);
}
return connect0(filePathBytes, dbPointer);
}
private native long connect0(byte[] path, long databasePtr) throws SQLException;

View File

@@ -1,6 +1,7 @@
package org.github.tursodatabase.jdbc4;
import org.github.tursodatabase.TestUtils;
import org.github.tursodatabase.core.LimboConnection;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -55,4 +56,12 @@ class JDBC4ConnectionTest {
connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, -1);
});
}
@Test
void prepare_simple_create_table() throws Exception {
String filePath = TestUtils.createTempFile();
String url = "jdbc:sqlite:" + filePath;
LimboConnection connection = new JDBC4Connection(url, filePath);
connection.prepare("CREATE TABLE users (id INT PRIMARY KEY, username TEXT)");
}
}