IQueryDef Interface

IQueryDef sets the parameters needed to create an attribute query. The name of the table and a string defining the where clause are required. An optional list of columns may be included to specify the columns to be retrieved. If no columns are specified, all columns will be returned. IQueryDef only can be used with Geodatabase and Personal Geodatabase data sources.


Remarks :

The IQueryDef interface allows the definition of an attribute query based on one or more tables. Multiple table joins may be defined through the use of this interface.   

Note on ORDER BY and returning sorted data: To add ORDER BY and GROUP BY clauses to the attribute query the IQueryFilterDefinition::PostfixClause property can be used prior to creating the cursor.


The following code excerpts show how to get a reference to an IQueryDef interface, set the values of the SubFields, Tables, and WhereClause properties.

Getting a reference:

Dim  pQueryDef  As  IQueryDef
Set  pQueryDef  =  pFeatureWorkspace.CreateQueryDef

 

Setting the SubFields, Tables, and WhereClause:

'  Single table with a WhereClause
pQueryDef.Tables  =   " STATES "
pQueryDef.SubFields 
=   " * "  
pQueryDef.WhereClause 
=   " STATE_NAME = 'California' "

 

Multiple tables with a join.

pQueryDef.Tables  =      " STATES,STATEPOP,STATEAGE "  
pQueryDef.SubFields 
=   " * "  
pQueryDef.WhereClause 
=   " STATESID=POPID and POPID=AGEID "

 

Using Evaluate:


Dim  pCursor  As  ICursor 
pQueryDef.Evaluate pCursor

 

Below is a complete example for IQueryDef
     '  This example creates a QueryDef
    
    
' Connect to Geodatabase (SDE)
     Dim  pPropset  As  IPropertySet
    
Set  pPropset  =   New  PropertySet
    
With  pPropset
      .SetProperty 
" Server " " griot "
      .SetProperty 
" Instance " " 5151 "
      .SetProperty 
" Database " ""
      .SetProperty 
" user " " shell "
      .SetProperty 
" password " " shell "
      .SetProperty 
" version " " SDE.DEFAULT "
    
End   With
        
    
Dim  pFact  As  IWorkspaceFactory
    
Set  pFact  =   New  SdeWorkspaceFactory
    
    
'  Open the Feature Dataset
     Dim  pWorkspace  As  IWorkspace
    
Set  pWorkspace  =  pFact.Open(pPropset,  Me .hWnd)
    
    
'  Create Feature Workspace
     Dim  pFeatureWorkspace  As  IFeatureWorkspace
    
Set  pFeatureWorkspace  =  pWorkspace
    
    
'  Create Query Definition
     Dim  pQueryDef  As  IQueryDef
    
Set  pQueryDef  =  pFeatureWorkspace.CreateQueryDef
    
    
'  Provide list of tables to join
    pQueryDef.Tables  =   " datesjoin,dudatest "
    
    
'  Retrieve the fields from all  tables
    pQueryDef.SubFields  =   " sde.datesjoin.dt_field = sde.dudates.dt_field "
    
    
'  Set up join
    pQueryDef.WhereClause  =   " datesjoin.dt_field = dudates.dt_field "
    
    
'  Create FeatureDataset. Note the use of .OpenFeatureQuery. The
     '  Name "MyJoin" is the name of the result of the query def
     '  and is used in place of a Feature Class name.
     Dim  pFeatureDataset  As  IFeatureDataset
    
Set  pFeatureDataset  =  pFeatureWorkspace.OpenFeatureQuery( " MyJoin " , pQueryDef)
    
    
' Open Layer to test against
     Dim  pFeatureClassContainer  As  IFeatureClassContainer
    
Set  pFeatureClassContainer  =  pFeatureDataset
     
    
Dim  pFeatureClass  As  IFeatureClass
    
Set  pFeatureClass  =  pFeatureClassContainer.ClassByName( " MyJoin " )

 


转载于:https://www.cnblogs.com/iswszheng/archive/2009/04/23/1442050.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值