B4J Question In Memory SQLite Database

AKJammer

Active Member
Licensed User
Hopefully this is a quick question. I'm trying to do some array processing and sorting and think it would be easier to do this within a database environment, but don't want to have to go back to the mySql server for this temporary stuff. I think an in memory SQLite connection would work just fine. Looking in the forums it looks it's possible, but there aren't really any examples for B4J, just basic Java, which I'm not really familiar with. I've looked at this link https://bitbucket.org/xerial/sqlite-jdbc/wiki/Usage and see basically what needs to be done, but how do you do that in the context of B4J? To initialize SQLite, you have to pass over folders and filenames, but that's not what's needed. Anyone with a B4J code snippet on initializing an In Memory database?

Thanks,
Jim
 

AKJammer

Active Member
Licensed User
Hey Klaus,
I looked there but it doesn't talk about initializing in Memory, only has a standard file database.

B4X:
B4J
Add the line below in Main module #Region Project Attributes.
#AdditionalJar: sqlite-jdbc-3.7.2
And:
SQL1.InitializeSQLite(DBDirName, DBFileName, True)
DBDirName = Directory name of the database.
DBFileName = Database file name.
True = Create if necessary False don't create the database.
SQL1.InitializeSQLite(DBDirName, DBFileName, True)
In B4J, SQL1.Initialize is used to initialize SQL drivers.
To use SQLite, you must initialize it with SQL1.InitializeSQLite.

I don't want to use a directory name, file name. I tried putting null in there, but it balks at that.

DBUtils has a ExecuteMemoryTable method, but that's for reading from a standard database and putting it into an array list. Not actually what's needed here.

Jim
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
From Erel's B4xTable.b4xlib:

B4X:
    #if B4J
    sql1.InitializeSQLite("", ":memory:", True)
    #Else If B4A OR B4I
    sql1.Initialize("", ":memory:", True)
    #End If

Try whichever flavour you need.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
@AKJammer
Sorry, I hadn't read your post carefully enough.
I didn't notice that you want to create the DB only internally without saving it outsides the program.

@stevel05
From Erel's B4xTable.b4xlib:
I had never seen this sql1.InitializeSQLite("", ":memory:", True), will add it in the B4X SQLite Database booklet.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I had never seen this sql1.InitializeSQLite("", ":memory:", True)
No I hadn't either, I just remembered that the B4xTable used in memory SQLite and went looking.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
No I hadn't either, I just remembered that the B4xTable used in memory SQLite and went looking.
That's what I intended to do just before rereading your post, and I saw that you already had done it !
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…