Ingres Examples

From Ingres Community Wiki

Jump to: navigation, search

This page contains a list of code samples dealing with the Ingres Technologies. For helpful articles, including integrating Ingres with other Technology see Tech Tips.

Contents

The following code samples demonstrate use of the Ingres DBMS

Community Provided Examples

Useful DBA Scripts

DBA Script Description
Utilitity to check status of Ingres Servers on Windows
Changing table structures
Collecting Ingres QEP and LockTrace Information Using JDBC
Summarise output of auditdb - Unix shell script

OME Examples

OME Program Examples Description
OME_README
OME base64()
OME checksum()
OME rand seq gen()
OME regex()
OME soundex dm()
OME unicode64()

Embedded SQL Examples

Embedded SQL Program Examples Description
Row Producing Procedure ESQL/C Example

Application Development

OpenROAD

Ingres OpenROAD Examples

JDBC

The following code samples demonstrate use of the Ingres JDBC Driver

Community Provided Examples

JDBC Program Examples Description
Simple Connect and SELECT Sample
Simple Java Example Accessing Ingres demodb
Collecting Ingres QEP and LockTrace Information Using JDBC
Using Java Property Resource Bundles
Using Multiple Threads in JDBC Applications

ODBC

The following code samples demonstrate use of the Ingres ODBC Driver

Community Provided Examples

ODBC Program Examples Description
Insert and Fetch of Blobs Using ODBC Create a table containing a long varchar. Read an ASCII file and insert contents into the table. Fetch and display the result.
Simple Select Using ODBC Select a column from the iitables catalog and display the result.
Getting Metadata Information about the ODBC Driver Use SQLGetInfo() and SQLGetTypeInfo() to show information about the ODBC driver and supported data types.

.NET

The following code samples demonstrate use of the Ingres .NET Data Provider.

Connections

.NET Program Examples Description
.NET - Connect to a database as current user

Executing Queries

.NET Program Examples Description
.NET - DataReader

DataSet

.NET Program Examples Description
.NET - DataSet

PHP

The following code samples are extracted from the test suite used for testing the PECL Ingres extension.

Connections

PHP Demo Program Description
PHP - Connect to a database as current user
PHP - Connect to a database with user+password
PHP - Connect to a database using a role
PHP - Connect to a database using a role and role password
PHP - Connect to a database changing the effective user
PHP - Connect to a database using a group
PHP - Connecting with a dbms password

Executing Queries

PHP Demo Program Description
PHP - Execute a simple select against default link - no results returned
PHP - Execute a simple select against default link - fetch object
PHP - Execute a simple select against default link - fetch row
PHP - Execute a simple select against default link - fetch assoc array
PHP - Nested (Master Detail) query
PHP - Connect to a database using a group
PHP - Connecting with a dbms password

Executing Queries With Parameters

PHP Demo Program Description
PHP - Execute a simple select using a parameter - fetch object
PHP - Execute an insert using a parameter
PHP - Execute a delete using a parameter
PHP - Execute an update using a parameter

Modifying The Default Table And Index Structures

PHP Demo Program Description
PHP - Specifying the default structure for a newly created table
PHP - Specifying the default structure for a new index

Adjusting The Timezone and Date Format

PHP Demo Program Description
PHP - Adjust the timezone to GMT and retrieve a date value
PHP - Adjust the timezone to NA-PACIFIC and retrieve a date value
PHP - Adjust the timezone to NA-EASTERN and retrieve a date value
PHP - Adjust the timezone to UNITED-KINGDOM and retrieve a date value
PHP - Adjust the timezone to HONG-KONG and retrieve a date value
PHP - Adjust the timezone to GMT-5 and retrieve a date value
PHP - Adjust the timezone to GMT3-AND-HALF and retrieve a date value
PHP - Adjust the date format to US and retrieve a date value
PHP - Adjust the date format to US and retrieve a date value
PHP - Adjust the date format to MULTINATIONAL and retrieve a date value
PHP - Adjust the date format to MULTINATIONAL4 and retrieve a date value
PHP - Adjust the date format to GERMAN and retrieve a date value
PHP - Adjust the date format to ISO and retrieve a date value
PHP - Adjust the date format to ISO4 and retrieve a date value
PHP - Adjust the date format to FINNISH and retrieve a date value
PHP - Adjust the date format to DMY and retrieve a date value
PHP - Adjust the date format to YMD and retrieve a date value
PHP - Adjust the date format to MDY and retrieve a date value
PHP - Date century boundary

Adjusting The Money Format And Currency Position

PHP Demo Program Description
PHP - Setting money format on connection
PHP - Setting money format to € in the trailing position

Unicode

PHP Demo Program Description
PHP - Selecting Unicode data using NCHAR parameters
PHP - Executing a row producing procedure using NCHAR parameters

BLOBS

PHP Demo Program Description
PHP - Selecting a binary object
PHP - Inserting a binary object

Python

The following code samples demonstrate use of the Ingres Python Driver

Connections

Executing Queries

Ruby

Ruby Program Examples Description

OpenAPI

The following code samples demonstrate use of the 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 2006 release 3 the row count can be obtained using scrollable cursors.
Using Describe Input

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 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
Developing With