PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → WM17 - Import data from remote DB to Android App DB
WM17 - Import data from remote DB to Android App DB
Iniciado por guest, 20,feb. 2015 14:27 - 7 respuestas
Publicado el 20,febrero 2015 - 14:27
Hello All,

I am trying to import data from a remote DB which is MySQL and I am using the web service Php2WM.

I am able to get the data from remote MySQL server and insert the same in Android App's DB.

But the problem is that when the data imported the Rec ID are not getting imported as per original data on remote MySQL DB. They are being assigned automatically as the Android Apps DB.

How can I import the data as it is from remote MySQL as it is?

TIA

Yogi Yang
Publicado el 20,febrero 2015 - 14:40
Hi

if you are using a local HF DB
if you are talking about automatic ID
If you are adding your records using hAdd
then you can for the value of the autoID by using the appropriate parameter in hadd (hforceautoID, from the top of my head)... All details, as usual, are in the help

Best regards
Publicado el 20,febrero 2015 - 15:36
Fabrice,

Thanks for the hint. Actually from the docs I understood that we have to use hSetIdAuto. And I was using that so I was not getting the expected results.

After using hForceIdAuto things are working as expected.

Once again thanks.

Regards,

Yogi Yang
Publicado el 20,febrero 2015 - 16:22
Now I am facing speed problems while importing data.

What I am doing it first deleting all the data in the file in question and then read data from remote server and add the data again. There are approx 59K entries.

Here is the code that I am using:
sSQL is string bRetCode is boolean //Delete existing records in Std Master IF HNbRec(student_master) > 0 THEN WHILE HNbRec(student_master) > 0 HReadFirst(student_master) HDelete(student_master) END //WHILE HNbRec(student_master) > 0 END //IF HNbRec(student_master) > 0 THEN sSQL = "SELECT * FROM student_master" //Execute SQLAssociebRetCode = AccessMySQL.mySQLExec(SQL, 0) bRetCode = AccessMySQL.mySQLExec(sSQL, 0) //If true then success IF bRetCode = True THEN //Check number of Rows IF AccessMySQL.mySQLGetNumRows(0) > 0 THEN //Move to First Record AccessMySQL.mySQLPremier(0) //Process All Records WHILE (NOT AccessMySQL.mySQLEnDehors) HReset(student_master) student_master.sm_id = AccessMySQL.mySQLCol(0,1) student_master.sm_roll_no = AccessMySQL.mySQLCol(0,2) student_master.sm_fname = AccessMySQL.mySQLCol(0,3) student_master.sm_mname = AccessMySQL.mySQLCol(0,4) student_master.sm_lname = AccessMySQL.mySQLCol(0,5) student_master.sm_address = AccessMySQL.mySQLCol(0,6) student_master.sm_city = AccessMySQL.mySQLCol(0,7) student_master.sm_pincode = AccessMySQL.mySQLCol(0,<img src="/NG2013_WEB/ui/smiley/7.gif" align=absmiddle border=0 alt="8)"> student_master.sm_state = AccessMySQL.mySQLCol(0,9) student_master.sm_mob_no = AccessMySQL.mySQLCol(0,10) student_master.sm_email_id = AccessMySQL.mySQLCol(0,11) student_master.sm_dob = AccessMySQL.mySQLCol(0,12) student_master.sm_gender = AccessMySQL.mySQLCol(0,13) student_master.sm_photo = AccessMySQL.mySQLCol(0,14) student_master.sm_father_name = AccessMySQL.mySQLCol(0,15) student_master.sm_father_mob_no = AccessMySQL.mySQLCol(0,16) student_master.sm_father_email_id = AccessMySQL.mySQLCol(0,17) HAdd(student_master,hForceIdAuto) //Move to Next Record AccessMySQL.mySQLSuivant(0) END //WHILE (NOT AccessMySQL.mySQLEnDehors) END //IF AccessMySQL.mySQLGetNumRows(0) > 0 THEN END //IF bRetCode = True THEN Is there any better way of updating data on the phone instead of first deleting the data and then adding it again.

TIA

Yogi Yang
Publicado el 20,febrero 2015 - 19:10
Hi again

you can use hcreation to delete the whole file and recreating it empty in one line and very fast
After that, you still need to add the records. You can try to deactivate the index creation and deactivate the integrity management in order to gain speed than to a hreindex, that should give your SOME gain...

Best regards
Publicado el 20,febrero 2015 - 20:56
Hi,
try to wrap your loop in a transaction

SQLTransaction(sqlStart,CONNECTION_NAME)
WHILE
END
SQLTransaction(sqlCommit,CONNECTION_NAME)

Otherwise every HAdd() is a transaciton by itself by default. Which causes a lot of overhead.

I had the same problems some years ago. I finally switched to another approach and generate my data on a webserver now (which I used anyway). This is as fast as you may expect and afterwards I download the sqlite.db as a whole.

I'm not sure if this i working in wm17, please give it a try. I'm writing this from memory and left wm17 already 2 years ago for wm18 and wm19 nowadays.
Publicado el 20,febrero 2015 - 20:59
Another thing I found out is refreshing the screen can cost time.
I remember showing a progressbar and incremented is on every record.(10000+).
That costs more time than the actual HAdd !!
Now I increment such progressbar only on every xxx iteration.
Publicado el 26,febrero 2015 - 07:11
Arie,
Quote
Arie

try to wrap your loop in a transaction



SQLTransaction(sqlStart,CONNECTION_NAME)

WHILE

END

SQLTransaction(sqlCommit,CONNECTION_NAME)
This feature is not supported in WM17.

There has to be something parallel. I am trying to find that at the moment.

TIA

Yogi Yang