K kcwenfrank New Member May 30, 2018 #1 I am trying to do some exercise about sql database with B4A, However, I am stuck here for a while, I tried to build a sample sql-database in advance and then write some simple code in B4A. The code is very simple as below Code: Copy SQL1.Initialize(File.DirInternal,"example.db", True) SQL1_Index=SQL1.ExecQuery("SELECT * from sql_exercise") the problem is every time the code crash after running ExecQuery. Can some one give me a hint for this ? Attachments sql_exercise.zip sql_exercise.zip 8.2 KB · Views: 336
I am trying to do some exercise about sql database with B4A, However, I am stuck here for a while, I tried to build a sample sql-database in advance and then write some simple code in B4A. The code is very simple as below Code: Copy SQL1.Initialize(File.DirInternal,"example.db", True) SQL1_Index=SQL1.ExecQuery("SELECT * from sql_exercise") the problem is every time the code crash after running ExecQuery. Can some one give me a hint for this ?
R ronell Well-Known Member Licensed User Longtime User May 30, 2018 #2 include the error logs in your post .. we cant help without it edit: change your code Code: Copy File.DirInternal to Code: Copy File.DirAssets Last edited: May 30, 2018 Upvote 0
include the error logs in your post .. we cant help without it edit: change your code Code: Copy File.DirInternal to Code: Copy File.DirAssets
klaus Expert Licensed User Longtime User May 30, 2018 #3 The files in the File folder of your project are in File.DirAssets and not in the File.DirInternal folder. These are two different folders. Databases cannot be accessed in File.DirAssets, they must be copied somewhere else, for example to File.DirInternal. Attached a modified project. I suggest you to have a look at the B4X Booklets and more specific the SQLite chapter in the B4A User's Guide. You may also have a look at the SQLiteLight examples, which are shipped with the User's Guide. Attachments sql_exercise1.zip sql_exercise1.zip 8.4 KB · Views: 363 Upvote 0
The files in the File folder of your project are in File.DirAssets and not in the File.DirInternal folder. These are two different folders. Databases cannot be accessed in File.DirAssets, they must be copied somewhere else, for example to File.DirInternal. Attached a modified project. I suggest you to have a look at the B4X Booklets and more specific the SQLite chapter in the B4A User's Guide. You may also have a look at the SQLiteLight examples, which are shipped with the User's Guide.
R ronell Well-Known Member Licensed User Longtime User May 30, 2018 #4 klaus said: Databases cannot be accessed in File.DirAssets, they must be copied somewhere else, for example to File.DirInternal. Click to expand... forgot about that lol , it should be like this Code: Copy If File.Exists(File.DirInternal,"example.db") = False Then File.Copy(File.DirAssets,"example.db",File.DirInternal,"example.db") End If Upvote 0
klaus said: Databases cannot be accessed in File.DirAssets, they must be copied somewhere else, for example to File.DirInternal. Click to expand... forgot about that lol , it should be like this Code: Copy If File.Exists(File.DirInternal,"example.db") = False Then File.Copy(File.DirAssets,"example.db",File.DirInternal,"example.db") End If
klaus Expert Licensed User Longtime User May 30, 2018 #5 That's what I added in the project in post#3. Upvote 0
K kcwenfrank New Member May 30, 2018 #6 ronell, thank you for the reply. I am not sure if I misunderstanding or not. The original code will give me the error msg as below. android.database.sqlite.SQLiteException: no such table: sql_exercise (code 1): , while compiling: SELECT * from sql_exercise I think the SQL command should be correct as I tried in SQLite Expert already. I also modified the code as your suggestion and got the error msg as below. android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database I think the initialize should be no problem , just don't know if i miss anything or not. Upvote 0
ronell, thank you for the reply. I am not sure if I misunderstanding or not. The original code will give me the error msg as below. android.database.sqlite.SQLiteException: no such table: sql_exercise (code 1): , while compiling: SELECT * from sql_exercise I think the SQL command should be correct as I tried in SQLite Expert already. I also modified the code as your suggestion and got the error msg as below. android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database I think the initialize should be no problem , just don't know if i miss anything or not.
K kcwenfrank New Member May 30, 2018 #7 klaus, thank you for the replay. Sorry, I just replied ronell's post. Anyway I just saw your replied and tried the code already. It works great and your replied help me as well. Upvote 0
klaus, thank you for the replay. Sorry, I just replied ronell's post. Anyway I just saw your replied and tried the code already. It works great and your replied help me as well.