What better way to create an app that works offline and automatically encrypt data with a server?

Asked

Viewed 3,031 times

11

I’m deepening into the world Mobile, where I had the first challenge, which is to create a App Android basic registration, name, age, etc. The tricky (at least for me) is that I have to update this data saved in Android Sqlite to a Mysql BD on the server.

I am using RAD Studio XE8 tool.

Would anyone have a light on how to do this? Do I have to enable some service on the outside, or leave a running Windows application to do the integration? My goal is to accomplish in a simple way that by clicking a synchronize button, the record is saved in the server’s BD, and another button to clear the data.

Thank you.

  • I haven’t used Delphi for Android development yet, but I recommend you send requests for Scripts (PHP or other scripting language) on your server. Then these scripts could perform the changes in the database.

3 answers

4


The method I suggest is as follows. Assuming you can use a scripting language on your server, first load the Local Database data into the Delphi application (Android).

To proceed, add the Indy HTTP library and the System Classes:

uses Classes, IdHTTP;

Create the necessary variables:

var 
    ParamList : TStringList; // Lista para representar o registro do banco
    MyRow     : TWhatever; // Esta variável hipotética representa o objeto ou array onde você terá o registro do Banco Local
    HTTP      : TIdHTTP; // Objeto HTTP do Indy

Put the data that should be passed to the server (single table record) into one TStringList in the standard format of Uris:

ParamList.Add('id=' + MyRow.ID);
ParamList.Add('name=' + MyRow.Nome);
ParamList.Add('phone_number=' + MyRow.PhoneNumber);
// Adicione todos os campos da tabela.

After, you must create the Indy HTTP object and perform the POST for the Script on the server:

HTTP := TIdHTTP.Create(nil);
try
    HTTP.Post('http://ip-ou-nome-do-servidor/pasta/do/script', ParamList);
finally
    HTTP.Free;
    ParamList.Free;
end;

The above example would send the Name, Surname and ID data to a server script (possibly in PHP or other language you prefer, know or want to learn). This script in turn would perform operations on the Remote Database (Server).

This is clearly just a generic and illustrative example. It contains the basic concepts for the method.

If you are not aware of any of the above terms, I suggest you study:

  • HTTP
  • POST and GET
  • CGI scripts

0

In fact, what is difficult in your question is more in relation to the many ways that Delphi allows to do, that choosing the best really depends on each particularity.

For example, Delphi is very simple to connect with Datasnap and has a lot of tutorials on YOUTUBE teaching you how to implement both server and client side. From one studied in JSON which, in my opinion, is the best way out to the part of sending information to the server. To retrieve the information, rely on Datasetprovider->Clientdataset

Firedac also has a number of new features, such as ETL components, which allow you to synchronize tables from different databases, and a factor feature that may be sufficient for you: Work with the offline database.

I recommend the courses of DEVMEDIA, especially from Professor Guinter Pauling, specialist in these subjects.

If you have a REST server to consume, then Delphi also has excellent connection controls, and I recommend starting with restDebuger, which comes with Delphi.

0

You could use the technology Datasnap REST using JSON objects from Embarcadero itself, which makes the synchronizations between Client/Server making the response time much faster and the Firedac component to make database connection to Mobile Android and Mysql, the technology is already ready to work in offline mode so it would not stay online all the time, only when doing a synchronization. If you have no knowledge about this new technology I suggest you take a look at the tutorial that Adriano Santos made.

Tdevrocks Datasnap REST

Browser other questions tagged

You are not signed in. Login or sign up in order to post.