dark_mode edit EN

WOdbcDatasource

  • Inherits from: None

    File: zOdbcDatasource.prg

This class allows access to any database engine through an ODBC driver.

This class has been specifically designed for use in CGI environments and therefore lacks many of the features found in other classes for this purpose. All of this, with the sole objective of gaining speed and ease of use.

Recordsets or cursors are very simple. They do not support inline editing, and you should consider them as what they are: simple arrays containing all the data from the SELECT operation you have performed. However, adding, editing, and deleting operations are very simple to perform.

Any SELECT operation must be performed with the Query method, which returns an instance of the WOdbcQuery class. This object has two fundamental members: the aData property and the Header method. The property returns an array with all the query data, and the method returns the name of each of the fields used.

To create queries, there is a very powerful method called WOdbcQuery:BuildSqlSt that automatically manages the construction of SQL statements. Once you start using this method, you will never build an SQL statement by hand again.

For editing operations, you must use the WOdbcQuery:Record method and the WOdbcQuery:SqlInsert and WOdbcQuery:SqlUpdate methods. The WOdbcQuery:Record method receives a single parameter with the record number you want to edit and returns a hash with the record data. If you want to perform an insert operation, you must specify the value (0) as a parameter. which will return a hash with the default values ​​for each of the fields. If you want a hash with all values ​​set to null, you can use the (-1) parameter. This hash will be passed as a parameter to the WOdbcQuery:SqlInsert method, and it will directly return the SQL statement to use with the Execute method.

For editing, the procedure is very similar, but you have the option to have the SQL statement run only on the fields that have actually been modified. Use the WOdbcQuery:Record method twice to retrieve the record you want to edit. Edit only the first one, but when constructing the SQL statement with the WOdbcQuery:SqlUpdate method, specify as the third parameter the additional hash you obtained in the second call to the WOdbcQuery:Record method. The method WOdbcQuery:SqlUpdate will construct the SQL statement with only the fields that have changed.

As you can imagine, the edit, insert, and delete operations you perform directly using the methods explained above do not affect the recordset. If you want to continue working with that dataset after editing, you'll need to manually update it or perform a reread to obtain a new recordset. However, the WOdbcQuery:LocalInsert and WOdbcQuery:LocalUpdate methods are available to make editing easier.

IMPORTANT NOTE:

In Linux environments, you must install the ODBC-devel module with the following statement:

sudo apt install unixodbc