ISearchQueryHelper::GenerateSQLFromUserQuery Method

Generates a Structured Query Language (SQL) query based on a client-supplied query string expressed in either Advanced Query Syntax (AQS) or Natural Query Syntax (NQS).

Syntax

HRESULT GenerateSQLFromUserQuery(      
    LPCWSTR pszQuery,
    LPWSTR *pwszSQL
);

Parameters

  • pszQuery
    [in] A pointer to a null-terminated Unicode string containing a query in AQS or NQS.
  • pwszSQL
    [out, retval] Receives the address of a pointer to a SQL query string based on the query in the pszQuery parameter.

Return Value

Returns S_OK if successful, or an error value otherwise.

Remarks

This method generates SQL in the following form:

SELECT <QuerySelectColumns> FROM <CatalogName that created query helper>
    WHERE <Result of interpreting the User query passed into this function according to QuerySyntax>
          [ AND|OR <QueryWhereRestrictions>]

The SQL generation uses the settings specified in ISearchQueryHelper::put_QueryTermExpansion, ISearchQueryHelper::put_QueryContentProperties, and ISearchQueryHelper::put_QueryContentLocale.

ISearchQueryHelper::GenerateSQLFromUserQuery uses regional locale settings. However, ISearchQueryHelper does not use the regional locale settings. As a result, there are inconsistencies in the SQL returned from ISearchQueryHelper::GenerateSQLFromUserQuery and ISearchQueryHelper for region specific settings such as date formats. For example, if you set the locale for date/time to something other than the system locale, such as en-CA if the system locale is en-US, and enter Toybox -m -i "date:3/7/2008" -Y -s, the SQL returned will differ. The SQL from ISearchQueryHelper::GenerateSQLFromUserQuery will have parsed 3/7/2008 according to en-CA (seeking items dated 3rd of July, 2008) while the SQL from ISearchQueryHelper will have parsed 3/7/2008 according to en-US (seeking items dated 7th of March, 2008).

The DSearch code sample, available on Code Gallery and the Windows 7 SDK, demonstrates how to create a class for a static console application to query Windows Search using the Microsoft.Search.Interop assembly for ISearchQueryHelper.

See Also

ISearchQueryHelper::get_QuerySyntax