Android Question SQLite db size null

gyruss68

Member
Licensed User
Longtime User
Hello Erel
I have a problem that is driving me crazy.
I created a database with sql lite expert and I copied the files in the Files folder
I used DBUtils to copy the file.

Dim db As SQL
As String Dim pathDb
pathDb = DBUtils.CopyDBFromAssets ("gpopsurvey.db")
The file is copied correctly (1.png)

but if I initialize the db
db.Initialize (File.DirDefaultExternal, "gpopsurvey.db", True)
the database is with 0 size and creates a .db.back file (2.png)

If I create the file directly
db.Initialize(File.DirDefaultExternal,"dbTest.db",True)
db.ExecNonQuery("CREATE TABLE giorni(ID INTEGER PRIMARY KEY,giorno DATE, inizio TIME,fine TIME,tot TEXT,note TEXT,costo DECIMAL)")
db.ExecNonQuery("CREATE TABLE setting(ID INTEGER PRIMARY KEY,formatdata text, formatvaluta text,costxhour int)")

everything is created correctly (3.png).

How can I solve this problem ?

I use B4A 5.8 and 1.3 sql library
 

Attachments

  • 1.png
    1.png
    66.8 KB · Views: 175
  • 2.png
    2.png
    82.7 KB · Views: 155
  • 3.png
    3.png
    109.7 KB · Views: 180
Last edited:

gyruss68

Member
Licensed User
Longtime User
Dim pathDb As String
pathDb = DBUtils.CopyDBFromAssets("gpopsurvey.db")
db.Initialize(pathDb,"gpopsurvey.db",False)

Error occurred on line: 47 (Main)
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:338)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:232)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:512)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:206)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:178)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:889)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:862)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:671)
at anywheresoftware.b4a.sql.SQL.Initialize(SQL.java:37)
at com.garrisonpop.gpopsurvey.main._activity_create(main.java:402)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at com.garrisonpop.gpopsurvey.main.afterFirstLayout(main.java:102)
at com.garrisonpop.gpopsurvey.main.access$000(main.java:17)
at com.garrisonpop.gpopsurvey.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:733)
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
try a regular copy instead of that dbutils one. maybe something locks that file.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
did you put a read only attribute on the file in windows?

or is the file not valid for some reason?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
It would appear that the SQLite implementation doesn't like the DB File, and when Create if necessary is set to true is creating a new one.

I have never used SQLite Expert, what version of SQLite is the file created for?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Thinking about it, I seem to remember that Android SQLite databases require an android_metadata table, is this created by SQ lite expert? That could be why it doesn't like the database.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
some devices don't support that SQLite3 or whatever version maybe it's that?

if it can't initialize it like it should it creates a new one.
 
Upvote 0

gyruss68

Member
Licensed User
Longtime User
I have created the same table with SqlLiteStudio.
The db is SqlLite version 3 ( the same of sql Expert Lite )
The error remain.

I have created a sqlLite versione 2 file , the error remain.
 
Upvote 0

gyruss68

Member
Licensed User
Longtime User
After some test I found the answer for my question.
The SQL library is not compatible with database created with third-party software.

I created a db with App, I copied the db from device to pc.
Open the file with SQL Expert Lite (or other)
Edit tables, create tables.
Copied the modified file to b4a files folder , and test .
Now work's.
 
Upvote 0
Top