As mentioned in the document Offline Database Object Table selection, this object is in charge of selecting the tables that the device is going to use in order to work Offline. But how and when are these tables created in the device? How are they reorganized when the table model changes?
The objective of this document is to answer these questions.
Once the Offline Database object determines the selected Tables, GeneXus makes a Smart Devices Impact Analysis that shows all the selected tables and their creation statements.
This impact analysis is always made after the first Build operation of the application when Offline architecture is selected.
After that, it is called in the following situations:
- On every model change: Any modification to model Create/Update/Delete tables or attributes.
- When table references change: For example, when your application makes reference to a table that was not referenced before.
- Every time the Rebuild All action is executed.
- Manually: Using the Create Offline Database action from the Build menu.
After the Impact Analysis is done, reorganization files are created for each Smart Device generator enabled for the Native Mobile Generator.
These files include the routines to create the database in the device once the application is installed.
The Offline local database is created when the application is launched for the first time in the device. In order to do this, the reorganization files must be created as they include the database creation routines.
After that, every time the offline database model changes, the reorganization files re-create the local database tables from scratch1, losing all their existing data. The exception here is the GXPendingEvents table, where the pending events (those that were not syncrhonized) will be copied into the new database, in order to be sent to the server in the next sync process. To learn more, read SynchronizationEventsAPI external object (X Evolution 3)
1 To know whether the database needs to be re-created, the MD5 of the ReorganizationScript.txt is compared.
- It is very important that you have the Reorganization files generated and compiled before you run your application in the device. Otherwise, several errors may occur, and your application may even crash as a result of not having these files.
- As Reorganization files are generated for every Smart Device generator that is enabled, when enabling a new Smart Device generator, the Impact Analysis may not be done and therefore the reorganization files may not be created. In summary, every time you enable a new Smart Device generator you must run a Rebuild All or the Create Offline Database action manually.
- Having more than one Offline main object is not supported, as only one reorganization program is kept by each Smart Device Generator.