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: 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 ContentsGo Home

Copyright © 1996-2023, Sergei Kuchin, email: skuchin@gmail.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. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.