Query by formula
One way to get a collection of documents from an AbtLnDatabase is to use the allNotesFromQuery: method. A query is a formula, like a view selection formula. See your documentation about writing formulas using the formula language of Domino.
Note:
Be careful executing query formulas. If you query a huge database and you specify a non-selective formula (for example, @All), you will get back a huge collection of documents. The operation might take very long and even cause memory problems if the selection is too big.
Here is a code sample that retrieves documents from the provided sample database that have been stored with the Response form:
Note:
For this code sample, you use the vasample.nsf database which is located in the \sample directory of your VA Smalltalk install directory. Do not forget to copy the sample databases to a directory called \vasample in your local data directory. If you do not copy the files, you have to modify the sample code below to match your database location. If you have modified the contents of this database, you might get an empty answer set. If this is the case, specify a different query (i.e. SELECT Form = "MainTopic").
| localConnection sampleDatabase queryFormula answerSet|
"Initialize your runtime system"
AbtLnEnvironment startUp.
"Create a local connection"
localConnection := AbtLnConnection local.
"Open the sample database"
sampleDatabase := localConnection openDatabase: 'vasample\vasample'.
"execute the query to get all the documents which
were stored using the 'Response' form"
answerSet := sampleDatabase
allNotesFromQuery: 'SELECT Form="Response" '.
"print the contents of the documents which matched the
query to the transcript window"
answerSet do: [ :document |
Transcript nextPutAll: document fill printString; cr.
].
"close the database"
sampleDatabase close.
"Deinitialize"
AbtLnEnvironment shutDown.
You may have noticed that the query returns a collection of
AbtLnNote instances. An
AbtLnNote is a generic representative for a Domino document. For more details on documents see
Using the Domino Form part (AbtNotesFormPart). After you have executed the sample code, your Transcript window should display contents like the following text:
Note:
Depending on your sample database the contents of your transcript window may look different.
an AbtLnNote[
an AbtLnItemText(Form ==> 'Response')
an AbtLnItemRefList($REF ==> '$REF')
an AbtLnItemText(From ==> 'Hans Kamutzki')
an AbtLnItemText(ImmediateParentSubject ==> 'AbtLnEnvironment')
an AbtLnItemText(NewsLetterSubject ==> 'Take care when you save image
(Response to: "AbtLnEnvironment")')
(Body ==> )
an AbtLnItemText(OriginalSubject ==> 'AbtLnEnvironment')
an AbtLnItemText(ParentForm ==> 'MainTopic')
an AbtLnItemText(readers ==> '')
an AbtLnItemText(ThreadId ==> 'HKAI-343ANV')
an AbtLnItemText(Subject ==> 'Take care when you save image')
an AbtLnItemTextList($UpdatedBy ==> OrderedCollection('Hans Kamutzki' ))
]
an AbtLnNote
an AbtLnItemText(Form ==> 'Response')
an AbtLnItemRefList($REF ==> '$REF')
an AbtLnItemText(From ==> 'Hans Kamutzki')
an AbtLnItemText(ImmediateParentSubject ==> 'AbtLnConnection')
an AbtLnItemText(NewsLetterSubject ==> 'Single Connection, many applications
(Response to: "AbtLnConnection")')
(Body ==> )
an AbtLnItemText(OriginalSubject ==> 'AbtLnConnection')
an AbtLnItemText(ParentForm ==> 'MainTopic')
an AbtLnItemText(readers ==> '')
an AbtLnItemText(ThreadId ==> 'HKAI-343AP8')
an AbtLnItemText(Subject ==> 'Single Connection, many applications')
an AbtLnItemTextList($UpdatedBy ==> OrderedCollection('Hans Kamutzki' ))
]
Note:
When specifying a query formula, you have to comply with the formula syntax. Refer to your Domino designer documentation for more information on the formula language.
Be aware that a string in a query is put in double-quotes rather than single-quotes.