Login Register Actian.com  

Actian Community Wiki

Navigation
Learn About
Developing With
Ingres Talk
Information
Toolbox

OpenAPI Examples

From Ingres Community Wiki

Jump to: navigation, search

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:

  • PAUSE Pause some number of seconds.
  • RAISE Call IIapi_query() to raise a database event.
  • INFO Call IIapi_getQueryInfo() to check raise event status.
  • CLOSE Call IIapi_close() to close request statement handle.
  • DONE Check if all events raised (done) or continue with PAUSE.
apiautil.c OpenAPI asynchronous demo utility module.

This module provides routine to perform common API calls synchronously.

The following functions are provided:

  • IIdemo_conn() Call IIapi_connect().
  • IIdemo_disconn() Call IIapi_disconnect().
  • IIdemo_abort() Call IIapi_abort().
  • IIdemo_autocommit() Call IIapi_autocommit().
  • IIdemo_query() Call IIapi_{query, getQueryInfo, close}().
  • IIdemo_checkError() Print API call status and error information.
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()

  • Register distributed transaction ID.
  • Prepare distributed transaction to be committed.
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()

  • Register distributed transaction ID.
  • Establish connection with distributed transaction.
  • Rollback distributed transaction.
  • Release distributed transaction ID.
apisauto.c Demonstrates using IIapi_autocommit().

Following actions are demonstrate in the main()

    • Enable autocommit
    • Disable autocommit
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()

  • Set EnvParam for segment length
  • Issue query
  • Get query result descriptors
  • Get query results
  • Close query processing
  • Free query resources.
apiscdel.c Demonstrates using IIapi_query(), IIapi_setDescriptor() and IIapi_putParams() to do a cursor positioned delete.

Following actions are demonstrated in the main()

  • Open cursor
  • Position cursor on row
  • Issue cursor delete statement
  • Describe parameters
  • Send parameter values
  • Get delete statement results
  • Free delete statement resources
  • Get cursor results
  • Free cursor resources
apiscomm.c Demonstrates using IIapi_commit()

Following actions are demonstrated in the main()

  • Commit transaction
apisconn.c Demonstrates using IIapi_connect(),IIapi_setConnectParam(), IIapi_disconnect() and IIapi_abort()

Following actions are demonstrate in the main()

  • Connect (no conn parms)
  • Disconnect
  • Set Connection Parameters
  • Connect (with conn parms)
  • Abort Connection
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()

  • Copy data from program into table.
  • Copy data into program from table.
apiscupd.c Demonstrates using IIapi_query(), IIapi_setDescriptor() and IIapi_putParams() to do a cursor positioned update.

Following actions are demonstrated in the main()

  • Open cursor
  • Position cursor on row
  • Issue cursor update statement
  • Describe parameters
  • Send parameter values
  • Get update statement results
  • Free update statement resources
  • Get cursor results
  • Free cursor resources
apisdata.c Demonstrates using IIapi_formatData() and IIapi_convertData()

Following actions are demonstrated in the main()

  • Set environment parameter
  • Convert string to DATE using environment date format.
  • Convert DATE to string using installation date format.
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()

  • Check status of statement with no rows.
  • Check status of insert statement.
  • Check status of invalid statement.
apisinit.c Demonstrates using IIapi_init(),IIapi_setEnvParam(), IIapi_releaseEnv() and IIapi_term()

Following actions are demonstrate in the main()

  • Initialize at level 1
  • Terminate API
  • Initialize at level 2
  • Set environment parameter
  • Release environmment resources
  • Terminate API
apisname.c Demonstrates using IIapi_connect(), IIapi_autocommit() and IIapi_query() to access the Name Server database.

Following actions are demonstrate in the main()

  • Connect to local Name Server
  • Enable Autocommit
  • Query connection info
  • Disable autocommit
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()

  • Create procedure
  • Execute procedure
  • Retrieve BYREF parameter results
  • Get procedure results
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()

  • Create procedure
  • Execute procedure
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()

  • Create procedure
  • Execute procedure
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()

  • Create procedure
  • Execute procedure
  • Retrieve result rows
  • Get procedure results
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()

  • Define repeated insert.
  • Execute repeated insert.
apisroll.c Demonstrates using IIapi_savePoint() and IIapi_rollback()

Following actions are demonstrated in the main()

  • Create savepoint
  • Rollback to savepoint
  • Rollback transaction.
apisscrl.c Demonstrates using IIapi_scroll() and IIapi_position().

Scroll and position in a result set.

Following actions are demonstrated in the main()

  • Issue query
  • Get query result descriptors
  • Scroll/position cursor
  • Get query results
  • Free query resources
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()

  • Issue query
  • Get query result descriptors
  • Get query results
  • Cancel query processing
  • Free query resources.
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()

  • Issue query
  • Get query result descriptors
  • Get query results
  • Cancel query processing
  • Free query resources.
Personal tools
© 2011 Actian Corporation. All Rights Reserved