NotesDominoQuery sample
I have put together a small sample to demonstrate how to use NotesDominoQuery from LotusScript.
I created a new Class DQLWrapper. A little bit over the top, I know.
%REM Library 10010.dql Created Dec 30, 2018 by Ulrich Krause/singultus %END REM Option Declare %REM Class DqlWrapper %END REM Public Class DqlWrapper m_query As String m_session As NotesSession m_db As NotesDatabase m_ndq As NotesDominoQuery %REM Sub New %END REM Public Sub New(strDbFilePath As String) Set me.m_session = New NotesSession Set me.m_db = me.m_session.Getdatabase("",strDbFilePath, False) If ( me.m_db.Isopen ) then Set me.m_ndq = me.m_db.Createdominoquery() Else ' // do some error handling End if End Sub %REM Public function executeQuery() %END REM Public function executeQuery() As NotesDocumentCollection If ( me.m_query <> "" ) then Set executeQuery = me.m_ndq.Execute(me.m_query) Else Set executeQuery = nothing End If End Function %REM Public Function explainQuery() %END REM Public Function explainQuery() As String If ( me.m_query <> "" ) Then explainQuery = me.m_ndq.Explain(me.m_query) Else explainQuery = "" End If End Function %REM Public Function explainQuery() %END REM Public Function parseQuery() As String If ( me.m_query <> "" ) Then parseQuery = me.m_ndq.parse(me.m_query) Else parseQuery = "" End If End Function %REM Property query %END REM Public Property Set query As String me.m_query = query End property End Class
The query itself is executed from an agent that runs on the server. At the moment it is not possible to run a query client/ server.
Here is the code for the agent
%REM Agent dql.execute Created Dec 30, 2018 by Ulrich Krause/singultus %END REM Option Public Option Declare Use "10010.dql" Sub Initialize Dim query As String Dim col As NotesDocumentCollection query = "firstname = 'Ulrich' And lastname = 'Krause'" Dim dql As New DQlWrapper("names.nsf") dql.query = query If ( LCase(dql.parseQuery()) ="success" ) Then Set col = dql.executeQuery() MsgBox "QRY returns # docs: " + CStr(col.count) If ( col.count > 0 ) then Dim doc As NotesDocument Set doc = col.Getfirstdocument() MsgBox "UNID of first doc: " + doc.Universalid End if Else MsgBox dql.explainQuery() End If End Sub
You can now start the agent from the server console. You will get the number of documents for this query and the UNID of the first document found.
te amgr run "ec11.nsf" 'dql.execute'
[0DFC:001F-0FFC] 30.12.2018 13:49:10 AMgr: Start executing agent 'dql.execute' in 'ec11.nsf'
[0DFC:001F-0FFC] 30.12.2018 13:49:10 Agent Manager: Agent message: QRY returns # docs: 1
[0DFC:001F-0FFC] 30.12.2018 13:49:10 Agent Manager: Agent message: UNID of first doc: D8436D0F4E546BA3C12573FE0070AE88
[0DFC:001F-0FFC] 30.12.2018 13:49:10 AMgr: Agent 'dql.execute' in 'ec11.nsf' completed execution
If your query contains errors / is not understandable, you will see an output similar like this on your console
[0DFC:0020-11D0] 30.12.2018 13:59:45 Agent Manager: Agent 'dql.execute' error: Domino Query execution error: Query is not understandable - syntax error - processing or expecting operator (=, <, <= …) token syntax (Call hint: OSCalls::OSLocalAllc, Core call
0) firstname = 'Ulrich' And lastname IS 'Krause' …………………………….^……….. ****
[0DFC:0020-11D0] 30.12.2018 13:59:45 AMgr: Agent 'dql.execute' in 'ec11.nsf' completed execution