LotusScript to C API Programming Guide

rtLib Domino Rich Text Management template
Home
Show details for ContentContent
Purchase
Ready-to-use samples
Show details for Online resourcesOnline resources
Forum
Links
Happy readers

Anonymous

login


 

Hosted by Prominic.NET, Inc.
Main topic: Need a fast way to find out the number of documents in a database

Problem solved and here is the solution (by Kenneth Haggman, 09/14/2007 07:15:21 AM)

I managed to solve this by using the NSFDbGetModifiedNoteTable.

By using the TIMEDATE_MINIMUM timestamp, deletion stubs are NOT included.

This works REALLY fast, even for a huge server-based database the answer is returned immideately.

Thought I'd share so here it is.

Note that this code is for Visual Basic, you will need to change the Declarations slightly for LotusScript.

Private Const TIMEDATE_MINIMUM = 0

Private Const NOTE_CLASS_DOCUMENT = &H1 ' document note

Private Declare Function OSPathNetConstruct Lib "nnotes.dll" (ByVal portName As Integer, ByVal serverName As String, ByVal fileName As String, ByVal pathName As String) As Integer

Private Declare Function NSFDbOpen Lib "nnotes.dll" (ByVal dbName As String, rethDb As Long) As Integer

Private Declare Function NSFDbClose Lib "nnotes.dll" (ByVal hDb As Long) As Integer

Private Declare Sub TimeConstant Lib "nnotes" (ByVal timeConstantType As Long, retDateTime As Double)

Private Declare Function NSFDbGetModifiedNoteTable Lib "nnotes" (ByVal hDb As Long, ByVal noteClassMask As Integer, ByVal startDate As Double, retEndDate As Double, rethTable As Long) As Integer

Private Declare Function IDEntries Lib "nnotes" (ByVal hTable As Long) As Long

Private Declare Function IDScan Lib "nnotes" (ByVal hTable As Long, ByVal tFirstBool As Integer, retID As Long) As Integer

Private Declare Sub IDDestroyTable Lib "nnotes" (ByVal hT As Long)

Public Function getDbDocumentCountAPI(pServer As String, pFilePath As String) As Long

'---

' Returns the number of documents in a database.

' Note that that is all that is returned.

' No collection or anything else - just a number.

'---

Dim hDb As Long

Dim hIDTable As Long

Dim pathName As String * 256

Dim startDate As Double

Dim endDate As Double

Dim noteID As Long

Dim firstFlag As Integer

Dim result As Integer

Dim lngCount As Long

lngCount = 0

'-- Build an API-friendly path.

Call OSPathNetConstruct(0, pServer, pFilePath, pathName)

'-- Open the database and get a handle with NSFDbOpen

result = NSFDbOpen(pathName, hDb)

If result <> 0 Then GoTo endOfFunction

'-- Create a time constant that will filter out the deletion stubs.

Call TimeConstant(TIMEDATE_MINIMUM, startDate)

'-- Get the ID-table. This is really fast - even for very large databases.

result = NSFDbGetModifiedNoteTable(hDb, NOTE_CLASS_DOCUMENT, startDate, endDate, hIDTable)

If result <> 0 Then GoTo closeDb

'-- Make sure we got some IDs returned to us (if not, just exit)

If (IDEntries(hIDTable) = 0) Then

GoTo freeIDTable

End If

'-- Get the number of IDs in the table

lngCount = CLng(IDEntries(hIDTable))

freeIDTable:

'-- Free the memory used when we grabbed the ID table.

Call IDDestroyTable(hIDTable)

closeDb:

'-- Close the database with NSFDbClose

Call NSFDbClose(hDb)

endOfFunction:

getDbDocumentCountAPI = lngCount

End Function