ICatalogManager3::Query Method [C++]

Use this method to perform queries against product, variant, and category data in one or more catalogs. This method is included for backward compatibility only since it does not support Commerce Server 2002 features such as multi-language catalogs. The recommended method for enabling the Query method functionality is the Search method.

Definition

[C++]

HRESULT ICatalogManager3::Query(BSTRstrPhrase,
  VARIANTstrCatalogsToSearch,
  VARIANTeClassTypeRequired,
  VARIANTstrPropertiesToReturn,
  VARIANTstrPropertyToSortOn,
  VARIANT_BOOLfSortAscending,
  VARIANTlStartingRecord,
  VARIANTlRecordsToRetrieve,
  VARIANT*plTotalRecordsInQuery,
  _Recordset**ppRSResult);

[Visual Basic]

Function Query(strPhrase As String,
  Optional strCatalogsToSearch As Variant,
  Optional eClassTypeRequired As Variant,
  Optional strPropertiesToReturn As Variant,
  Optional strPropertyToSortOn As Variant,
  Optional fSortAscending As Boolean,
  Optional lStartingRecord As Variant,
  Optional lRecordsToRetrieve As Variant,
  Optional plTotalRecordsInQuery As Variant) As _Recordset

Parameters

  • strPhrase[C++]
    [in] A BSTR that contains the search phrase.
  • strPhrase[Visual Basic]
    A String that contains the search phrase.
  • strCatalogsToSearch[C++]
    [in, optional] A VARIANT that contains the catalogs to search as a comma-separated list. An empty string indicates search all catalogs.
  • strCatalogsToSearch[Visual Basic]
    A Variant that contains the catalogs to search as a comma-separated list. An empty string indicates search all catalogs.
  • eClassTypeRequired[C++]
    [in, optional] A Variant that contains the catalog class wanted. Valid values are from the CatalogClassTypeEnum enumeration, and are described in the Remarks section.
  • eClassTypeRequired[Visual Basic]
    A Variant that contains the catalog class wanted. Valid values are from the CatalogClassTypeEnum enumeration, and are described in the Remarks section.
  • strPropertiesToReturn[C++]
    [in, optional] A VARIANT that contains the properties to return as a comma-separated list.
  • strPropertiesToReturn[Visual Basic]
    A Variant that contains the properties to return as a comma-separated list.
  • strPropertyToSortOn[C++]
    [in, optional] A VARIANT that contains the property on which to sort. This must be a property in the returned recordset.
  • strPropertyToSortOn[Visual Basic]
    A Variant that contains the property on which to sort. This must be a property in the returned recordset.
  • fSortAscending[C++]
    [in, defaultvalue (-1)] A VARIANT_BOOL that specifies whether to sort in ascending or descending order. A value of True indicates that the returned recordset will be sorted in ascending order. A value of False indicates that the returned recordset will be sorted in descending order.
  • fSortAscending[Visual Basic]
    A Boolean that specifies whether to sort in ascending or descending order. A value of True indicates that the returned recordset will be sorted in ascending order. A value of False indicates that the returned recordset will be sorted in descending order. The default value is True.
  • lStartingRecord[C++]
    [in, optional] A VARIANT that contains the starting record to retrieve. A value of one (1) indicates the first record.
  • lStartingRecord[Visual Basic]
    A Variant that contains the starting record to retrieve. A value of one (1) indicates the first record.
  • lRecordsToRetrieve[C++]
    [in, optional] A VARIANT that contains the number of records to retrieve, beginning from the starting record. A value of minus one (-1) indicates return all records.
  • lRecordsToRetrieve[Visual Basic]
    A Variant that contains the number of records to retrieve, beginning from the starting record. A value of minus one (-1) indicates return all records.
  • plTotalRecordsInQuery[C++]
    [out, optional] A pointer to a VARIANT used to return the total number of records matching the query.
  • plTotalRecordsInQuery[Visual Basic]
    A Variant used to return the total number of records matching the query.
  • ppRSResult[C++]
    [out, retval] A pointer to a _Recordset object used to return the search results.

Return Values

[C++] This method returns an HRESULT indicating whether it completed successfully. See the Error Values section for more details.

[Visual Basic] If this method completes successfully, it returns a Recordset object containing the search results.

Error Values

[C++] This method returns S_OK (0x00000000) to indicate success and either standard or custom COM HRESULT error values to indicate failure. For more information about standard COM errors, see Standard COM Errors.

[Visual Basic] This method sets the Number property of the global Err object to S_OK (&H00000000) to indicate success and to either standard or custom COM error values to indicate failure. For more information about standard COM errors, see Standard COM Errors.

The following table shows the custom COM errors that this method can return.

Constant Value Description
E_CAT_CATMGR_NOT_INITIALIZED

[C++] 0x889800B5

[Visual Basic] &H889800B5

The CatalogManager object has not been initialized. The CatalogManager object should be initialized before calling this method.
E_CAT_INVALID_RS_POINTER

[C++] 0x889800B7

[Visual Basic] &H889800B7

The recordset pointer that you specified is invalid.
E_INVALIDARG

[C++] 0x80070057

[Visual Basic] &H80070057

One or more arguments are invalid
E_CAT_INVALID_RETURN_PROPS

[C++] 0x8898011D

[Visual Basic] &H8898011D

The properties to return that you specified are invalid. Properties that contain a space should be enclosed in square brackets. Properties should not contain [ or ] and /* or -- in property names.
E_CAT_INVALID_SORT_PROPS

[C++] 0x8898011E

[Visual Basic] &H8898011E

The properties to sort that you specified are invalid. Properties that contain a space should be enclosed in square brackets. Properties should not contain [ or ] and /* or -- in property names.
S_FALSE 1 Query failed. The recordset is now NULL.
E_CAT_MULTI_CAT_QUERY_NEEDS_PROPS

[C++] 0x8898000F

[Visual Basic] &H8898000F

When performing a query against multiple catalogs, you should specify the actual properties to return.

[C++] Additional information may be available using the global Err object, which can be accessed using the API function GetErrorInfo. In particular, the GetDescription method of the IErrorInfo interface may return a text description of the error.

[Visual Basic] Additional information may be available using the global Err object. In particular, the Description property may contain a text description of the error.

Remarks

[C++] The plTotalRecordsInQuery and ppRSResult parameters contain valid data only if the method completes successfully.

[Visual Basic] The returned Recordset object and the plTotalRecordsInQuery parameter contain valid data only if the method completes successfully.

The Query method is used to perform arbitrary queries against product, product-variant, and category data in one or more catalogs. The strPhrase parameter is very similar to the ADO recordset Filter property. Simple queries should follow the key-operator-value convention (for example, length < 100). Queries whose value is a String data type should enclose that value in single quotes (for example, color = 'Blue'); additionally, if the string value contains unicode characters then it should be preceded with an N (for example, color = N'blue').

More sophisticated queries can be constructed by using the AND and OR operators to group multiple clauses, such as (level > 10) OR (Name = 'Bob' AND Title='CPA').

The following table shows the values of the CatalogClassTypeEnum enumeration, their associated names, and describes their use.

Name Value Description
cscCategoryClass 1 Requests category data.
cscProductVariantClass 2 Requests product variant data.
cscProductClass 4 Requests product data.
cscProductFamilyClass 8 Requests product family data.
cscProductFamilyForVariantsClass 16 Requests family for variant data, which means the product family of a product variant is being requested.
CscProductVariantsForFamily 32 Requests variants for family data, which means that all of the product variants for a product family are being requested.

The CatalogClassTypeEnum values can be combined in the eClassTypeRequired parameter with logical OR operators, so that specifying cscProductClassORcscProductVariantClass will return both product and product variant data.

The search results for multilingual catalogs will be returned in a single language. The language will be selected differently depending on the number of catalogs specified in the strCatalogsToSearch parameter. If a single catalog is specified, the results will be returned in the default language of the catalog. If multiple catalogs are specified, the results will be returned in the default system language of the Web server. If a catalog does not support the selected language only language insensitive properties will be returned for that catalog.

Use the Search method to specify the search language or for doing a free-text search and a query simultaneously.

The programming rules regarding the strPropertiesToReturn parameter vary depending if a single catalog name is passed in the strCatalogsToSearch parameter, or if multiple catalog names are passed. When a single catalog name is passed, the strPropertiesToReturn parameter is optional and defaults to all properties. When multiple catalog names are passed, the strPropertiesToReturn parameter is required.

If no value is specified for the strPropertiesToReturn parameter the method returns all fields in the specified catalog, otherwise it returns only the fields specified in the strPropertiesToReturn parameter. When specifying properties to return, or when specifying the strPropertyToSortOn parameter, enclose the field names in square brackets to avoid unintentional side effects in the SQL query created by this method. For example, use "[Property1], [Property2]" to specify two properties.

For more information about memory ownership issues related to COM property and method parameters, see Managing COM Parameter Memory.

[Visual Basic]

Example

'plTotalRecordsInQuery is an existing Long. 
'Examine it after the method returns to see if 
'there are more records to get.
Set rsQueryResults = myCatalogManager.Query("[Productid]='blue suede'", "ShoeCatalog", cscProductClass,"Price, SKU, Size", "SKU", TRUE, 1, 25, plTotalRecordsInQuery)

See Also

[C++]CatalogManager Object

[Visual Basic]CatalogManager Object

[C++]ICatalogManager3::FreeTextSearch

[Visual Basic]CatalogManager.FreeTextSearch

Copyright © 2005 Microsoft Corporation.
All rights reserved.