TGTable

From Gestinux Wiki
Jump to navigation Jump to search

Purpose

This component is only used to store table metadata : description, fields, index, constraints.

TGTable is not used to store or retrieve data.

To create a new table

This is for a new functionnality in the application (only in the trunk version).

In order to have sources easy to read, avoid spaces in table names and fields. This way, quotes are not required.

After a table is created, the minimal database version number must be incremented in the datamodule. This ensure a reorganization the first time the database is opened with the new program.

  • Create the table and all it's index and constraints with MySql Query Browser or any other MySql client (not PostgreSQL).
    • The following types can be used only. If other types are necessary, some development must be done.
      • Integer Autoinc
      • Integer, smallint
      • Varchar
      • Timestamp
      • Date, Datetime
      • Blob
    • Always start with an Id field, Autoinc and Primary key. In Gestinux datamodel all relations are made between such Id fields.
    • Always end with an UpdateDate field, TimeStamp default current_timestamp on update current_timestamp
  • Drop a TGTable object in Datamodule, with connexion set to open the previous database.
    • Create a new computed field AutoInc
    • Because of a bug, correct it's wrong name to <TableName>Id
    • set it Required and set the FieldKind to fkData.
    • Add all other fields as usual.
    • Write the index and constraint instructions in the property Properties.
    • Copy and paste the MySql Syntaxe, remove quotes and commas at the end of the line
    • In DataModule1.DbAfterConnect event, add a TGTable.Check for the new table, when a reorganization is requested.
  • To test, select another database not containing the new table, or delete the new table in the database where it was created.
    • Run the reorganization : the table should be re-created with the specified properties
    • Check the structure of the table in the query browser

To add fields, index, constraints in an existing table

  • Add the fields, the new index, the new constraints with MySql Query Browser
  • Add fields in the TGTable object, add the index and constraint definitions in the TGTable.properties.
  • If necessary, make a query to be excuted after the reorganization to populate the new field with values from other tables.
  • Run the reorganization : the fields, index or constraints should be added.

Deleting fields, index or constraints

This is not and will not be automated. If an index or constraint is no more useful, you can execute after the reorganization a SQL Script to delete it If a field is no more useful, it should be kept and updated until the n+2 stable version is out, to allow backward compatibility. Never re-use an previously used name.