Example
The following example steps you through the process of creating a database object, connecting to a datasource, creating a table, and moving data between the database and IDL. The example uses the SQLAnywhere server; you will need to replace references to the SQLAnywhere server with references to your own specific database server. In order to work through this example, you will need to be able to connect to and log on to your database server.
First, create a database object. Enter the following at the IDL command prompt:
Use the GetDatasources method to discover the names of the datasources available on your system, the print the list to your command log window:
IDL will print something like the following:
Connect to the SQLAnywhere server. (Substitute your own datasource, username, and password.)
Get a list of the available tables:
IDL will print something like the following:
Create a new table named "im_info" using SQL commands:
oDB->ExecuteSQL, $ "create table im_info (id integer, x integer," + $ "y integer, data image, name char(50))"
Now create a Recordset object and connect to the table you just created:
Add a record to the object. This record contains four fields that describe an image: the width of the image, the height of the image, the image data itself, and the name of the image.
Move the current location in the table (the cursor position) to the first row:
You can check the value of the variable status and report on whether the move was successful:
Retrieve the information from this record into IDL variables:
X = oRS->GetField(1) ;X size of image Y = oRS->GetField(2) ;Y size of image image = oRS->GetField(3) ;Image data name = oRS->getField(4) ;Image name
Create an IDL window to display the image:
Reform the image into two dimensions (ODBC data is stored as a one-dimensional stream of bytes):
Display the image:
Now, delete the im_info table and destroy the database objects: