Querying a Repository Database Using SQL Views
To query a database using a view, you can use the IRepositoryODBC::ExecuteQuery method or you can run queries using SQL commands. The following example illustrates one approach. Other query syntax is required for querying Workspace views.
dim oRepos as Repository
dim ODBC as IRepositoryODBC
set ODBC=oRepos
ODBC.ExcecuteQuery("select intID from cTable where TableName="Customer")
The addition of a SQL view makes it easier to build select statements that correspond to your information model.
To perform a query, the object that you specify must implement IRepositoryODBC, which provides the ExecuteQuery method.
Instead of referencing the generated view in your SELECT statement, you specify the class, interface, or relationship object for which you defined a view definition and generated the corresponding view. In this case, cTable is a class that has a corresponding IViewClassDef defined for it, and a generated view that is available to it. Microsoft® SQL Server™ 2000 uses the generated SQL view transparently to process the query. You do not need to specify the name of the view when creating the query.
Note Collection filters can also be used to facilitate querying. For more information, see Filtering Collections.
Querying Workspace Views
Workspace views are created as user-defined functions. The name of the user-defined function is the view name that you specify. When querying a workspace, you must pass in the workspace IntID.
The following example illustrates one way to query a Workspace view. In this example, MyUDF is the view name.
dim oRepos as Repository
dim ODBC as IRepositoryODBC
set ODBC=oRepos
ODBC.ExcecuteQuery("select * from MyUDF(IntID)")