To connect to a database, you must first create an IDL Database Object using the OBJ_NEW function:

objDB = OBJ_NEW('IDLdbDatabase')

The newly-created database object represents a connection to a datasource. The object is not considered valid until a connection to the datasource is made, either via the Connect method of the IDL Database Object or the DIALOG_DBCONNECT function.

Once the Database Object has been created, you can perform operations, including:

  • Connect to a database

  • Find out which databases are available

  • Find out if a specific database is available

  • Get properties of the database object

Finding Available Databases


To find out which databases are available, use the database object’s GetDatasources method as follows:

sources = objDB->GetDatasources()

The result is an array of IDL structures containing the datasource names and descriptions of all available data sources. See IDLdbDatabase::GetDatasources for more information.

Finding a Specific Database


To find out if a specific database is available, inspect the list of datasources returned by the GetDatasources method. The following IDL commands check to see if "Informix" is listed in the array of data sources, and if so, print the word “Yes” to the IDL command log:

index = WHERE(sources.datasource EQ 'Informix', nmatch) IF(nmatch ge 1) THEN PRINT, 'Yes'

If the desired database is reported as available, the database driver is installed on your system. You still need to make sure that the driver is configured correctly before you are able to connect to a database.

Connect to a Database


Once you have created a Database object, you can connect to a database. IDL DataMiner has two options for accessing databases:

Connect with the DIALOG_DBCONNECT Function


DIALOG_DBCONNECT is a function used to connect to a database using ODBC dialog boxes. These dialogs prompt you for information required to connect to the desired database.

To connect to a database using the DIALOG_DBCONNECT function, enter the following at the IDL prompt:

status = DIALOG_DBCONNECT(objDB)

The Select Data Sources dialog box appears. This dialog box lists the currently defined Data Sources, for example:

Note: Due to Motif library inconsistencies, this dialog may fail on some UNIX systems.

You can take one of the following actions:

  • Select the desired data source and click OK. After selecting this button, a “true” value is returned if the database object connects to the data source.
  • Cancel the operation by clicking the Cancel button. After selecting this button, a “false” value is returned, and the database object does not connect to the data source.
  • On Windows systems, click the New button to define a new data source for the system. (This button is not available on Motif systems.) The Create New Data Source wizard appears.

    1. In the wizard, select the desired ODBC driver for the new data source from the list and click Next button.

    2. Confirm the selection and click the Finish button.

    3. In the wizard, follow the steps to provide a Name, Description, and Server ID and follow the remaining steps to complete the connection.

Connect with the IDL Database Object’s Connect Method


To connect to a database using the database object’s Connect method, enter the following at the IDL prompt:

objDB->Connect, datasource = source_name

where source_name is the name of the data source. One way to specify the datasource name is to provide an index into the array of datasource names created with the IDL commands. For example, if you wanted to connect to the first available datasource in the list of available sources, you might use the following IDL commands:

sources = objDB->GetDatasources() mysource = sources[0].datasource objDB->Connect, datasource = mysource

Once you have connected to a database, you can perform several operations using IDL DataMiner methods, including:

  • Find out which tables are available in the datasource

  • Find specific tables in the datasource

  • Run SQL statements to perform actions such as creating a table or deleting a table

  • Get database properties

  • Create a Recordset and connect to tables

  • Retrieve and manipulate table data