Show: Delphi C++
Display Preferences

Getting Started with InterBase Express

From RAD Studio
Jump to: navigation, search

Go Up to Developing Database Applications


InterBase Express (IBX) is a set of data access components that provides a means of accessing data from InterBase databases. The InterBase Administration Components, which require InterBase, are described after the InterBase data access components.

IBX components

The following components are located on the InterBase tab of the component palette.

IBX

IBTable.TIBTable

IBX

IBX.IBQuery.TIBQuery

IBX

IBX.IBStoredProc.TIBStoredProc

IBX

IBX.IBDatabase.TIBDatabase

IBX

IBX.IBDatabase.TIBTransaction

IBX

IBX.IBUpdateSQL.TIBUpdateSQL

IBX

IBX.IBCustomDataSet.TIBDataSet

IBX

IBX.IBSQL.TIBSQL

IBX

IBX.IBDatabaseInfo.TIBDatabaseInfo

IBX

IBX.IBSQLMonitor.TIBSQLMonitor

IBX

IBX.IBEvents.TIBEvents

IBX

IBX.IBExtract.TIBExtract

IBX

IBX.IBConnectionBroker.TIBConnectionBroker

IBX

InterBase Script

IBX

InterBase SQL Parser

IBX

IBX.IBDatabaseINI.TIBDatabaseINI

IBX

IBX.IBFilterDialog.TIBFilterDialog



Though they are similar to BDE components in name, the IBX components are somewhat different. For each component with a BDE counterpart, the sections below give a discussion of these differences.

Note: There is no simple migration from BDE to IBX applications. Generally, you must replace BDE components with the comparable IBX components, and then recompile your applications. However, the speed you gain, along with the access you get to the powerful InterBase features, make migration well worth your time.

IBDatabase

Use a IBX.IBDatabase.TIBDatabase component to establish connections to databases, which can involve one or more concurrent transactions. Unlike BDE, IBX has a separate transaction component, which allows you to separate transactions and database connections.

To set up a database connection

  1. Drop an IBDatabase component onto a form or data module.
  2. Fill out the DatabaseName property. For a local connection, this is the drive, path, and filename of the database file. Set the Connected property to True.
  3. Enter a valid user name and password and click OK to establish the database connection.
Tip: You can store the user name and password in the Params property of the IBDatabase component by setting the LoginPrompt property to False after logging in. For example, after logging in as the system administrator and setting the LoginPrompt property to False, you may see the following when editing the Params property:


user_name=sysdba
password=masterkey

IBTransaction

Unlike the BDE, IBX controls transactions with a separate component, IBX.IBDatabase.TIBTransaction. This powerful feature allows you to separate transactions and database connections, so you can take advantage of the InterBase two-phase commit functionality (transactions that span multiple connections) and multiple concurrent transactions using the same connection.

Use an IBTransaction component to handle transaction contexts, which might involve one or more database connections. In most cases, a simple one database/one transaction model are enough.

To set up a transaction

  1. Set up an IBDatabase connection as described above.
  2. Drop an IBTransaction component onto the form or data module
  3. Set the DefaultDatabase property to the name of your IBDatabase component.
  4. Set the Active property to True to start the transaction.

IBX dataset components

There are a variety of dataset components from which to choose with IBX, each having their own characteristics and task suitability:

IBTable

Use an IBX.IBTable.TIBTable component to set up a live dataset on a table or view without having to enter any SQL statements.

To configure IBTable components

  1. Add an IBTable component to your form or data module.
  2. Specify the associated database and transaction components.
  3. Specify the name of the relation from the TableName drop-down list.
  4. Set the Active property to True.

IBQuery

Use an IBX.IBQuery.TIBQuery component to execute any InterBase DSQL statement, restrict your result set to only particular columns and rows, use aggregate functions, and join multiple tables.

IBQuery components provide a read-only dataset, and adapt well to the InterBase client/server environment.

To set up an IBQuery component

  1. Set up an IBDatabase connection as described above.
  2. Set up an IBTransaction connection as described above.
  3. Add an IBQuery component to your form or data module.
  4. Specify the associated database and transaction components.
  5. Enter a valid SQL statement for the IBQuery SQL property in the String list editor.
  6. Set the Active property to True.

IBDataSet

Use an IBX.IBCustomDataSet.TIBDataSet component to execute any InterBase DSQL statement, restrict your result set to only particular columns and rows, use aggregate functions, and join multiple tables. IBDataSet components are similar to IBQuery components, except that they support live datasets without the need of an IBUpdateSQL component.

The following is an example that provides the steps to create a live dataset for the COUNTRY table in employee.gdb:

  1. Set up an IBDatabase connection as described above.
  2. Specify the associated database and transaction components.
  3. Add an IBDataSet component to your form or data module.
  4. Enter SQL statements for the following properties:

SelectSQL

SELECT Country, Currency FROM Country

RefreshSQL

SELECT Country, Currency FROM Country WHERE Country = :Country

ModifySQL

UPDATE Country SET Country = :Country, Currency = :Currency WHERE Country = :Old_Country

DeleteSQL

DELETE FROM Country WHERE Country = :Old_Country

InsertSQL

INSERT INTO Country (Country, Currency) VALUES (:Country, :Currency)
5. Set the Active property to True.


Note: Parameters and fields passed to functions are case-sensitive in dialect 3. For example,


FieldByName(EmpNo)

would return nothing in dialect 3 if the field was 'EMPNO'.

IBStoredProc

Use IBX.IBStoredProc.TIBStoredProc for InterBase executable procedures: procedures that return, at most, one row of information. For stored procedures that return more than one row of data, or "Select" procedures, use either IBQuery or IBDataSet components.

IBSQL

Use an IBX.IBSQL.TIBSQL component for data operations that need to be fast and lightweight. Operations such as data definition and pumping data from one database to another are suitable for IBSQL components.

In the following example, an IBSQL component is used to return the next value from a generator:

  1. Set up an IBDatabase connection as described above.
  2. Put an IBSQL component on the form or data module and set its Database property to the name of the database.
  3. Add an SQL statement to the SQL property string list editor, for example:


SELECT GEN_ID(MyGenerator, 1) FROM RDB$DATABASE

IBUpdateSQL

Use an IBX.IBUpdateSQL.TIBUpdateSQL component to update read-only datasets. You can update IBQuery output with an IBUpdateSQL component:

  1. Set up an IBQuery component as described above.
  2. Add an IBUpdateSQL component to your form or data module.
  3. Enter SQL statements for the following properties: DeleteSQL, InsertSQL, ModifySQL, and RefreshSQL.
  4. Set the IBQuery component's UpdateObject property to the name of the IBUpdateSQL component.
  5. Set the IBQuery component's Active property to True.

IBSQLMonitor

Use an IBX.IBSQLMonitor.TIBSQLMonitor component to develop diagnostic tools to monitor the communications between your application and the InterBase server. When the TraceFlags properties of an IBDatabase component are turned on, active TIBSQLMonitor components can keep track of the connection's activity and send the output to a file or control.

A good example would be to create a separate application that has a TIBSQLMonitor component and a Memo control. Run this secondary application, and on the primary application, activate the TraceFlags of the IBDatabase component. Interact with the primary application, and watch the memo control in the second application fill with data.

IBDatabaseInfo

Use an IBX.IBDatabaseInfo.TIBDatabaseInfo component to retrieve information about a particular database, such as the sweep interval, ODS version, and the user names of those currently attached to this database.

The following procedure is an example of how to set up an IBDatabaseInfo component that displays the users currently connected to the database.

To set up an IBDatabaseInfo component

  1. Set up an IBDatabase connection as described above.
  2. Put an IBDatabaseInfo component on the form or data module and set its Database property to the name of the database.
  3. Put a Memo component on the form.
  4. Put a Timer component on the form and set its interval.
  5. Double click on the Timer's OnTimer event field and enter code similar to the following:


Memo1.Text := IBDatabaseInfo.UserNames.Text;   //  Delphi example
Memo1->Text = IBDatabaseInfo->UserNames->Text; //  C++ example

IBEvents

Use an IBEvents component to register interest in, and asynchronously handle, events posted by an InterBase server.

To set up an IBEvents component

  1. Set up an IBDatabase connection as described above.
  2. Put an IBEvents component on the form or data module and set its Database property to the name of the database.
  3. Enter events in the Events property string list editor, for example:
IBEvents.Events.Add('EVENT_NAME');   //  Delphi example
IBEvents->Events->Add("EVENT_NAME"); //  C++ Example

4. Set the Registered property to True.


InterBase Administration Components

If you have InterBase installed, you can use the InterBase Administration components, which allow you to use access the powerful InterBase Services API calls.

The components are located on the InterBase Admin tab of the IDE and include:

IBX

IBX.IBServices.TIBConfigService

IBX

IBX.IBServices.TIBBackupService

IBX

IBX.IBServices.TIBRestoreService

IBX

IBX.IBServices.TIBValidationService

IBX

IBX.IBServices.TIBStatisticalService

IBX

IBX.IBServices.TIBLogService

IBX

IBX.IBServices.TIBSecurityService

IBX

IBX.IBServices.TIBServerProperties


Note: You must install InterBase to use these features.

IBConfigService

Use an IBX.IBServices.TIBConfigService object to configure database parameters, including page buffers, async mode, reserve space, and sweep interval.

IBBackupService

Use an IBX.IBServices.TIBBackupService object to back up your database. With IBBackupService, you can set such parameters as the blocking factor, backup file name, and database backup options.

IBRestoreService

Use an IBX.IBServices.TIBRestoreService object to restore your database. With IBRestoreService, you can set such options as page buffers, page size, and database restore options.

IBValidationService

Use an IBX.IBServices.TIBValidationService object to validate your database and reconcile your database transactions. With the IBValidationService, you can set the default transaction action, return limbo transaction information, and set other database validation options.

IBStatisticalService

Use an IBX.IBServices.TIBStatisticalService object to view database statistics, such as data pages, database log, header pages, index pages, and system relations.

IBLogService

Use an IBX.IBServices.TIBLogService object to create a log file.

IBSecurityService

Use an IBX.IBServices.TIBSecurityService object to manage user access to the InterBase server. With the IBSecurityService, you can create, delete, and modify user accounts, display all users, and set up work groups using SQL roles.

IBServerProperties

Use an IBX.IBServices.TIBServerProperties component to return database server information, including configuration parameters, and version and license information.

See Also

Personal tools
RAD Studio 10.2 Tokyo
In other languages
Previous Versions
Assistance