# Appendix B. OTL/ODBC, DB2-CLI, accessing system data dictionaries via OTL streams

ODBC / DB2 CLI specifications define functions like SQLTables for accessing system data dictionaries. OTL extends the stream notation for calling the following ODBC / DB2-CLI functions:

- SQLColumnPrivileges

- Parameter 1: CatalogName
- Parameter 2: SchemaName
- Parameter 3: TableName
- Parameter 4: ColumnName

- SQLColumns

- Parameter 1: CatalogName
- Parameter 2: SchemaName
- Parameter 3: TableName
- Parameter 4: ColumnName

- SQLForeignKeys

- Parameter 1: PKTableCatalog
- Parameter 2: PKTableSchema
- Parameter 3: PKTableName
- Parameter 4: FKTableCatalog
- Parameter 5: FKTableSchema
- Parameter 6: FKTableName

- SQLPrimaryKeys

- Parameter 1: CatalogName
- Parameter 2: SchemaName
- Parameter 3: TableName

- SQLProcedureColumns

- Parameter 1: CatalogName
- Parameter 2: SchemaName
- Parameter 3: ProcName
- Parameter 4: ColumnName

- SQLProcedures

- Parameter 1: CatalogName
- Parameter 2: SchemaName
- Parameter 3: ProcName

- SQLTablePrivileges

- Parameter 1: CatalogName
- Parameter 2: SchemaName
- Parameter 3: TableName

- SQLTables

- Parameter 1: CatalogName
- Parameter 2: SchemaName
- Parameter 3: TableName
- Parameter 4: TableType

The OTL stream extended format is as follows:

`$function_name {$1:'val1'} {$2:'val2'} {$3:'val3'} {$4: 'val4'} {$5: 'val5'} {$6: 'val6'}`

where `{}` mean an optional parameter, and `$function_name` means a name of the ODBC / DB2 CLI functions, listed above. Even though the ODBC and DB2 CLI specifications define the meaning of each ODBC / DB2 CLI function from the list above, in reality, it is specific to every single ODBC / DB2 CLI driver.

Examples

`1. "$SQLTables"` -- get a list of all tables in the current database.
`2. "$SQLTables $1:'%'"` -- get a list of all tables in all databases.
`3. "$SQLTables $1:'%' $2:'' $3:''"` -- get a list of databases on the current connection's server.
`4. "$SQLColumns $1:'DMS' $2:'dbo' $3:'test_tab'"` -- get a list of all columns of table "test_tab" that belongs to schema "dbo", catalog "DMS".

Here is an example of the full format of the OTL stream extended syntax:

`#define OTL_ODBC // or OTL_DB2_CLI`
`#include <otlv4.h>`
`...`
`otl_stream s(100,`
`"$SQLTables $1:'%'",`
`db);`
`...`
`while(!s.eof()){`
`s>>...;`
`}`
`...`

With this new feature (OTL stream extended format), it is possible to use OTL with ODBC data sources that do not have access to their system data dictionaries via normal "system views", which makes it impossible to query the system data dictionary as "SELECT * FROM a system view". Therefore, the only way to query the system data dictionary is via ODBC functions like SQLTables().

Prev Contents Go Home

Copyright © 1996, 2007, Sergei Kuchin, email: skuchin@ispwest.com, skuchin@gmail.com
.

Permission to use, copy, modify and redistribute this document for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies.