Emme Developer Well-Known Member Licensed User Longtime User Apr 18, 2020 #1 Hi to all, i'm trying to initialize a db in File.dirInternal (copied from assets) but i got this error: B4X: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14 SQLITE_CANTOPEN): Could not open database This is the code i use: B4X: If File.Exists(File.DirInternal,DB_NAME) Then sqlManager.Initialize(File.DirInternal,DB_NAME,False) Else File.Copy(File.DirAssets,DB_NAME,File.DirInternal,DB_NAME) sqlManager.Initialize(File.DirInternal,DB_NAME,False) End If I think is right because is a shared sub that I use in all my projects... So i don't understand the issue. File in assets exists. Also in DirInternal.. I know i can use DBUtils to copy file, but i need to understand why i'm getting this error Thanks to all
Hi to all, i'm trying to initialize a db in File.dirInternal (copied from assets) but i got this error: B4X: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14 SQLITE_CANTOPEN): Could not open database This is the code i use: B4X: If File.Exists(File.DirInternal,DB_NAME) Then sqlManager.Initialize(File.DirInternal,DB_NAME,False) Else File.Copy(File.DirAssets,DB_NAME,File.DirInternal,DB_NAME) sqlManager.Initialize(File.DirInternal,DB_NAME,False) End If I think is right because is a shared sub that I use in all my projects... So i don't understand the issue. File in assets exists. Also in DirInternal.. I know i can use DBUtils to copy file, but i need to understand why i'm getting this error Thanks to all
Emme Developer Well-Known Member Licensed User Longtime User Apr 18, 2020 #2 I noticed that I can open another db... maybe could be this specific db? Upvote 0
drgottjr Expert Licensed User Longtime User Apr 18, 2020 #3 normally, i would suspect an issue with DB_NAME (eg, you spelled it wrong or there is a problem with case sensitivity - "A" vs "a"), but in this case if there was a problem with DB_NAME, your tests would have failed and you would have seen a different error. perhaps you did and didn't tell us... so, if the problem is not with DB_NAME, it would seem to be with the db itself. is it sqlite for sure? did you create it? perhaps it's corrupt? Upvote 0
normally, i would suspect an issue with DB_NAME (eg, you spelled it wrong or there is a problem with case sensitivity - "A" vs "a"), but in this case if there was a problem with DB_NAME, your tests would have failed and you would have seen a different error. perhaps you did and didn't tell us... so, if the problem is not with DB_NAME, it would seem to be with the db itself. is it sqlite for sure? did you create it? perhaps it's corrupt?
makis_best Well-Known Member Licensed User Longtime User Apr 18, 2020 #4 If you copy that database on your computer you can use it? You can open it? Upvote 0
aeric Expert Licensed User Longtime User Apr 18, 2020 #5 Maybe the db is readonly if you are reading it from assets folder. Upvote 0
Emme Developer Well-Known Member Licensed User Longtime User Apr 18, 2020 #6 drgottjr said: normally, i would suspect an issue with DB_NAME (eg, you spelled it wrong or there is a problem with case sensitivity - "A" vs "a"), but in this case if there was a problem with DB_NAME, your tests would have failed and you would have seen a different error. perhaps you did and didn't tell us... so, if the problem is not with DB_NAME, it would seem to be with the db itself. is it sqlite for sure? did you create it? perhaps it's corrupt? Click to expand... Now way to have a problem with dbname as i use it in every sub, so i'm sure there is not a problem with mispelling. I'm sure it is SQLite, i created it with SQLliteStudio. I think it's not corrupted, maybe can be an issue with table makis_best said: If you copy that database on your computer you can use it? You can open it? Click to expand... Yes i can open without any issue aeric said: Maybe the db is readonly if you are reading it from assets folder. Click to expand... I'm trying to read from Dirinternal, not assets. Btw is not readonly Upvote 0
drgottjr said: normally, i would suspect an issue with DB_NAME (eg, you spelled it wrong or there is a problem with case sensitivity - "A" vs "a"), but in this case if there was a problem with DB_NAME, your tests would have failed and you would have seen a different error. perhaps you did and didn't tell us... so, if the problem is not with DB_NAME, it would seem to be with the db itself. is it sqlite for sure? did you create it? perhaps it's corrupt? Click to expand... Now way to have a problem with dbname as i use it in every sub, so i'm sure there is not a problem with mispelling. I'm sure it is SQLite, i created it with SQLliteStudio. I think it's not corrupted, maybe can be an issue with table makis_best said: If you copy that database on your computer you can use it? You can open it? Click to expand... Yes i can open without any issue aeric said: Maybe the db is readonly if you are reading it from assets folder. Click to expand... I'm trying to read from Dirinternal, not assets. Btw is not readonly
makis_best Well-Known Member Licensed User Longtime User Apr 18, 2020 #7 You are 100% that the name of your database are the same on your database file and everywhere on your code? Are you sure you don't have any other instance open? Are you sure that the folder you use is not read only? Have you try to create another file inside that folder? Last edited: Apr 18, 2020 Upvote 0
You are 100% that the name of your database are the same on your database file and everywhere on your code? Are you sure you don't have any other instance open? Are you sure that the folder you use is not read only? Have you try to create another file inside that folder?
Emme Developer Well-Known Member Licensed User Longtime User Apr 18, 2020 #9 makis_best said: You are 100% that the name of your database are the same on your database file and everywhere on your code? Are you sure you don't have any other instance open? Are you sure that the folder you use is not read only? Have you try to create another file inside that folder? Click to expand... Yes, 100% Yes Yes Yes Upvote 0
makis_best said: You are 100% that the name of your database are the same on your database file and everywhere on your code? Are you sure you don't have any other instance open? Are you sure that the folder you use is not read only? Have you try to create another file inside that folder? Click to expand... Yes, 100% Yes Yes Yes
Emme Developer Well-Known Member Licensed User Longtime User Apr 18, 2020 #10 klaus said: What exactly is : DB_NAME ? Click to expand... dbgames.db, i've declared it globally B4X: Sub Class_Globals Private sqlManager As SQL Private DB_NAME As String = "dbgames.db" End Sub Upvote 0
klaus said: What exactly is : DB_NAME ? Click to expand... dbgames.db, i've declared it globally B4X: Sub Class_Globals Private sqlManager As SQL Private DB_NAME As String = "dbgames.db" End Sub
aeric Expert Licensed User Longtime User Apr 18, 2020 #11 Try restart the PC, maybe the file is locked by other processes. ? Upvote 0
Emme Developer Well-Known Member Licensed User Longtime User Apr 18, 2020 #12 aeric said: Try restart the PC, maybe the file is locked by other processes. ? Click to expand... The error is on Android Upvote 0
aeric said: Try restart the PC, maybe the file is locked by other processes. ? Click to expand... The error is on Android
Pendrush Well-Known Member Licensed User Longtime User Apr 18, 2020 #13 Did you maybe upload your DB to your phone from PC directly? Trough ADB, FTP or any other way? EDIT: Can you upload example project? Last edited: Apr 18, 2020 Upvote 0
Did you maybe upload your DB to your phone from PC directly? Trough ADB, FTP or any other way? EDIT: Can you upload example project?
M Mahares Expert Licensed User Longtime User Apr 18, 2020 #14 I think you need to upload your project if you can as Pendrush suggested. But, here is another suggestion, as if you need another one, did you try to delete the database from internal and then copy it back to internal from assets and initialize it on firsttime in internal. I hope I am not repeating a recommendation given in the posts above. Upvote 0
I think you need to upload your project if you can as Pendrush suggested. But, here is another suggestion, as if you need another one, did you try to delete the database from internal and then copy it back to internal from assets and initialize it on firsttime in internal. I hope I am not repeating a recommendation given in the posts above.
OliverA Expert Licensed User Longtime User Apr 18, 2020 #15 Pure guess: could it be due to version differences in SQLite? Android is notorious for being behind. Does the desktop version use a feature that the older SQLite can not deal with? Upvote 0
Pure guess: could it be due to version differences in SQLite? Android is notorious for being behind. Does the desktop version use a feature that the older SQLite can not deal with?
M Mahares Expert Licensed User Longtime User Apr 18, 2020 #16 OliverA said: Pure guess: could it be due to version differences in SQLite? Click to expand... Usually, from what I observed in the past, if the version on the device is behind you get a syntax error. But, I am guessing too. See this thread: SQLite "OVER PARTTION" not supported in B4A ?! Hi, I wanted to add some statistics to my App and now have the problem, that it seems that "OVER" is not supported by B4A ?! SELECT Spieler, count(*) OVER (PARTITION BY spieler ORDER BY Spieler_Spieltag.ID_Spieltag) as Part_SUM from Spieler_Spieltag Executing the statement in "DB Browser for... www.b4x.com Please MDev, don't let us down. we are all eager to find out what you come up with. Watch, tomorrow Erel will blow by all our suggestions and give him the correct diagnosis. Upvote 0
OliverA said: Pure guess: could it be due to version differences in SQLite? Click to expand... Usually, from what I observed in the past, if the version on the device is behind you get a syntax error. But, I am guessing too. See this thread: SQLite "OVER PARTTION" not supported in B4A ?! Hi, I wanted to add some statistics to my App and now have the problem, that it seems that "OVER" is not supported by B4A ?! SELECT Spieler, count(*) OVER (PARTITION BY spieler ORDER BY Spieler_Spieltag.ID_Spieltag) as Part_SUM from Spieler_Spieltag Executing the statement in "DB Browser for... www.b4x.com Please MDev, don't let us down. we are all eager to find out what you come up with. Watch, tomorrow Erel will blow by all our suggestions and give him the correct diagnosis.
Emme Developer Well-Known Member Licensed User Longtime User Apr 19, 2020 #17 Pendrush said: Did you maybe upload your DB to your phone from PC directly? Trough ADB, FTP or any other way? EDIT: Can you upload example project? Click to expand... I need to try to copy directly as you suggest. Mahares said: I think you need to upload your project if you can as Pendrush suggested. But, here is another suggestion, as if you need another one, did you try to delete the database from internal and then copy it back to internal from assets and initialize it on firsttime in internal. I hope I am not repeating a recommendation given in the posts above. Click to expand... I delete all files in internal folder everytime i start the app, to be sure that i will a fresh copy of db (of course only meanwhile i'm in debug) OliverA said: Pure guess: could it be due to version differences in SQLite? Android is notorious for being behind. Does the desktop version use a feature that the older SQLite can not deal with? Click to expand... I'm no trying to do nothing, only initialize the db. I don't think the problem is releated to a specific version I'm attaching a small project that replicates the issue, hope to help someone to find the right way. Thanks to everybody Attachments try.zip try.zip 166.6 KB · Views: 522 Upvote 0
Pendrush said: Did you maybe upload your DB to your phone from PC directly? Trough ADB, FTP or any other way? EDIT: Can you upload example project? Click to expand... I need to try to copy directly as you suggest. Mahares said: I think you need to upload your project if you can as Pendrush suggested. But, here is another suggestion, as if you need another one, did you try to delete the database from internal and then copy it back to internal from assets and initialize it on firsttime in internal. I hope I am not repeating a recommendation given in the posts above. Click to expand... I delete all files in internal folder everytime i start the app, to be sure that i will a fresh copy of db (of course only meanwhile i'm in debug) OliverA said: Pure guess: could it be due to version differences in SQLite? Android is notorious for being behind. Does the desktop version use a feature that the older SQLite can not deal with? Click to expand... I'm no trying to do nothing, only initialize the db. I don't think the problem is releated to a specific version I'm attaching a small project that replicates the issue, hope to help someone to find the right way. Thanks to everybody
Emme Developer Well-Known Member Licensed User Longtime User Apr 19, 2020 #18 Mahares said: Please MDev, don't let us down. we are all eager to find out what you come up with. Watch, tomorrow Erel will blow by all our suggestions and give him the correct diagnosis. Click to expand... I'm sure of this, but i'm also sure we can find a solution without the help of Erel (but if he wants to help of course he can ) Upvote 0
Mahares said: Please MDev, don't let us down. we are all eager to find out what you come up with. Watch, tomorrow Erel will blow by all our suggestions and give him the correct diagnosis. Click to expand... I'm sure of this, but i'm also sure we can find a solution without the help of Erel (but if he wants to help of course he can )
Emme Developer Well-Known Member Licensed User Longtime User Apr 19, 2020 #19 Finally, found the issue!! The problem is in the DB, i've using a table with a colum named All, and seems that All is a restricted keyword in sqllite so we can't use it as column name SQLite Keywords I am quite irritated by the error, could be specified the problem instead of giving error 14, but at the least without this colum all works properly. Thanks to all for help, and sorry for wasting your time Upvote 0
Finally, found the issue!! The problem is in the DB, i've using a table with a colum named All, and seems that All is a restricted keyword in sqllite so we can't use it as column name SQLite Keywords I am quite irritated by the error, could be specified the problem instead of giving error 14, but at the least without this colum all works properly. Thanks to all for help, and sorry for wasting your time
M Mahares Expert Licensed User Longtime User Apr 19, 2020 #20 I was just going to post that I deleted the table called: progress and then it worked fine. Also, you have columns in that table with data type as STRING. I have never seen that before. I usually put TEXT. Is STRING a valid data type in SQLite. Apparently, it is valid. You learn something every day. Last edited: Apr 19, 2020 Upvote 0
I was just going to post that I deleted the table called: progress and then it worked fine. Also, you have columns in that table with data type as STRING. I have never seen that before. I usually put TEXT. Is STRING a valid data type in SQLite. Apparently, it is valid. You learn something every day.