PRB: Undocumented Filter Syntax for IReposQuery::GetCollection Method

Article translations Article translations
Article ID: 297211 - View products that this article applies to.
This article was previously published under Q297211
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

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])
				

MORE INFORMATION

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.
  1. 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.
  2. Create a new Visual Basic Standard EXE project.
  3. Set a project reference to Microsoft Repository.
  4. Place a command button on Form1.
  5. 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 "Driver={SQL Server};Server=(local);Database=FileSys;UID=user;PWD=password"
      Set reposq = repos
      strFilter = "[FileSystem._FolderDef.Name] LIKE '%'"
      Debug.Print strFilter
      Set coll = reposq.GetCollection(strFilter, FILTERCOL_SYNC)
      For Each itm In coll
        Debug.Print vbTab & itm.Name
      Next
    End Sub
    					
  6. Edit the ODBC connection parameters for your SQL Server and Repository database.
  7. 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 "Name" property on which you filtered is defined on the parent FolderItemDef interface, which both FolderDef and FileDef inherit.
  8. To return only the folders, add an Implements() clause to the Filter expression as follows:
      strFilter = "[FileSystem._FolderDef.Name] LIKE '%' AND " & _
        "Implements ([FileSystem._FolderDef])"
    					
  9. 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.
  10. 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.
  11. Change the filter string as follows:
      strFilter = "[FileSystem._FolderDef.Name] LIKE '%' AND " & _
        "InstanceOf ([FileSystem.FolderDef])"
    					
  12. Run the code again. This also returns only folders (that is, instances of the FolderDef class).
  13. Remove the space after InstanceOf, and run the code again. You receive the same error message as above.

Properties

Article ID: 297211 - Last Review: February 27, 2014 - Revision: 2.3
APPLIES TO
  • Microsoft Visual Studio 6.0 Enterprise Edition
  • Microsoft Visual Studio 6.0 Professional Edition
  • Microsoft SQL Server 2000 Enterprise Edition
Keywords: 
kbnosurvey kbarchive kbprb KB297211

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com