db.open-table

function

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

Returns: A specific table of type db.table.


Declaration
define external db.table function db.open-table
  in    value   db.database  database
  named value   stream      table

Argument definitions

database
is a db.database object representing an open database connection.
table
is the name of the table in the database you wish to access.


Purpose

Use db.open-table to attach a db.table OMX item to an existing table in the database.

Requirements

The database connection represented by database must be:

The table must exist (else external exception OMDB501).

Usage Notes

You may open a table that is already opened. The resulting db.table object behaves independently, unlike a copy.

Example

This code sample shows two different ways of opening a table. The choice depends on whether you want to reuse the table connection or not.

  import "omdb.xmd" prefixed by db.
  
  process
      local db.database this-db
      local db.table course
      local db.table course-2
      local stream SQL-insert initial
      {  "insert into Course values " ||
          " ( '503', 'Learning Through Pain'  )"
      }
      local stream course-data variable initial
      {   '504' with key 'CID',
           'What is that Sound?' with key 'CourseName'
      }
  
      set this-db to db.open-odbc 'dbDemo'
  
      set course to db.open-table in this-db table 'Course'
      db.execute-in this-db sql SQL-insert
  
      db.insert into db.open-table in this-db table 'Course' from course-data