5. Domino Query Language (DQL)
Domino Query Language (DQL) は、Dominoのコアで実行される機能であり、文書内
の情報を検索する際に簡潔な構文を可能にする機能。
アクセスするための詳細なコードを書く必要はない。
DQL は(Notes)Database オブジェクトの LotusScript および Java Query メソッド、
または domino-db node.js API を介して実行することができる。
6. 簡潔な構文
Term Boolean Term [ Boolean Term ...]
[ Identifier ] Operator [ Value ]
And
Or
and not
or not
Boolean
Term
7. 簡潔な構文
Term Boolean Term [ Boolean Term ...]
[ Identifier ] Operator [ Value ]
And
Or
and not
or not
SummaryField
‘View or folder
name’.Columnname
@function
=
>
>=
<
<=
in [all]
‘ Quoted string value ’
@dt(‘ datetime value ’)
Number
( in value list )
Boolean
Term
[ Identifier ] Operator [ Value ]
8. 簡潔な構文
Term Boolean Term [ Boolean Term ...]
[ Identifier ] Operator [ Value ]
And
Or
and not
or not
SummaryField
‘View or folder
name’.Columnname
@function
=
>
>=
<
<=
in [all]
‘ Quoted string value ’
@dt(‘ datetime value ’)
Number
( in value list )
Boolean
Term
[ Identifier ] Operator [ Value ]
31. 【参考】
コマンドプロンプトは「管理者として実行」
C:IBMDomino>domquery.exe -f "DQL.nsf" -q "Subject = '2019/01/26 13:38:08'" -e
This database is currently in use by another person or process, and cannot be accessed at this
time. In order to share a Notes database, it must be accessed via a Domino Server by all users of
the database.
C:IBMDomino>
※「管理者として実行」しない場合、 V10.0.1 では次のように表示されました
32. 【参考】
DomQuery コマンドのオプション
-f [DBName] data directory relative path, REQUIRED
-q [double quoted string query] query string - either this or -z file REQUIRED
-z [QueryFile path] full path to a file containing query syntax queries
delimited by #* at preceding line begin
-t [File Path] full path to a file with query tree(s)
-e Explain the nodes (query tree mode only)
-p Parse only (for testing)
-g Provide and output overall timing
-v [MaxEntries] Maximum view entries to be scanned
-c [MaxDocsScanned] Maximum number of documents to be scanned
-m [Msecs] Maximum milliseconds to execute
-x Exit on error (-z file case)
-j No view processing performed (only NSF document scan and FT)
38. SetNamedVariable
クエリー中の変数名を値に置き換える
名前付き置換変数は1~15バイトの英数字および特殊文字のテキスト名
Dim ss As New NotesSession
Dim db As NotesDatabase
Dim ndq As NOTESDOMINOQUERY
Dim query As String
Set db = ss.Currentdatabase
Set ndq = db.Createdominoquery()
query = "DocNo = ?docno"
ndq.Setnamedvariable "docno", 210
MsgBox ndq.Explain( query ),,"Explain Result"
40. SQLインジェクション対策
SetNamedVariable を使用することで、フィールド名
(またはビューの列名)と値とを明確に区別可能で
あり、不正なクエリーへの対策として有効です
Dim ss As New NotesSession
Dim db As NotesDatabase
Dim ndq As NOTESDOMINOQUERY
Dim query As String
Set db = ss.Currentdatabase
Set ndq = db.Createdominoquery()
query = "Subject = '2019/01/26 13:38:08' OR not DocNO = 0"
msgbox ndq.Explain( query ),,“Result #1"
Set ndq = Nothing
Set ndq = db.Createdominoquery()
query = "Subject = ?subject"
ndq.Setnamedvariable "subject", "2019/01/26 13:38:08' OR not DocNo = 0"
MsgBox ndq.Explain( query ),,"Result #2"
ndq.Resetnamedvariables
値を構造化しない
クエリーが構造化される
44. コード抜粋(LotusScript)
Dim ss As New NotesSession
Dim db As NotesDatabase
Dim ndq As NOTESDOMINOQUERY
Dim dc As NotesDocumentCollection
Dim query As String
Set db = ss.Currentdatabase
‘ 検索
query = |Subject = "2019/01/26 13:38:08"|
Set dc = db. Search( query, Nothing, 0 )
Set dc = Nothing
‘ 全文検索
query = |[Subject] = "2019/01/26 13:38:08"|
Set dc = db. Ftsearch( query, 0 )
Set dc = Nothing
‘ DQL NSF文書検索
Set ndq = db.Createdominoquery()
ndq.Noviews = True ‘ビュー列検索しない
query = |Subject = '2019/01/26 13:38:08'|
Set dc = ndq.Execute( query )
Set dc = Nothing
Set ndq = Nothing
‘ DQL ビュー列検索
Set ndq = db.Createdominoquery()
query = |'All'.Subject = '2019/01/26 13:38:08'|
Set dc = ndq.Execute( query )
Set dc = Nothing
Set ndq = Nothing
45. 【参考】
LotusScriptで1秒未満を計る
%Include "lsconst.lss"
Sub Initialize
Dim ss As New NotesSession
Dim ndq As NOTESDOMINOQUERY
Dim dc As NotesDocumentCollection
Dim tick_start As Long, tick_end As Long, seconds As Double
Set ndq = ss.Currentdatabase.Createdominoquery()
tick_start = GetThreadInfo( LSI_THREAD_TICKS )
Set dc = ndq.Execute(|'All'.Subject = '2019/01/26 13:38:08'| )
tick_end = GetThreadInfo( LSI_THREAD_TICKS )
seconds = ( tick_end - tick_start ) / GetThreadInfo( LSI_THREAD_TICKS_PER_SEC )
Print Format$( seconds, "##0.000" )
End Sub
52. 【失敗例】
サーバー上のエージェント実行権限がない
[2394:008E-2A30] 2019/01/31 14:39:00 Error validating execution rights for agent
'DQL Test#1' in database 'DQL.nsf'. Agent signer 'admin/v10', effective user
'admin/v10'. Examine 'Programmability Restrictions' field in the Server Record.
サーバー文書で
エージェント実行権限を付与します
53. 【失敗例】
デザインカタログがない
[2394:008E-2AA4] 2019/01/31 14:43:23 Agent 'DQL Test#1' error: Domino Query
execution error: ** ERROR during View Processing Initializing - possible design
catalog corruption ** File does not exist - error during planning and tree generation
Error (File does not exist) in getCatalogDB, path = GQFDsgn.cat Please run updall
<dbname> -e to create the design catalog (Call hint: NSFCalls::NSFDbOpen, Core call
#0) ******************
updall に -e オプションを付けて実行すると作成されます!
56. 【失敗例】
ヒットする数 > デフォルト値
[2394:008E-2AC0] 2019/01/31 14:46:53 Agent 'DQL Test#1' error: Domino Query
execution error: Maximum number of documents or view entries scanned for query
exceeded - timeout or resources exceeded error Too many documents scanned
(500001) vs max allowed (500000) (C
all hint: NSFCalls::NSFSearchExtended3, Core call #0) ******************
Notes.ini パラメータで制限値を緩和します
QUERY_MAX_DOCS_SCANNED
QUERY_MAX_VIEW_ENTRIES_SCANNED