首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 數據庫知識 >  >> SQL Server 資料庫 >> 關於SqlServer

LotusScript 實作:依條件跨資料庫複製文件並自動清理壓縮來源庫

     編輯:關於SqlServer

需求場景

將符合特定搜尋條件的文件從來源 Notes 資料庫(database1.nsf)複製至目標資料庫(database2.nsf),複製完成後刪除來源文件並壓縮來源資料庫以釋放空間。

完整程式碼

Dim db1 As NotesDatabase
Dim db2 As NotesDatabase
Dim dcc As NotesDocumentCollection
Dim note As NotesDocument
Dim sqlSearch As String

Set db1 = New NotesDatabase("", "database1.nsf")
Set db2 = New NotesDatabase("", "database2.nsf")

sqlSearch = "搜尋條件"  ' 例如: [Status]="Completed"
Set dcc = db1.Search(sqlSearch, Nothing, 0)
Set note = dcc.GetFirstDocument

If dcc.Count = 0 Then
    Msgbox "未搜尋到符合條件的文件,程序結束"
    Exit Sub
End If

While Not (note Is Nothing)
    Call note.CopyToDatabase(db2)
    Set note = dcc.GetNextDocument(note)
Wend

Call dcc.RemoveAll(True)  ' 從來源資料庫永久刪除文件
Call db1.Compact          ' 壓縮來源資料庫
Msgbox "跨庫複製、清理與壓縮作業完成"

關鍵方法說明

  • NotesDatabase.Search(query, view, maxDocs):依公式語言條件檢索文件集合
  • NotesDocument.CopyToDatabase(targetDb):將文件(含附件、Rich Text)完整複製至目標庫
  • NotesDocumentCollection.RemoveAll(force):True 表示硬刪除(不進垃圾桶)
  • NotesDatabase.Compact:整理資料庫碎片、回收未使用空間

注意事項

  • 搜尋條件需符合 Notes 公式語法,建議先在檢視測試
  • 大量文件操作時,考慮分批處理避免記憶體耗盡
  • 執行前務必備份來源資料庫
  • Compact 操作會暫時鎖定資料庫,建議離峰時段執行
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved