dtl


ODBC Catalog Functions

In many applications, we may need to perform queries to retrieve metadata about the database we are connected to. Common examples include retrieving a list of tables in the database, or retrieving a list of columns and column attributes in a table. DTL supports this by providing access to the ODBC catalog functions as though these were regular queries. As an example, here is how one would retrieve a list of tables and basic details using the ODBC SQLTables function:



// Call SQLTables to get a list of tables and descriptions from the DB

DynamicDBView<> view("_SQLTables", "");

DynamicDBView<>::sql_iterator it = view.begin(), end_it = view.end();



// Print titles of returned columns

vector <tstring> cols = it.GetBoundIOs().GetColumnNames();

copy(cols.begin(), cols.end(), ostream_iterator<tstring>(cout," "));

cout << endl;



// Print result of query

copy(it, end_it, ostream_iterator<variant_row>(cout,"\n"));

In general, to call an ODBC catalog function we create a query that begins with an underscore, followed by the name of the function we wish to call and a comma seperated list of arguments. (Any trailing arguments that are ommitted are assumed to be empty strings). The currently supported catalog functions with arguments are:



_SQLTables, TableName, SchemaName, CatalogName

_SQLColumns, ColumnName, TableName, SchemaName, CatalogName

To add more catalog function to this list, see CallCatalogFunction() in DBStmt.cpp

For details about the ODBC catalog functions see the ODBC documentation.

Note that you may also need to #define DTL_VARIANT_USE_FIXED_LEN_STRING to use a DynamicDBView with these ODBC catalog functions, depending on how your ODBC driver handles strings. See sql_iterator [3] for details.


[DTL Home]

Copyright 2002, Michael Gradman and Corwin Joy.

Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appears in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Corwin Joy and Michael Gradman make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.

SourceForge Logo

This site written using the ORB. [The ORB]