sqlite-jdbc icon indicating copy to clipboard operation
sqlite-jdbc copied to clipboard

Support open and connection to memory DB based on given bytes

Open wyalchemy opened this issue 3 months ago • 7 comments

Is your feature request related to a problem? Please describe. N/A. The is just an enhancement request to JDBC driver.

Describe the solution you'd like Currently the driver seems does not support open and connect to a memeory DB which is based on given byte[] (The byte[] comes from already ready DB content from somewhere else. With which, the DB is ready to query), but only support open and connect to brand new memory DB(it is empty, has nothing in it yet). We have an application which already reads DB content as byte[] already and the size is OK to be in memory. We expect we can directly use that already ready bytes to open the DB and connect to it to do query. The existing code about open an DB from file or other source does get related byte[] and then open it. But just no public interface to directly support open DB and connect to it based on given byte[]. I guess support open and connect to a memory DB based on existing byte[] should be easy.

Describe alternatives you've considered No

Additional context NO

wyalchemy avatar Nov 19 '25 03:11 wyalchemy

The driver uses the SQLite C library to perform the connection, i don't think this is supported in sqlite, but i may be wrong.

We have an application which already reads DB content as byte[] already and the size is OK to be in memory. We expect we can directly use that already ready bytes to open the DB and connect to it to do query.

What library does this application uses ?

gotson avatar Nov 19 '25 05:11 gotson

Thanks for the reply! The java JDBC driver jar from maven repository is used by the application. Not sure if something can be done in java code showing below to achieve what we expect? The source from src\main\java\org\sqlite\core\NativeDB.java

// WRAPPER FUNCTIONS ////////////////////////////////////////////

/** @see org.sqlite.core.DB#_open(java.lang.String, int) */
@Override
protected synchronized void _open(String file, int openFlags) throws SQLException {
    _open_utf8(stringToUtf8ByteArray(file), openFlags);
}

synchronized native void _open_utf8(byte[] fileUtf8, int openFlags) throws SQLException;

发件人: Gauthier @.> 发送时间: 2025年11月19日 13:30 收件人: xerial/sqlite-jdbc @.> 抄送: Daniel Wang @.>; Author @.> 主题: Re: [xerial/sqlite-jdbc] Support open and connection to memory DB based on given bytes (Issue #1352)

[https://avatars.githubusercontent.com/u/2139133?s=20&v=4]gotson left a comment (xerial/sqlite-jdbc#1352)https://github.com/xerial/sqlite-jdbc/issues/1352#issuecomment-3550878541

The driver uses the SQLite C library to perform the connection, i don't think this is supported in sqlite, but i may be wrong.

We have an application which already reads DB content as byte[] already and the size is OK to be in memory. We expect we can directly use that already ready bytes to open the DB and connect to it to do query.

What library does this application uses ?

― Reply to this email directly, view it on GitHubhttps://github.com/xerial/sqlite-jdbc/issues/1352#issuecomment-3550878541, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AE23A37ZJKB3FQA6RXP2CIT35P565AVCNFSM6AAAAACMQZDV5GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTKNJQHA3TQNJUGE. You are receiving this because you authored the thread.Message ID: @.***>

wyalchemy avatar Nov 19 '25 06:11 wyalchemy

Not sure if something can be done in java code showing below to achieve what we expect?

as i said we use the SQLite library to connect to the DB, this is not handled in our driver.

I don't see any way from SQLite to open an in-memory database with pre-populated data: https://sqlite.org/inmemorydb.html

gotson avatar Nov 19 '25 06:11 gotson

If this cannot be done in JDBC driver, is that possible to request CQLite C lib to support my request first and then jdbc driver can support it?


发件人: Gauthier @.> 发送时间: 2025年11月19日 14:29 收件人: xerial/sqlite-jdbc @.> 抄送: Daniel Wang @.>; Author @.> 主题: Re: [xerial/sqlite-jdbc] Support open and connection to memory DB based on given bytes (Issue #1352)

[https://avatars.githubusercontent.com/u/2139133?s=20&v=4]gotson left a comment (xerial/sqlite-jdbc#1352)https://github.com/xerial/sqlite-jdbc/issues/1352#issuecomment-3551011469

Not sure if something can be done in java code showing below to achieve what we expect?

as i said we use the SQLite library to connect to the DB, this is not handled in our driver.

I don't see any way from SQLite to open an in-memory database with pre-populated data: https://sqlite.org/inmemorydb.html

― Reply to this email directly, view it on GitHubhttps://github.com/xerial/sqlite-jdbc/issues/1352#issuecomment-3551011469, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AE23A3YJUVRNCPOHJDFOSG335QE3RAVCNFSM6AAAAACMQZDV5GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTKNJRGAYTCNBWHE. You are receiving this because you authored the thread.Message ID: @.***>

wyalchemy avatar Nov 19 '25 06:11 wyalchemy

If this cannot be done in JDBC driver, is that possible to request CQLite C lib to support my request first and then jdbc driver can support it?

you can ask them yes, we won't be doing it for you

gotson avatar Nov 19 '25 07:11 gotson

Hi gotson, Please see https://sqlite.org/forum/forumpost/ae6eeb7454 It seems that there is a way to support what I request by using "The C API Nuno linked". Please have a look.

wyalchemy avatar Dec 01 '25 08:12 wyalchemy

I reopened the issue, if anyone is willing to send a PR we could look at it.

gotson avatar Dec 02 '25 00:12 gotson