Microsoft KB Archive/297211

= PRB: Undocumented Filter Syntax for IReposQuery::GetCollection Method =

Article ID: 297211

Article Last Modified on 2/22/2007

-

APPLIES TO


 * Microsoft Visual Studio 6.0 Enterprise Edition
 * Microsoft Visual Studio 6.0 Professional Edition
 * Microsoft SQL Server 2000 Enterprise Edition

-



This article was previously published under Q297211



SYMPTOMS
The GetCollection method of the IReposQuery interface in SQL Server 2000 Metadata Services programming accepts a filter string to limit the collection that is returned. This filter string also accepts a special Implements or InstanceOf clause. These two clauses require a particular syntax that is not clearly documented in the Metadata Services 3.0 Software Development Kit (SDK) reference.



RESOLUTION
To resolve this problem, when you use either the Implements(interface) or the InstanceOf(class) clause, insert a space between the keyword (Implements or InstanceOf) and the opening left parenthesis. For example, insert a space after Implements as follows: Implements ([FileSystem._FolderDef]) Or, insert a space after InstanceOf as follows: InstanceOf ([FileSystem.FolderDef])



Steps to Reproduce Behavior
The following steps illustrate this problem in Microsoft Visual Basic. However, this problem also occurs when you use other client languages.  If you have not already done so, run the Visual Basic FileSys.vbp FileSystem sample that is included with the Repository 3.0 SDK, and populate your Repository with some sample folders and file names for testing purposes. Create a new Visual Basic Standard EXE project. Set a project reference to Microsoft Repository. Place a command button on Form1.  Paste the following code in the code module for Form1: Private Sub Command1_Click Dim repos As Repository Dim reposq As IReposQuery Dim strFilter Dim coll As IObjectCol2 Dim itm As RepositoryObject Set repos = New Repository repos.Open &quot;Driver={SQL Server};Server=(local);Database=FileSys;UID=user;PWD=password&quot; Set reposq = repos strFilter = &quot;[FileSystem._FolderDef.Name] LIKE '%'&quot; Debug.Print strFilter Set coll = reposq.GetCollection(strFilter, FILTERCOL_SYNC) For Each itm In coll Debug.Print vbTab & itm.Name Next End Sub  Edit the ODBC connection parameters for your SQL Server and Repository database.</li> Run the project, and click the command button. In the Immediate (Debug) window, notice that this filter has returned all items, both folders and files, that you saved to your FileSystem repository because the &quot;Name&quot; property on which you filtered is defined on the parent FolderItemDef interface, which both FolderDef and FileDef inherit.</li>  To return only the folders, add an Implements clause to the Filter expression as follows: strFilter = &quot;[FileSystem._FolderDef.Name] LIKE '%' AND &quot; & _ &quot;Implements ([FileSystem._FolderDef])&quot; </li> Run the code again. Notice that only the folders are listed in the Debug window (that is, items that implement the _FolderDef interface). Notice the space after the Implements keyword.</li> Remove the space after Implements, and run the code again. You receive the following error message, which is misleading but alerts you to the invalid syntax:

The property name [FileSystem._FolderDef]) inside [] could not be resolved.

Note the mismatched parentheses in the error message.</li>  Change the filter string as follows: strFilter = &quot;[FileSystem._FolderDef.Name] LIKE '%' AND &quot; & _ &quot;InstanceOf ([FileSystem.FolderDef])&quot; </li> Run the code again. This also returns only folders (that is, instances of the FolderDef class).</li> Remove the space after InstanceOf, and run the code again. You receive the same error message as above.</li></ol>

Additional query words: repository getcollection ireposquery filter

Keywords: kbprb KB297211

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.