Difference between revisions of "TGDbConnection"
Line 45: | Line 45: | ||
== Error handling == | == Error handling == | ||
− | When | + | When the connection is lost, the exception EGDbServerHasGoneAway is raised, and [[ServerHasGoneAway|this page]] is displayed, or it's translation to the current language, when available. |
+ | |||
+ | When another error occurs in any method of this object, the exception EGDbError is raised, and by default [[EGDbError|this page]] is displayed, or it's translation to the current language, when available. |
Latest revision as of 14:44, 20 October 2020
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
Error handling
When the connection is lost, the exception EGDbServerHasGoneAway is raised, and this page is displayed, or it's translation to the current language, when available.
When another error occurs in any method of this object, the exception EGDbError is raised, and by default this page is displayed, or it's translation to the current language, when available.