Android Question shows problem saving to sql data

ibra939

Active Member
Licensed User
Longtime User
shows problem saving to sql data the following screen
upload_2016-4-8_14-33-27.png
upload_2016-4-8_14-33-44.png
 

mangojack

Expert
Licensed User
Longtime User
if i deleted how is it work ? where will save data?

You had to delete the db first (The blank one with no Tables Defined ) .. then run the new code .. or you will continually get an error.

Try This ..
 

Attachments

  • TestSQL.zip
    10.7 KB · Views: 148
Upvote 0

ibra939

Active Member
Licensed User
Longtime User
You had to delete the db first (The blank one with no Tables Defined ) .. then run the new code .. or you will continually get an error.

Try This ..
i delete db but i still get error what happen ?
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
i delete db but i still get error what happen ?

Sorry .. Just noticed the New error
java.io.FileNotFoundException: /mnt/sdcard/Android/data/b4a.example/files/savedata.db: open failed: EACCES (Permission denied)

Change all File.Dir references to .. File.DirInternal (where you app is)

from Lolipop there is an permission issue try to save to external sd card.
 
Upvote 0

ibra939

Active Member
Licensed User
Longtime User
Sorry .. Just noticed the New error



Change all File.Dir references to .. File.DirInternal (where you app is)
The is a permission issue try to save to external sd card.


but is every think fine with code only that permission problem?
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
but is every think fine with code only that permission problem?
If I understand you correct .. If you have changed the code as suggested above ..
Yes ... All is Good . you only have to save the db elsewhere (File.DirInternal) or search forum to solve saving to External SD.
 
Upvote 0

ibra939

Active Member
Licensed User
Longtime User
If I understand you correct .. If you have changed the code as suggested above ..
Yes ... All is Good . you only have to save the db elsewhere (File.DirInternal) or search forum to solve saving to External SD.

i change but still same issue
 
Upvote 0

ibra939

Active Member
Licensed User
Longtime User
why is writing?????

no such table: setting: , while compiling: INSERT INTO setting VALUES (Null,?,?)
 

Attachments

  • a2.zip
    10.7 KB · Views: 137
Upvote 0

mangojack

Expert
Licensed User
Longtime User
why is writing?????
no such table: setting: , while compiling: INSERT INTO setting VALUES (Null,?,?)

You did not follow instructions above to change your code ... See post #17.

Your Code
B4X:
sql1.Initialize(File.DirInternal,"savedata.db",True)
  
If File.Exists(File.DirInternal,"savedata.db")=False Then
  File.Copy(File.DirAssets,"savedata.db",File.DirDefaultExternal,"savedata.db") '@@ wrong DIR
End If

Should be ...
B4X:
If File.Exists(File.DirInternal,"savedata.db")=False Then
  File.Copy(File.DirAssets,"savedata.db",File.DirInternal,"savedata.db")
End If

sql1.Initialize(File.DirInternal,"savedata.db",False)  '@@  change to False .. the db should always exist now.

*** Uninstall old app first OR delete existing blank db on first run !

Also Please study the Starter Service which would be best place for above code (see uploaded project #21)
 
Upvote 0

ibra939

Active Member
Licensed User
Longtime User
as you say i do but same issue but in my phone work saving data but not view data:



LogCat connected to: emulator-5554
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 334)
android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file
at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1013)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:962)
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
?? .. Could you try the attached . There should be no reason for it to fail.
 

Attachments

  • TestSQL 2.zip
    10.8 KB · Views: 140
Upvote 0

ibra939

Active Member
Licensed User
Longtime User
?? .. Could you try the attached . There should be no reason for it to fail.

the problem was sql1.Initialize(File.DirInternal,"savedata.db",False)

thanks for you solve work fine
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
the problem was sql1.Initialize(File.DirInternal,"savedata.db",False)

It was only the position of this line that caused a problem.;)
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
yes but i think if my phone have root will be working o_O:D
I don't think you need to root your phone. It may depend on which Android version that support external storage. My phone is not rooted and I usually develop my app to move the db file from asset to Internal and not external to reduce any problem with the storage permission.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
The sqlite db is usually very small storage footprint (<1 Megabyte). I don't think app user mind to let it keep inside the internal storage.
Here is how my app normally written when loading at Main activity.

B4X:
Sub Process_Globals
    Dim DB As SQL
    Dim DBFileDir As String
    Dim DBFileName As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        DBFileDir = File.DirInternal
        DBFileName = "mytenant.db"
        If File.Exists(DBFileDir, DBFileName) = False Then
            DBFileDir = DBUtils.CopyDBFromAssets(DBFileName)
        End If       
        DB.Initialize(DBFileDir, DBFileName, False)
    End If
End Sub
 
Upvote 0

ibra939

Active Member
Licensed User
Longtime User
I don't think you need to root your phone. It may depend on which Android version that support external storage. My phone is not rooted and I usually develop my app to move the db file from asset to Internal and not external to reduce any problem with the storage permission.
Yes is it true internal will be better
 
Upvote 0

Similar Threads

Top