更高效的通用查询方法
因为文档少,所以采用了以下方法:
Function GetDocUnidByOneStrField(ViewName As String,FieldName As String,FieldVal As String) As String
Dim session As NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim TmpStr As Variant
Set session= New NotesSession
Set db = session.CurrentDatabase '(session、db是全局的,此处为示例代码)
Set view = db.GetView( ViewName )
GetDocUnidByOneField=""
Set doc = view.GetFirstDocument()
While Not(doc Is Nothing)
TmpStr = doc.GetItemValue("""" & FieldName & """")(0)
If FieldVal =TmpStr Then
GetDocUnidByOneField=doc.UniversalID
Goto last
End If
Set doc = view.GetNextDocument(doc)
Wend
last:
Set view = Nothing
Set doc = Nothing
End Function
说明:符合域值条件的文档只取第一条
问题:
1:TmpStr返回为空,但对应文档中的数据是确实存在的。
2:效率低下,有没有更好的办法?不采用GetDocumentByKey原因是因为域太多,不可能每个都建索引。
谢谢!
Function GetDocUnidByOneStrField(ViewName As String,FieldName As String,FieldVal As String) As String
Dim session As NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim TmpStr As Variant
Set session= New NotesSession
Set db = session.CurrentDatabase '(session、db是全局的,此处为示例代码)
Set view = db.GetView( ViewName )
GetDocUnidByOneField=""
Set doc = view.GetFirstDocument()
While Not(doc Is Nothing)
TmpStr = doc.GetItemValue("""" & FieldName & """")(0)
If FieldVal =TmpStr Then
GetDocUnidByOneField=doc.UniversalID
Goto last
End If
Set doc = view.GetNextDocument(doc)
Wend
last:
Set view = Nothing
Set doc = Nothing
End Function
说明:符合域值条件的文档只取第一条
问题:
1:TmpStr返回为空,但对应文档中的数据是确实存在的。
2:效率低下,有没有更好的办法?不采用GetDocumentByKey原因是因为域太多,不可能每个都建索引。
谢谢!
...全文
相关推荐
通用动态多条件查询方法的研究与实现
从基于SQL语句查询优化的角度出发,对当前数据库应用程序研发中的动态多条件查询方法进行了探究与对比分析,进而提出了一种高效通用的动态多条件查询方法。该方法在当前的动态多条件查询方法的基础上作了巧妙的改进,提高了执行效率,所形成的SQL语句及程序代码简洁灵活,适用于通用查询模块的设计或高效搜索引擎的研发。
【MP 中常用的查询方法和 API】
【MP 中常用的查询方法和 API】
一种通用的交叉表查询方法的实现.pdf
一种通用的交叉表查询方法的实现.pdf...............
Java中的万能查询方法(源码)
用反射做的的万能查询方法,只要传实体类和SQL语句即可
通过反射机制写的通用的方法
通过反射机制写的通用的方法,查询出对应的对象信息出来,通过一个SQL语句 返回一个对象或列表,在使用方法时要确保表名和实体名称一致,如果不一致,根据自己的业务规则需要改成一致,


