Other Problems with B4A Envoronment - SQLite updates

aklisiewicz

Active Member
Licensed User
Longtime User
Looks like B4A IDE has a serious problem with updating SQLite database link.
I have a local SQLite file stored on my C:/...... drive.
I also have a local PHP application which can access and modify SQLite records. When I change any data the information is not updated in my Android App at all. Even if I restart the App the records still show old data. The only way to get the updates visible is to REMOVE and the re-ADD the database file in the FILES Tab, then recompile App. This of course is very anoying and has to be fixed ASAP.
Possibly updates to the database installed on the device would not work as well.

Erel - could you please address this issue.

Arthur
 
Erel - I think you missed my point. This is not about update.
There are 2 application that write to the same database. When the PHP app makes a change the Android app doesn't see it !
For example: I have my App running on the Android Emulator and I list a set of records.
At the same time I run the PHP App and modify any of the records shown in Android - the change is not updated (even if I restart the App)!

Arthur
 
Upvote 0
I do not understand why the emulator doesn't update the data even if the App is restarted ?
If I have a SQLite dB on my device and have 2 apps modifying data in the same database would my Android App reflect the changes ? I haven't made such test but it seems like there might be a problem. My PHP App will reside on the internet and will update SQLite database. This database (once updated) will be downloaded to the Android Device and then I need to make sure all changes are reflected. At this moment the procedure is very simple.
I plan to use some type of File Transfer (hope there is a LIB for that) utility do download the dB file to the device. Once the file is downloaded I plan to copy that file to the DirInternal folder (replacing the old one). I hope this scenario would work.

One posibility that exists is that I'm copying the MyDatabase_REM.db to the wrong folder (?). In a local environment it is COPYING but in production it would be downloading the database file to the device folder, so wehere it supposed to be copied (downloaded) ?

At this moment I'm trying to test the same scenario in my local environment. I have a MyDatabase_REM.db as remote file. I change data to that database with my local PHP App running on local Apache .

Within Android App I copy that file to MyDatabase_LOC (as local-device database). Then I simply try to access the data and I should be able to see the changes - right ? But I do not, so am I doing something wrong ?

Arthur
 
Upvote 0
The emulator file system cannot be accessed from outside. The PHP script cannot write to the emulator database.
I noticed that even if I use SQLite MANAGER and manually change some data, after that change (when I run the App) the change does not show up !
this isn't right. Why do I have to Remove then Add the database file in the FILES Tab in order to see changes ? It doesn't make much sense to me.
Art
 
Upvote 0
When B4A updates a SQLite file, the DB IS definitely updated. The fault must be on your side - maybe you are accessing a different file or something else is not right.

It would seem that your best scenario is to have your DB on a MySQL server and then use PHP to synchronise that DB with your local SQLite DB on the device. This would require your DB's to have a 'lastupdated' field to know which require synchronising.
 
Upvote 0
Seeing some code would be a good start..

Do you copy the DB to the read-write area of your App? If so do you check to see if it's already in the read-write area? If so, then you'll need to work out some way of allowing the code to overwrite the DB with a newer version. There are quite a few other threads about this on here.
 
Upvote 0
When B4A updates a SQLite file, the DB IS definitely updated. The fault must be on your side - maybe you are accessing a different file or something else is not right.

It would seem that your best scenario is to have your DB on a MySQL server and then use PHP to synchronise that DB with your local SQLite DB on the device. This would require your DB's to have a 'lastupdated' field to know which require synchronising.
I guess you not reading carefully. This is completely opposite problem. B4A Application (at this moment) do not update anything. It works in READ ONLY mode. The updates take place by PHP App.

Once again here is a scenario:
- database A: MyDatabase_Rem.db (stored in DirInternal)
- database B: MyDatabaseLoc.db (stored in DirDefaultExternal)

1. PHP Apps modifies database A
2. Android App starts and copies database A (from DirDefaultExternal) into database B (DirInternal) location (overriding old file)
3. Android App shows updated data (this doesn't work)

QUESTION:
where on a PC am I supposed to place database B (which folder)
where on a DEVICE am I supposed to place database B (which folder)

Thanks - Arthur
 
Upvote 0
Is there a specific reason why you are using DirInternal and DirDefaultExternal? Especially for situations where you are wanting access to the DB from other Apps (PHP in your case), I have always used File.DirRootExternal. Create a folder there, place your DB in it and use PHP to modify the DB there, and then let your Android App read the data from the same place. No Step 2 in previous post required.
 
Upvote 0
Erel - than kyou for your patience.
I understood you suggestion, so instead I'm trying to update a database which is outside of the Android Project. Once it is updated I need the dB file to be copied to the DirInternal and use it with the App. It seems like the file is copied, but the App dos not display updated records (showing old data). When I go to FILES tab and remove/add the dB file it all works. Perhaps I'm missing something. Is there any way to test if the newly copied (updated) dB file is really a new one ? Where do I look for that file (on a PC) if it is stored in DirInternal folder ?

Thanks - Arthur
 
Upvote 0
Arthur,
After watching this thread for a bit, I think I see what is going on.

Updating a file in the 'files tab' will only be changed in your app if you recompile and reinstall the app!
If you want to update the data separately from the app, it is necessary to transfer the file independently - Depends on how many people need to update the data, but I prefer holding the data file on the internet and using httputils2 to download it to the andriod device!

cheers,
Douglas
 
Upvote 0
Back
Top