TGDbConnection

From Gestinux Wiki
Jump to navigation Jump to search

Purpose

This component inherits from TZConnection and is used to store server and database properties.

Currently, We are restricted to MySql 5 and MariaDb 5 and PostgreSQL 9.

The GDbConnection.pas unit defines also TGTable and TGQuery and function and procedures not belonging to objects.

Description

In addition to TZConnection, some procedures and functions can be used to simplify code in the application.

Some of them depends on the DBMS to ensure portability without need to handle this in the main application software.

  • Data formating
    • StringSql : returns a string surrounded with quotes to include in a Sql query.
    • DateSql : returns a date in the right format, depending on the DBMS, and surrounded with quotes to include in a Sql query.
    • BoolSql : returns a boolean value changed to a digit when required by the DBMS to include in a Sql query.
    • EmptyStringSql : returns the empty string to include in a Sql query.
    • AddWhereClause : adds AND or WHERE and a clause to a Sql query.
  • Data retrieving
    • ExistingQuery : returns True if a query returns row(s).
    • SelectSql : execute a query to return a single string field
    • SelectSqlDate : execute a query to return a single date field
    • SelectSqlInteger : execute a query to return a single integer field
  • Data update
    • ExecSql : execute a query to update or delete data
    • ExecSqlRaise : execute a query to update or delete data
    • LastInsertedId : returns Id of last inserted record
    • InsertSql : should be used for all inserts.
    • Rollback : raise no error if called when transaction is not started
  • Setup and database connection :
    • TryConnectDatabase and ConnectDatabase
    • CreateDatabase
    • ExecSqlDataDefinition
    • GetDatabasesList
    • GetDBMSType
    • ReadLastVersion and WriteLastVersion : store and read a version of the software to trigger database reorganization.
    • NoDatabase