Convert DB table to XML - a worked example: Difference between revisions

From Zymonic
Content added Content deleted
Line 11: Line 11:
First we run the import_from_db command below:
First we run the import_from_db command below:


zymonic_toolkit.pl Definition import_from_db --definition [destination system] --dbname [source db ] --dbusername root --AutoCreateMaintenanceProcess true --AutoCreateFilter true --AutoCreateForm true --tablename [source table sql name you chose] --fieldznameprefix [whatever you like] --tableznameprefix [whatever you like]
[[File: import_from_db.PNG]]


It's worth noting that here you must put the database that currently has the table, the system you wish to add the xml to, and the sql/db name of the table.
It's worth noting that here you must put the database that currently has the table, the system you wish to add the xml to, and the sql/db name of the table.
Line 17: Line 17:
This has added the system definition to the export_test's db, in the table zz_system_definition. We can then do a config build, and the definition will be added from this table, to the system. After, when we run export_def:
This has added the system definition to the export_test's db, in the table zz_system_definition. We can then do a config build, and the definition will be added from this table, to the system. After, when we run export_def:



[[File: export_def.PNG]]





Revision as of 08:17, 27 September 2018

If you have a database table which you wish to convert into a Zymonic XML defined table, this can be a laborious task. Luckily 2 toolkit commands (import_from_db) and (export_def) can be used to automatically generate a Zymonic XML definition to replicate any DB table, below is an example.

The situation

We have a 'legacy' database table that we wish to use in Zymonic.

There are 2 commands here, that are used together. The aim is to be able to automatically produce an xml file that defines the SQL table. You should use import_from_db to create a system definition from a table in the DB, then use export_def to create an xml file from that system defintion.

Importing

First we run the import_from_db command below:

 zymonic_toolkit.pl Definition import_from_db --definition [destination system] --dbname [source db ] --dbusername root --AutoCreateMaintenanceProcess true --AutoCreateFilter true --AutoCreateForm true --tablename [source table sql name you chose] --fieldznameprefix [whatever you like] --tableznameprefix [whatever you like]

It's worth noting that here you must put the database that currently has the table, the system you wish to add the xml to, and the sql/db name of the table.

This has added the system definition to the export_test's db, in the table zz_system_definition. We can then do a config build, and the definition will be added from this table, to the system. After, when we run export_def:



There is now a system definition in export_test, of the table (with the definitions of the fields seperately outside of the table, but inside the Zymonic tags, if you are worried about these znames being duplicates of current existing ones, there are params to pass in field and table zname prefixes).

Editing

Once the definition has been config built into the system, the definition of the table can be viewed and edited from the system GUI with 'User System Definitions List' (although I won't here because I want to test that the tables come out identical):

Exporting

Now producing a bit of user-style xml is as simple as redirecting the output of export_def to a file:

File:Makingxml.PNG

This can then be added to your system in /etc/zymonic/system, and when a config build is run the table (and process and filter if you had the flags set to autocreate them), will be added to the system. (Before config building, you may need to delete from zz_system_definition and remove the perist file "sudo rm /etc/zymonic/export_test/ZZPersist.conf" before config building if you get zname conflicts.)

Below is a comparison of the explains of the original table, and the table produced (with the fields re-ordered for clarity):