db.open-odbc

function

Library: Database access (OMDB)
Import : omdb.xmd

Returns: a db.database object for the opened database connection


Declaration
export external database function 
   open-odbc          value string dsn
                 user value string user-name optional initial { "" }
             password value string password  optional initial { "" }

      

Argument definitions

dsn
is the named data source you want to be connected.
user-name
is the user name that will be supplied to the database when the connection is made.
password
is the password that will be supplied to the database when the connection is made.


Purpose

Use db.open-odbc to create a connection to an ODBC-compliant database. The function returns an instance of type db.database.

Requirements

dsn must:

else external exception OMDB501 is thrown.

user-name and password are optional with default values of an empty string. Check the requirements for access to the specified database.

Usage Notes

You must have declared a shelf of type db.database (either global or local) to reuse a database connection in other OMDB functions.

This function will throw external exception OMDB501 if there are any ODBC driver errors. The exception will include any error numbers and descriptive text generated by the ODBC driver. Consult your driver documentation for further details on the error condition.

Example #1:

Create a connection to the ODBC compliant database named DatabaseDemo. No user-name or password is required to access this database. This connection can be reused in other OMDB functions.

  import "omdb.xmd" prefixed by db.
  
  process
     local db.database d
  
     set d to db.open-odbc "DatabaseDemo"

Example #2:

Create a record set from a query to an unopened ODBC compliant database named Collection1. A user-name and password are required to access this database. Note that you will be unable to reuse this connection in other OMDB functions as it has not been assigned to a shelf.

  import "omdb.xmd" prefixed by db.
  
  process
     local db.database d
     local db.field    q variable
  
     set d to db.open-odbc          "Collection1"
                               user "Phred123"
                           password "ecorde143"
     db.query      d
               sql ('SELECT EmpName, EmpName, {fn ucase(EmpName)}, Salary FROM Employee')
              into q