vb6 ADODB记录集大小检索

时间:2014-11-08 14:20:13

标签: ms-access vb6 adodb

使用ADODB - 是否有一个函数来检索结果查询的实际大小? (VB6)

我不是说它的意思是指它的实际大小, 我想知道需要通过网络使用多少数据来检索我的查询结果。

如果不存在这样的东西,我想我总是可以把所有检索到的数据,把它转换成字节,然后开始计算,但是我想避免它,如果已经内置的东西(应该是)

谢谢!

P.S 使用.mdb文件,使用adodb 2.0库

1 个答案:

答案 0 :(得分:0)

以下是使用ADO获取客户端记录集后报告WorkingSetSize的示例

Option Explicit

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function GetProcessMemoryInfo Lib "psapi" (ByVal hProcess As Long, ppsmemCounters As PROCESS_MEMORY_COUNTERS, ByVal cb As Long) As Long

Private Type PROCESS_MEMORY_COUNTERS
    cb                      As Long
    PageFaultCount          As Long
    PeakWorkingSetSize      As Long
    WorkingSetSize          As Long
    QuotaPeakPagedPoolUsage As Long
    QuotaPagedPoolUsage     As Long
    QuotaPeakNonPagedPoolUsage As Long
    QuotaNonPagedPoolUsage  As Long
    PagefileUsage           As Long
    PeakPagefileUsage       As Long
    PrivateUsage            As Long
End Type

Private Function pvGetWorkingSetSize() As String
    Dim uCounters       As PROCESS_MEMORY_COUNTERS

    On Error GoTo QH
    If GetProcessMemoryInfo(GetCurrentProcess(), uCounters, Len(uCounters)) <> 0 Then
        pvGetWorkingSetSize = Format$(pvToUnsigned(uCounters.WorkingSetSize) / 1024 / 1024, "0.00") & "MB"
    End If
QH:
End Function

Private Function pvToUnsigned(ByVal lValue As Long) As Currency
    Call CopyMemory(pvToUnsigned, lValue, 4)
    pvToUnsigned = pvToUnsigned * 10000@
End Function

'--- UI stuff

Private Sub Command1_Click()
    Const CONN_STR  As String = "Provider=SQLOLEDB;Data Source=UCSDB\R2;Initial Catalog=Dreem15_IVB_2;Integrated Security=SSPI"
    Dim rs          As ADODB.Recordset

    pvLog "Starting"
    Set rs = New ADODB.Recordset
    pvLog "After loading ADO"

    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open "SELECT 1 AS ID", CONN_STR, adOpenStatic, adLockBatchOptimistic
    pvLog "After loading SQLOLEDB"

    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    rs.Open "SELECT TOP 10000 * FROM inv_Docs", CONN_STR, adOpenStatic, adLockBatchOptimistic
    pvLog "After fetching 10000 records"
    With New PropertyBag
        .WriteProperty "rs", rs
        pvLog "Propbag size: " & Format$(UBound(.Contents) / 1024 / 1024, "0.00") & "MB"
    End With
    pvLog "After destroy propbag"
    Set rs = Nothing
    pvLog "After destroy recordset"
End Sub

Private Sub Command2_Click()
    pvLog "Ping"
End Sub

Private Sub pvLog(sText As String)
    Text1.Text = Text1.Text & Format$(Timer, "0.00") & ": " & pvGetWorkingSetSize() & ", " & sText & vbCrLf
    Text1.SelStart = &H7FFF
    Refresh
End Sub

以下是连续三次执行后的结果

60366.48: 17.71MB, Starting
60366.48: 18.04MB, After loading ADO
60366.51: 22.00MB, After loading SQLOLEDB
60366.74: 48.49MB, After fetching 10000 records
60368.34: 62.81MB, Propbag size: 6.04MB
60368.34: 50.73MB, After destroy propbag
60368.34: 28.63MB, After destroy recordset

60369.45: 28.67MB, Starting
60369.45: 28.68MB, After loading ADO
60369.47: 28.90MB, After loading SQLOLEDB
60369.71: 53.28MB, After fetching 10000 records
60371.30: 67.41MB, Propbag size: 6.04MB
60371.30: 55.33MB, After destroy propbag
60371.30: 33.88MB, After destroy recordset

60371.95: 33.88MB, Starting
60371.95: 33.88MB, After loading ADO
60371.96: 33.91MB, After loading SQLOLEDB
60372.20: 56.37MB, After fetching 10000 records
60373.80: 69.11MB, Propbag size: 6.04MB
60373.80: 57.03MB, After destroy propbag
60373.80: 34.09MB, After destroy recordset