HomeActive Query Builder - Metadata handling and filtrationMetadata handling and filtration in Java, VCL and ActiveX EditionsLoading metadata from several databases at once

2.2. Loading metadata from several databases at once

Warning:

This article might be obsolete!

It is valid for ASP.NET, Java, ActiveX, VCL editions, and for previous version of Active Query Builder WinForms .NET Edition (1.x).

The appropriate article for Active Query Builder 2 WinForms .NET Editon can be found here:

Active Query Builder is intended to build, parse and analyze SQL queries, but not to execute them in any way. This means that you can load metadata from several databases at once into the component's metadata container, and the component will be able to build a query using these objects (by the rules of specific syntax provider).

Thus, if you add objects from several databases of a single MS SQL Server, this server will be able to execute this query. But if you'll try to add object from several servers not linked with each other, no one can execute this query.

Some database servers (ex. MS SQL, Oracle) allow to link tables and entire databases from other servers and execute SQL queries against them.

The other way is to analyze the query, execute it's parts against respective database servers and combine their results. It is not easy to implement, but I know that some of our customers have dealt successfully with this task.

To load metadata from different databases, use the QueryBuilder.MetadataContainer.LoadMetadataByMask method.

This method accepts three parameters: Object name mask, Schema name mask and Database name. First two parameters are used for metadata filtration. These masks act exactly as the LIKE operator, so passing '%' value to these parameter instructs the component to load all names. Database name could be omitted, to load metadata from the currently active database.

To load all objects from the "db_name" database, you should write the following code:

QueryBuilder.MetadataContainer.LoadMetadataByMask("%", "%", "db_name");

To load metadata from different servers, follow the steps below.

  1. Set the WorkOffine (OfflineMode in .NET Edition) property to True.
  2. Set the right syntax and metadata providers for a database server.
  3. Connect to the database server.
  4. Load Metadata from the database using the LoadMetadataByMask method.
  5. Disconnect from the server.

Repeat steps 2-5 for all subsequent databases you want to extract metadata from.

After that you can save all metadata to the XML file and use it afterwards.

---

To get list of all databases from server, use the GetDatabaseList method:

SQLQualifiedNameList dbList = new SQLQualifiedNameList(queryBuilder1.SQLContext);
queryBuilder1.GetDatabaseList(dbList);
for (int I = 0; I <= dbList.Count - 1; I++)
{
   queryBuilder1.LoadMetadata(dbList[I]);
}

This page was: Helpful | Not Helpful