Navigation
Learn About
Developing With
Ingres Talk
Information
Toolbox
Views
OpenAPI Examples
From Ingres Community Wiki
The following code samples demonstrate use of Ingres OpenAPI.
Community Provided Examples
| API Demo Program | Description |
|---|---|
| Row count from a select query | Until Ingres 9.2.0 there was only one way to get the number of rows returned with a "SELECT" statement, using "IIapi_getQueryInfo()". Unfortunately if called before all the results are fetched from Ingres "IIapi_getQueryInfo()" will terminate any existing results still to be fetched. With Ingres 9.2 the row count can be obtained using scrollable cursors. |
| Using Describe Input | Demonstrates using IIapi_setDescriptor( ) and IIapi_putParams( ). |
| Searched timestamp queries | Shows the use of timestamps as dynamic parameters for insert and searched fetch queries. |
| Searched Update timestamp queries | Shows the use of timestamps as dynamic parameters for insert, fetch and update queries. |
| Batch Fetching using OpenAPI | Fetching more than one row at a time improves the performance of an application by reducing traffic to/from the server |
| OpenAPI query literals - Apibatch0.c | Ingres 10 will add full support for Batch Execution. This program is a test program to demonstrate the use of OpenAPI query literals with batch execution. |
| OpenAPI parameterized queries - Apibatch1.c | Ingres 10 will add full support for Batch Execution. This program is a test program to demonstrate the use of OpenAPI parameterized queries with batch execution. |
| OpenAPI prepared queries - Apibatch2.c | Ingres 10 will add full support for Batch Execution. This program is a test program to demonstrate the use of OpenAPI prepared queries with batch execution. |
| OpenAPI database procedures - Apibatch3.c | Ingres 10 will add full support for Batch Execution. This program is a test program to demonstrate the use of OpenAPI database procedures with batch execution. |
Examples Provided with the Ingres Distribution
Several synchronous and asynchronous OpenAPI examples are provided as part of the Ingres distribution. These examples are installed into the %II_SYSTEM%\ingres\demo\api directory. The examples are documented below:
| API Demo Program | Description | |
|---|---|---|
| apiademo.c | OpenAPI asynchronous demo main control module.
This program demonstrates calling OpenAPI asynchronously, using callback functions for notification of OpenAPI call completion and the processing of database events using OpenAPI. The program consist of four modules: a main control module (apiademo.c), a server module (apiasvr.c), a client module (apiaclnt.c) and a utility module (apiautil.c). The server module establishes a connection to the target database, creates a database event and registers to receive event notification. The server then waits for database events to be received. The client module establishes it's own database connection, raises a series of database events and terminates. The server terminates when a database event is received indicating that termination has been requested. The main control module processes the command line arguments and initializes, runs and terminates the client and server modules. The utility module provides common synchronous OpenAPI calls used during initialization and termination. The program can be run as a client, a server or both. Multiple clients and multiple servers may be run concurrently. | |
| apiasvr.c | OpenAPI asynchronous demo server module.
The server demo establishes a connection with the target database, creates and registers a database event and waits to receive event notifications. Server execution is implemented in a single processing function with a set of actions. Each action represents a state in a finite state machine. | |
| apiaclnt.c | OpenAPI asynchronous demo client module.
The client demo establishes a connection with the target database and raises database events at (somewhat) random intervals. Client execution is implemented as a series of callback functions. Each asynchronous OpenAPI request specifies the next sequential function as its callback. Each function represents a state in a simple finite state machine as follows:
| |
| apiautil.c | OpenAPI asynchronous demo utility module.
This module provides routine to perform common API calls synchronously. The following functions are provided:
| |
| apis2ph1.c | Demonstrates using IIapi_registerXID(), IIapi_prepareCommit().
First part of the two phase commit demo. Begin a distributed transaction and exit without disconnecting. Run apis2ph2 to finish processing of distributed transaction. Following actions are demonstrated in the main()
| |
| apis2ph2.c | Demonstrates using IIapi_registerXID(), IIapi_connect() with transaction handle, IIapi_releaseXID().
Second part of two phase commit demo. Run apis2ph1 to begin distributed transaction. Reconnects to distribute transaction and rolls back the transaction. Following actions are demonstrated in the main()
| |
| apisauto.c | Demonstrates using IIapi_autocommit().
Following actions are demonstrate in the main()
| |
| apisblob.c | Demonstrates using IIapi_setEnvParam(), IIapi_query(), IIapi_getDescriptor(), IIapi_getColumns(), IIapi_getQueryInfo(), and IIapi_close().
SELECT row with blob data. Following actions are demonstrated in the main()
| |
| apiscdel.c | Demonstrates using IIapi_query(), IIapi_setDescriptor() and IIapi_putParams() to do a cursor positioned delete.
Following actions are demonstrated in the main()
| |
| apiscomm.c | Demonstrates using IIapi_commit()
Following actions are demonstrated in the main()
| |
| apisconn.c | Demonstrates using IIapi_connect(),IIapi_setConnectParam(), IIapi_disconnect() and IIapi_abort()
Following actions are demonstrate in the main()
| |
| apiscopy.c | Demonstrates using IIapi_query(), IIapi_getCopyMap(), IIapi_putColumns() and IIapi_getColumns() to execute 'copy from' and 'copy into' statements.
Following actions are demonstrated in the main()
| |
| apiscupd.c | Demonstrates using IIapi_query(), IIapi_setDescriptor() and IIapi_putParams() to do a cursor positioned update.
Following actions are demonstrated in the main()
| |
| apisdata.c | Demonstrates using IIapi_formatData() and IIapi_convertData()
Following actions are demonstrated in the main()
| |
| apiserr.c | This demo program can be taken as an example of a generic error
handler function for handling OpenAPI errors returned to the application. Additionally please refer to the OpenAPI documentation, section "Generic Parameters" to understand the meaning of each of IIAPI_ST_* error codes returned in "gp_status" o/p parameter of IIAPI_GENPARM structure. Demonstrates using IIapi_getQueryInfo() and IIapi_getErrorInfo(). Following actions are demonstrated in the main()
| |
| apisinit.c | Demonstrates using IIapi_init(),IIapi_setEnvParam(), IIapi_releaseEnv() and IIapi_term()
Following actions are demonstrate in the main()
| |
| apisname.c | Demonstrates using IIapi_connect(), IIapi_autocommit() and IIapi_query() to access the Name Server database.
Following actions are demonstrate in the main()
| |
| apisparm.c | Demonstrates using IIapi_setDescriptor() and IIapi_putParams(). | |
| apisprbr.c | Demonstrates using IIapi_query(), IIapi_setDescriptor(), IIapi_putParams(), IIapi_getDescriptor() and IIapi_getColumns() to execute a database procedure with BYREF parameters and retrieve the parameter result and procedure return values.
Following actions are demonstrated in the main()
| |
| apisprgt.c | Demonstrates using IIapi_query(), IIapi_setDescriptor() and IIapi_putParams() to execute a database procedure with a global temporary table parameter.
Following actions are demonstrated in the main()
| |
| apisproc.c | Demonstrates using IIapi_query(), IIapi_setDescriptor(), IIapi_putParams(), IIapi_getQInfo() and IIapi_close() to execute a database procedure.
Following actions are demonstrated in the main()
| |
| apisprrp.c | Demonstrates using IIapi_query(), IIapi_setDescriptor(), IIapi_putParams(), IIapi_getDescriptor() and IIapi_getColumns() to execute a database procedure which returns multiple rows.
Following actions are demonstrated in the main()
| |
| apisrept.c | Demonstrates using IIapi_query(), IIapi_setDescriptor() and IIapi_putParams() to define and execute a repeated statement.
Following actions are demonstrated in the main()
| |
| apisroll.c | Demonstrates using IIapi_savePoint() and IIapi_rollback()
Following actions are demonstrated in the main()
| |
| apisscrl.c | Demonstrates using IIapi_scroll() and IIapi_position().
Scroll and position in a result set. Following actions are demonstrated in the main()
| |
| apisselc.c | Demonstrates using IIapi_query(), IIapi_getDescriptor(), IIapi_getColumns() and IIapi_close().
SELECT data using a cursor. Following actions are demonstrated in the main()
| |
| apissell.c | Demonstrates using IIapi_query(), IIapi_getDescriptor(), IIapi_getColumns(), IIapi_cancel() and IIapi_close().
SELECT data using a select loop. Following actions are demonstrated in the main()
|

