# MTQueryAdapter

The query adapter allows for the creation of queries that reside in query files. The queries are comprised of two parts: the query tag and the query string. The query tag identifies the query and must be unique within the query file.

The query string may be parameterized with parameters of the form %%PARAMTER%% where PARAMETER is the name of the parameter.

Note: Parameter must be enclosed in %%.

## Program ID

MetraTech.MTQueryAdapter.1

## MTQueryAdapter Methods

AddParam | The AddParam method adds the specified parameter to the query string. All instances of the parameter tag will be replaced by the parameter value that is passed.
ClearQuery | The ClearQuery method clears the currently set query tag.
GetAccessType | The GetAccessType method calls the GetAccessType method of the MTQueryCache to the get the access type from the cache.
GetDBName | The GetDBName method calls the GetDBName method of the MTQueryCache to the get the database name from the cache.
GetDBType | The GetDBType method calls the GetDBType method of the MTQueryCache to the get the database type from the cache.
GetDataSource | The GetDataSource method calls the GetDataSource method of the MTQueryCache to the get the data source from the cache.
GetProvider | The GetProvider method calls the GetProvider method of the MTQueryCache to the get the provider from the cache.
GetQuery | The GetQuery method gets the completed query string. If not all the parameters have been specified, an error is raised.
GetServerName | The GetServerName method calls the GetServerName method of the MTQueryCache to the get the server name from the cache.
GetTimeout | The GetTimeout method calls the GetTimeout method of the MTQueryCache to the get the timeout value from the cache.
GetUserName | The GetUserName method calls the GetUserName method of the MTQueryCache to the get the user name from the cache.
Init | The Init method initializes the query adapter by creating an instance of the query cache COM singleton. If the query cache already exists within this process, a pointer to the COM object is returned. Otherwise, a new instance of the query cache is created. The query cache is then initialized with the relative configuration path passed.
SetQueryTag | The SetQueryTag method calls the GetQueryString method of the MTQueryCache COM object. If the call to GetQueryString fails, an error is raised.

## Example

Example to be provided in a future release of this online help system.

# Method Detail

## AddParam

The AddParam method adds the specified parameter to the query string. All instances of the parameter tag will be replaced by the parameter value that is passed.

### Visual Basic Syntax

Sub AddParam(apParamTag As String, aParam)

### C++ Syntax

HRESULT AddParam([in] BSTR apParamTag, [in] VARIANT aParam);

### Arguments

apParamTag

The name of the parameter.

aParam

The value of the parameter.

### Errors Raised

0xE1500003L - Unable to get query. Invalid parameter.

0xE1500007L - Invalid type for query parameter.

0xE1500005L - Unable to get query. Unable to find query parameter.

## ClearQuery

The ClearQuery method clears the currently set query tag.

### Visual Basic Syntax

Sub ClearQuery()

### C++ Syntax

HRESULT ClearQuery();

## GetAccessType

The GetAccessType method calls the GetAccessType method of the MTQueryCache to the get the access type from the cache.

### Visual Basic Syntax

Function GetAccessType() As String

### C++ Syntax

HRESULT LogThis([in] MTLogLevel aLogLevel, [in] BSTR apData);

### Arguments

apAccessType

The access type from the dbaccess.xml file.

### Return Value

The access type.

## GetDBName

The GetDBName method calls the GetDBName method of the MTQueryCache to the get the database name from the cache.

### Visual Basic Syntax

Function GetDBName() As String

### C++ Syntax

HRESULT GetDBName([out,retval] BSTR *apDBName);

### Arguments

apDBName

The database name from the dbaccess.xml file.

### Return Value

The database name.

## GetDBType

The GetDBType method calls the GetDBType method of the MTQueryCache to get the database type from the cache.

### Visual Basic Syntax

Function GetDBType() As String

### C++ Syntax

HRESULT GetDBType([out,retval] BSTR *apDBType);

### Arguments

apDBType

The database type from the dbaccess.xml file.

### Return Value

The database type.

## GetDataSource

The GetDataSource method calls the GetDataSource method of the MTQueryCache to the get the data source from the cache.

### Visual Basic Syntax

Function GetDataSource() As String

### C++ Syntax

HRESULT GetDataSource([out,retval] BSTR *apDataSource);

### Arguments

apDataSource

The data source from the dbaccess.xml file.

### Return Value

The data source.

## GetProvider

The GetProvider method calls the GetProvider method of the MTQueryCache to get the provider from the cache.

### Visual Basic Syntax

Function GetProvider() As String

### C++ Syntax

HRESULT GetProvider([out,retval] BSTR *apProvider);

### Arguments

apProvider

The provider from the dbaccess.xml file.

### Return Value

The provider.

## GetServerName

The GetServerName method calls the GetServerName method of the MTQueryCache to get the server name from the cache.

### Visual Basic Syntax

Function GetServerName() As String

### C++ Syntax

HRESULT GetServerName([out,retval] BSTR *apServerName);

### Arguments

apServerName

The server name from the dbaccess.xml file.

### Return Value

The server name.

## GetTimeout

The GetTimeout method calls the GetTimeout method of the MTQueryCache to get the timeout value from the cache.

### Visual Basic Syntax

Function GetTimeout() As Long

### C++ Syntax

HRESULT GetTimeout([out,retval] long *apTimeout);

### Arguments

apTimeout

The timeout value from the dbaccess.xml file.

### Return Value

The timeout value.

## GetUserName

The GetUserName method calls the GetUserName method of the MTQueryCache to get the user name from the cache.

### Visual Basic Syntax

Function GetUserName() as String

### C++ Syntax

HRESULT GetUserName([out,retval] BSTR *apUserName);

### Arguments

apUserName

The database user name from the dbaccess.xml file.

### Return Value

The database user name.

## Init

The Init method initializes the query adapter by creating an instance of the query cache COM singleton. If the query cache already exists within this process a pointer to the COM object is returned. Otherwise, a new instance of the query cache is created. The query cache is then initialized with the relative configuration path passed.

### Visual Basic Syntax

Sub Init(apConfigPath As String)

### C++ Syntax

HRESULT Init([in] BSTR apConfigPath);

### Arguments

apConfigPath

The configuration path for the query file.

### Errors Raised

??? - Unable to initialize query adapter. Cannot create query cache.

??? - Unable to initialize query adapter.

## GetQuery

The GetQuery method gets the completed query string. If not all the parameters have been specified, an error is raised.

### Visual Basic Syntax

Function GetQuery() As String

### C++ Syntax

HRESULT GetQuery([out, retval] BSTR *apQuery);

### Arguments

apQuery

The query string.

### Return Value

The query string.

### Errors Raised

0xE150000CL - Unable to get query. Parameter not specified.

0xE1500005L - Unable to get query. No query specified.

## SetQueryTag

The SetQueryTag method calls the GetQueryString method of the MTQueryCache COM object. If the call to GetQueryString fails, an error is raised.

### Visual Basic Syntax

Sub SetQueryTag(apQueryTag As String)

### C++ Syntax

HRESULT SetQueryTag([in] BSTR apQueryTag);

### Arguments

apQueryTag

The query tag for the SQL query to create.