【问题标题】:Querying a specific record in Lotus Notes在 Lotus Notes 中查询特定记录
【发布时间】:2013-11-06 17:14:44
【问题描述】:

我习惯于使用关系数据库,您可以在其中定位特定记录。例如,使用下面的伪 sql。

SELECT id, name, otherVar FROM students WHERE id=:studentId

但是,我什至不确定如何在 Lotus Notes 中使用其平面数据模型来解决这个问题。我一直在谷歌上搜索,但不断想出如何更新 Lotus Notes 本身,而不是 Lotus Notes 内的文档。如果有一些 LN 专业知识的人可以为我指明正确的方向,那将不胜感激。

【问题讨论】:

    标签: lotus-notes


    【解决方案1】:

    使用 SQL 语句作为类比,假设您有一个视图 students,其中包含 idnameotherVar 列。 id 列应进行排序(升序或降序)。所以视图看起来像这样

    ╔════╦════════════╦═════════════╗
    ║ id ║ name       ║ otherVar    ║
    ╠════╬════════════╬═════════════╣
    ║ 1  ║ Daniel     ║ ----------  ║
    ║ 2  ║ Joseph     ║ ----------  ║
    ║ 3  ║ Michelle   ║ ----------  ║
    ╚════╩════════════╩═════════════╝
    

    要查找此视图,您可以在 LotusScript 中编写如下内容:

    Dim session As New NotesSession 'Get current session
    Dim currentDB As NotesDatabase
    Dim view As NotesView
    Dim doc As NotesDocument
    Dim studentId As String
    
    studentId = "<STUDENT_ID>" 'The student ID that needs to be searched
    Set currentDB = session.CurrentDatabase 'Get current database
    Set view = currentDB.GetView("students") 'Get the view
    Set doc = view.GetDocumentByKey(studentId, True) 'Look up the view with student ID to get the student document
    

    通过简单的 Google 搜索 NotesView 了解更多信息。在公式语言中,您可以将其写为:

    @DbLookup("Notes":"NoCache"; ""; "students"; "<STUDENT_ID>"; "<FIELD TO BE RETRIEVED>"; [FailSilent]);
    

    但如果您想进行复杂的计算,公式的灵活性不如 LotusScript。

    【讨论】:

    • @JRSmith: getDocumentByID 函数通过 Notes ID 获取文档。 Lotus Notes 中还有一个叫做 Universal ID 的东西,这个概念本身是一个单独的主题,所以我不会在这里离题。 getDocumentByID 函数将根据 Lotus Notes 在创建文档时生成的 Notes ID 获取文档。您确定 studentId 与文档的 Notes ID 相同吗?如果是,那么它可以工作,如果不是,那么你必须通过NotesView
    • 最好将其称为 NoteID,而不是 Notes ID——因为后者很容易与 Notes ID 文件混淆,这也是一个完全不同的概念。 NoteID 不是一个稳定的值。你永远无法确定它是否匹配任何东西。甚至不能保证在同一个数据库的两个不同副本中匹配同一个文档。
    • 另外,重要的是要指出 GetDocumentByKey 仅在 studentId 与“students”视图中第一个排序列的值匹配的情况下才有效。未能在列上设置排序属性是造成混淆的常见原因。
    • @JRSmith getDocumentByID 不是 NotesView 的方法的原因是视图不按 ID 组织数据。正如 Richard 所指出的,GetDocumentByKey 可用于通过第一个排序列的值来选择单个文档,或者如果您使用数组作为 GetDocumentByKey 的键,则可以通过多个排序列(当然是按顺序)。
    • @JRSmith:Notes 很强大,如果你只知道平台,一点也不复杂。我可以说我很高兴我没有将 SQL 用于我的解决方案。 ;-)
    【解决方案2】:

    也尝试使用 Domino 数据服务。让您的 Notes 管理员为 REST 服务工作打开数据库,您几乎可以从任何地方获取 Domino 数据!见Domino Data Services manual on the web

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多