Perf.frm
Upload User: loyalwww
Upload Date: 2007-08-12
Package Size: 933k
Code Size: 34k
Category:

ADO-ODBC

Development Platform:

Visual C++

  1. VERSION 5.00
  2. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "Comctl32.ocx"
  3. Begin VB.Form frmPerf 
  4.    Caption         =   "ADO Performance Test"
  5.    ClientHeight    =   7095
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   9390
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   7095
  11.    ScaleWidth      =   9390
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.TextBox txtCacheSize 
  14.       Height          =   285
  15.       Left            =   6480
  16.       TabIndex        =   52
  17.       Text            =   "1"
  18.       Top             =   3480
  19.       Width           =   495
  20.    End
  21.    Begin VB.CheckBox chkNoRecords 
  22.       Alignment       =   1  'Right Justify
  23.       Caption         =   "adExecuteNoRecords"
  24.       Height          =   255
  25.       Left            =   7200
  26.       TabIndex        =   50
  27.       ToolTipText     =   "Will run the query asynchronously"
  28.       Top             =   3480
  29.       Width           =   2055
  30.    End
  31.    Begin VB.Frame fraCursorLocation 
  32.       Caption         =   "Cursor Location"
  33.       Height          =   1095
  34.       Left            =   6840
  35.       TabIndex        =   44
  36.       Top             =   4680
  37.       Width           =   2415
  38.       Begin VB.CheckBox chkCursorLocation 
  39.          Caption         =   "Use Client"
  40.          Height          =   255
  41.          Index           =   3
  42.          Left            =   240
  43.          TabIndex        =   46
  44.          Top             =   720
  45.          Width           =   1575
  46.       End
  47.       Begin VB.CheckBox chkCursorLocation 
  48.          Caption         =   "Use Server"
  49.          Height          =   255
  50.          Index           =   2
  51.          Left            =   240
  52.          TabIndex        =   45
  53.          Top             =   360
  54.          Width           =   1455
  55.       End
  56.    End
  57.    Begin VB.Frame fraLockType 
  58.       Caption         =   "Lock Type"
  59.       Height          =   1095
  60.       Left            =   3240
  61.       TabIndex        =   39
  62.       Top             =   4680
  63.       Width           =   3255
  64.       Begin VB.CheckBox chkLockType 
  65.          Caption         =   "Batch Optimistic"
  66.          Height          =   255
  67.          Index           =   4
  68.          Left            =   1680
  69.          TabIndex        =   43
  70.          Top             =   720
  71.          Width           =   1455
  72.       End
  73.       Begin VB.CheckBox chkLockType 
  74.          Caption         =   "Optimistic"
  75.          Height          =   255
  76.          Index           =   3
  77.          Left            =   240
  78.          TabIndex        =   42
  79.          Top             =   720
  80.          Width           =   1215
  81.       End
  82.       Begin VB.CheckBox chkLockType 
  83.          Caption         =   "Pessimistic"
  84.          Height          =   255
  85.          Index           =   2
  86.          Left            =   1680
  87.          TabIndex        =   41
  88.          Top             =   360
  89.          Width           =   1215
  90.       End
  91.       Begin VB.CheckBox chkLockType 
  92.          Caption         =   "Read Only"
  93.          Height          =   255
  94.          Index           =   1
  95.          Left            =   240
  96.          TabIndex        =   40
  97.          Top             =   360
  98.          Width           =   1215
  99.       End
  100.    End
  101.    Begin VB.Frame fraCursorType 
  102.       Caption         =   "Cursor Type"
  103.       Height          =   1095
  104.       Left            =   120
  105.       TabIndex        =   34
  106.       Top             =   4680
  107.       Width           =   2655
  108.       Begin VB.CheckBox chkCursorType 
  109.          Caption         =   "Static"
  110.          Height          =   255
  111.          Index           =   3
  112.          Left            =   1680
  113.          TabIndex        =   38
  114.          Top             =   720
  115.          Width           =   735
  116.       End
  117.       Begin VB.CheckBox chkCursorType 
  118.          Caption         =   "Dynamic"
  119.          Height          =   255
  120.          Index           =   2
  121.          Left            =   240
  122.          TabIndex        =   37
  123.          Top             =   720
  124.          Width           =   1335
  125.       End
  126.       Begin VB.CheckBox chkCursorType 
  127.          Caption         =   "Keyset"
  128.          Height          =   255
  129.          Index           =   1
  130.          Left            =   1680
  131.          TabIndex        =   36
  132.          Top             =   360
  133.          Width           =   855
  134.       End
  135.       Begin VB.CheckBox chkCursorType 
  136.          Caption         =   "Forward Only"
  137.          Height          =   255
  138.          Index           =   0
  139.          Left            =   240
  140.          TabIndex        =   35
  141.          Top             =   360
  142.          Width           =   1335
  143.       End
  144.    End
  145.    Begin VB.CheckBox chkAsync 
  146.       Alignment       =   1  'Right Justify
  147.       Caption         =   "Asynchronous"
  148.       Height          =   255
  149.       Left            =   7680
  150.       TabIndex        =   33
  151.       ToolTipText     =   "Will run the query asynchronously"
  152.       Top             =   3840
  153.       Width           =   1575
  154.    End
  155.    Begin VB.TextBox txtTimes 
  156.       Height          =   285
  157.       Left            =   6480
  158.       TabIndex        =   26
  159.       Text            =   "10"
  160.       ToolTipText     =   "Number of times to run the test"
  161.       Top             =   3840
  162.       Width           =   495
  163.    End
  164.    Begin VB.CommandButton cmdCancel 
  165.       Caption         =   "Cancel Test"
  166.       Height          =   375
  167.       Left            =   5400
  168.       TabIndex        =   25
  169.       Top             =   6600
  170.       Visible         =   0   'False
  171.       Width           =   1215
  172.    End
  173.    Begin VB.CommandButton cmdClose 
  174.       Caption         =   "Close"
  175.       Height          =   375
  176.       Left            =   8040
  177.       TabIndex        =   24
  178.       Top             =   6600
  179.       Width           =   1215
  180.    End
  181.    Begin VB.TextBox txtMarker 
  182.       Height          =   285
  183.       Left            =   6480
  184.       TabIndex        =   22
  185.       ToolTipText     =   "User specific text to write to the log"
  186.       Top             =   4200
  187.       Width           =   2775
  188.    End
  189.    Begin VB.Frame fraTest 
  190.       Caption         =   "Test"
  191.       Height          =   2295
  192.       Left            =   5280
  193.       TabIndex        =   15
  194.       Top             =   960
  195.       Width           =   3615
  196.       Begin VB.OptionButton optTest 
  197.          Caption         =   "Run Command (no recordset)"
  198.          Height          =   255
  199.          Index           =   4
  200.          Left            =   240
  201.          TabIndex        =   53
  202.          Top             =   1800
  203.          Width           =   3135
  204.       End
  205.       Begin VB.OptionButton optTest 
  206.          Caption         =   "Open / GetRows (Chunked) / Close"
  207.          Height          =   255
  208.          Index           =   3
  209.          Left            =   240
  210.          TabIndex        =   32
  211.          Top             =   1440
  212.          Width           =   3135
  213.       End
  214.       Begin VB.OptionButton optTest 
  215.          Caption         =   "Open / GetRows / Close"
  216.          Height          =   255
  217.          Index           =   2
  218.          Left            =   240
  219.          TabIndex        =   18
  220.          Top             =   1080
  221.          Width           =   2175
  222.       End
  223.       Begin VB.OptionButton optTest 
  224.          Caption         =   "Open / MoveNext / Close"
  225.          Height          =   255
  226.          Index           =   1
  227.          Left            =   240
  228.          TabIndex        =   17
  229.          Top             =   720
  230.          Width           =   2175
  231.       End
  232.       Begin VB.OptionButton optTest 
  233.          Caption         =   "Open / Close"
  234.          Height          =   255
  235.          Index           =   0
  236.          Left            =   240
  237.          TabIndex        =   16
  238.          Top             =   360
  239.          Value           =   -1  'True
  240.          Width           =   2175
  241.       End
  242.    End
  243.    Begin VB.Frame fraTables 
  244.       Height          =   3135
  245.       Index           =   0
  246.       Left            =   240
  247.       TabIndex        =   2
  248.       Top             =   1320
  249.       Width           =   4695
  250.       Begin VB.Frame fraadCmdTable 
  251.          Caption         =   "Command Type"
  252.          Height          =   1215
  253.          Left            =   2400
  254.          TabIndex        =   6
  255.          Top             =   240
  256.          Width           =   2055
  257.          Begin VB.OptionButton optadCmdTableDirect 
  258.             Caption         =   "adCmdTableDirect"
  259.             Height          =   255
  260.             Left            =   240
  261.             TabIndex        =   8
  262.             Top             =   720
  263.             Visible         =   0   'False
  264.             Width           =   1695
  265.          End
  266.          Begin VB.OptionButton optadCmdTable 
  267.             Caption         =   "adCmdTable"
  268.             Height          =   255
  269.             Left            =   240
  270.             TabIndex        =   7
  271.             Top             =   360
  272.             Value           =   -1  'True
  273.             Width           =   1455
  274.          End
  275.       End
  276.       Begin VB.ListBox lstTables 
  277.          Height          =   2790
  278.          ItemData        =   "Perf.frx":0000
  279.          Left            =   120
  280.          List            =   "Perf.frx":0007
  281.          Sorted          =   -1  'True
  282.          TabIndex        =   5
  283.          Top             =   240
  284.          Width           =   2055
  285.       End
  286.    End
  287.    Begin VB.CommandButton cmdTest 
  288.       Caption         =   "Test"
  289.       Height          =   375
  290.       Left            =   6720
  291.       TabIndex        =   0
  292.       Top             =   6600
  293.       Width           =   1215
  294.    End
  295.    Begin VB.Frame fraTables 
  296.       Height          =   3105
  297.       Index           =   2
  298.       Left            =   240
  299.       TabIndex        =   4
  300.       Top             =   1320
  301.       Visible         =   0   'False
  302.       Width           =   4695
  303.       Begin VB.Frame fraPrepare 
  304.          Caption         =   "Prepare"
  305.          Height          =   735
  306.          Left            =   2280
  307.          TabIndex        =   19
  308.          Top             =   2280
  309.          Width           =   2295
  310.          Begin VB.OptionButton optPrepareNo 
  311.             Caption         =   "No"
  312.             Height          =   255
  313.             Left            =   1320
  314.             TabIndex        =   21
  315.             Top             =   360
  316.             Width           =   735
  317.          End
  318.          Begin VB.OptionButton optPrepareYes 
  319.             Caption         =   "Yes"
  320.             Height          =   255
  321.             Left            =   240
  322.             TabIndex        =   20
  323.             Top             =   360
  324.             Value           =   -1  'True
  325.             Width           =   975
  326.          End
  327.       End
  328.       Begin VB.TextBox txtSQL 
  329.          Height          =   1935
  330.          Left            =   120
  331.          MultiLine       =   -1  'True
  332.          TabIndex        =   14
  333.          Top             =   240
  334.          Width           =   4455
  335.       End
  336.       Begin VB.Frame fraadCmdTab 
  337.          Caption         =   "Command Type"
  338.          Height          =   735
  339.          Index           =   1
  340.          Left            =   120
  341.          TabIndex        =   12
  342.          Top             =   2280
  343.          Width           =   2055
  344.          Begin VB.OptionButton optadCmdText 
  345.             Caption         =   "adCmdText"
  346.             Height          =   255
  347.             Left            =   240
  348.             TabIndex        =   13
  349.             Top             =   360
  350.             Value           =   -1  'True
  351.             Width           =   1695
  352.          End
  353.       End
  354.    End
  355.    Begin VB.Frame fraTables 
  356.       Height          =   3135
  357.       Index           =   1
  358.       Left            =   240
  359.       TabIndex        =   3
  360.       Top             =   1320
  361.       Visible         =   0   'False
  362.       Width           =   4695
  363.       Begin VB.Frame fraadCmdTab 
  364.          Caption         =   "Command Type"
  365.          Height          =   735
  366.          Index           =   0
  367.          Left            =   2400
  368.          TabIndex        =   10
  369.          Top             =   240
  370.          Width           =   2055
  371.          Begin VB.OptionButton optadCmdStoredProc 
  372.             Caption         =   "adCmdStoredProc"
  373.             Height          =   255
  374.             Left            =   240
  375.             TabIndex        =   11
  376.             Top             =   360
  377.             Value           =   -1  'True
  378.             Width           =   1695
  379.          End
  380.       End
  381.       Begin VB.ListBox lstQueries 
  382.          Height          =   2790
  383.          ItemData        =   "Perf.frx":0016
  384.          Left            =   120
  385.          List            =   "Perf.frx":001D
  386.          Sorted          =   -1  'True
  387.          TabIndex        =   9
  388.          Top             =   240
  389.          Width           =   2055
  390.       End
  391.    End
  392.    Begin ComctlLib.TabStrip tabTables 
  393.       Height          =   3585
  394.       Left            =   120
  395.       TabIndex        =   1
  396.       Top             =   960
  397.       Width           =   4935
  398.       _ExtentX        =   8705
  399.       _ExtentY        =   6324
  400.       _Version        =   327682
  401.       BeginProperty Tabs {0713E432-850A-101B-AFC0-4210102A8DA7} 
  402.          NumTabs         =   3
  403.          BeginProperty Tab1 {0713F341-850A-101B-AFC0-4210102A8DA7} 
  404.             Caption         =   "Tables"
  405.             Object.Tag             =   ""
  406.             ImageVarType    =   2
  407.          EndProperty
  408.          BeginProperty Tab2 {0713F341-850A-101B-AFC0-4210102A8DA7} 
  409.             Caption         =   "Queries"
  410.             Object.Tag             =   ""
  411.             ImageVarType    =   2
  412.          EndProperty
  413.          BeginProperty Tab3 {0713F341-850A-101B-AFC0-4210102A8DA7} 
  414.             Caption         =   "SQL"
  415.             Object.Tag             =   ""
  416.             ImageVarType    =   2
  417.          EndProperty
  418.       EndProperty
  419.    End
  420.    Begin VB.Label Label1 
  421.       Caption         =   "Cache Size"
  422.       Height          =   255
  423.       Left            =   5400
  424.       TabIndex        =   51
  425.       Top             =   3480
  426.       Width           =   975
  427.    End
  428.    Begin VB.Label lblCursorLocation 
  429.       Height          =   255
  430.       Left            =   6840
  431.       TabIndex        =   49
  432.       Top             =   5880
  433.       Width           =   2415
  434.    End
  435.    Begin VB.Label lblLockType 
  436.       Height          =   255
  437.       Left            =   3240
  438.       TabIndex        =   48
  439.       Top             =   5880
  440.       Width           =   3255
  441.    End
  442.    Begin VB.Label lblCursorType 
  443.       Height          =   255
  444.       Left            =   120
  445.       TabIndex        =   47
  446.       Top             =   5880
  447.       Width           =   2655
  448.    End
  449.    Begin VB.Label lblProvider 
  450.       Height          =   255
  451.       Left            =   1440
  452.       TabIndex        =   31
  453.       Top             =   120
  454.       Width           =   7455
  455.    End
  456.    Begin VB.Label lblProvCaption 
  457.       Caption         =   "Provider:"
  458.       Height          =   255
  459.       Left            =   120
  460.       TabIndex        =   30
  461.       Top             =   120
  462.       Width           =   1215
  463.    End
  464.    Begin VB.Label lblConnCaption 
  465.       Caption         =   "Connect String:"
  466.       Height          =   255
  467.       Left            =   120
  468.       TabIndex        =   29
  469.       Top             =   480
  470.       Width           =   1215
  471.    End
  472.    Begin VB.Label lblConnectString 
  473.       Height          =   255
  474.       Left            =   1440
  475.       TabIndex        =   28
  476.       Top             =   480
  477.       Width           =   7455
  478.    End
  479.    Begin VB.Label lblTimes 
  480.       Caption         =   "Times:"
  481.       Height          =   255
  482.       Left            =   5400
  483.       TabIndex        =   27
  484.       Top             =   3840
  485.       Width           =   975
  486.    End
  487.    Begin VB.Label lblMarkerText 
  488.       Caption         =   "Marker Text:"
  489.       Height          =   255
  490.       Left            =   5400
  491.       TabIndex        =   23
  492.       Top             =   4200
  493.       Width           =   975
  494.    End
  495. End
  496. Attribute VB_Name = "frmPerf"
  497. Attribute VB_GlobalNameSpace = False
  498. Attribute VB_Creatable = False
  499. Attribute VB_PredeclaredId = True
  500. Attribute VB_Exposed = False
  501. Option Explicit
  502. Private m_oConn                 As New ADODB.Connection     ' data store connection
  503. Private m_iTab                  As Integer                  ' tab selected
  504. Private m_iadCmdTableDirect     As Integer                  ' value of adCmdTableDirect
  505. Private m_iadExecuteNoRecords   As Integer                  ' value of adExecuteNoRecords
  506. Private m_bCancel               As Boolean                  ' true if cancelling form open
  507. 'TODO: options which would be good to implement
  508. Private m_bAsync                As Boolean                  ' execute the queries asynchronously
  509. Private m_iNumRows              As Integer                  ' limit the number of rows returned
  510. Private Sub chkAsync_Click()
  511.     ' as yet nothing is done with this
  512.     
  513.     m_bAsync = chkAsync
  514.     cmdCancel.Visible = m_bAsync
  515. End Sub
  516. Private Sub cmdClose_Click()
  517.     If m_oConn.State = adStateOpen Then
  518.         m_oConn.Close
  519.         Set m_oConn = Nothing
  520.     End If
  521.     Me.Visible = False
  522.     frmConnect.Visible = True
  523.     
  524. End Sub
  525. Private Sub Form_Activate()
  526.     If m_bCancel Then
  527.         cmdClose_Click
  528.         Unload Me
  529.     End If
  530. End Sub
  531. Private Sub Form_Load()
  532.     'On Error GoTo Form_Load_err
  533.     ' which version of ADO
  534.     SetVersionSpecifics
  535.     ' connect to the provider
  536.     m_oConn.Provider = g_sProvider
  537.     m_oConn.Open g_sConnectString
  538.     lblProvider.Caption = g_sProvider
  539.     lblConnectString.Caption = g_sConnectString
  540.     ' fill the tables/queries lists
  541.     SchemaFill lstTables, adSchemaTables
  542.     If g_sDriver = ACCESS_DRIVER Or _
  543.        g_sProvider = ACCESS_PROVIDER Then
  544.         SchemaFill lstQueries, adSchemaViews
  545.     Else
  546.         SchemaFill lstQueries, adSchemaProcedures
  547.     End If
  548.     ' don't allow async or adCmdTableDirect if ado 1.5
  549.     If m_oConn.Version = 1.5 Then
  550.         chkAsync.Visible = False
  551.         optadCmdTableDirect.Visible = False
  552.         m_bAsync = False
  553.     Else
  554.         chkAsync.Visible = True
  555.         optadCmdTableDirect.Visible = True
  556.         m_bAsync = True
  557.     End If
  558. Form_Load_Exit:
  559.     Exit Sub
  560. Form_Load_err:
  561.     Select Case Err
  562.     Case 3706   ' could not find provider
  563.         MsgBox "I'm sorry but this provider is not available.  Please pick another.", vbExclamation, "Cannot find provider"
  564.         Me.Visible = False
  565.         m_bCancel = True
  566.     Case Else
  567.         MsgBox "Error: Form_Load: " & Err.Description & " (" & Err.Number & ")"
  568.         Resume Form_Load_Exit
  569.     End Select
  570. End Sub
  571. Private Sub cmdTest_Click()
  572.     ' run the tests
  573.     
  574.     Dim iCmd        As CommandTypeEnum
  575.     Dim sText       As String
  576.     Select Case tabTables.SelectedItem.Index
  577.     Case 1
  578.         ' tables
  579.         If optadCmdTable Then
  580.             iCmd = adCmdTable
  581.         Else
  582.             iCmd = m_iadCmdTableDirect
  583.         End If
  584.         sText = lstTables
  585.     Case 2
  586.         ' queries
  587.         iCmd = adCmdStoredProc
  588.         sText = lstQueries
  589.     Case 3
  590.         ' sql text
  591.         iCmd = adCmdText
  592.         sText = txtSQL
  593.     End Select
  594.     ' TODO: set number of rows
  595.     If m_iNumRows = 0 Then
  596.         ' open recordset with select count(*) ?
  597.         ' this was for logging only
  598.     End If
  599.     ' run the tests
  600.     Test sText, iCmd
  601.     ' some of them can be long, so pop up message
  602.     MsgBox "Done"
  603. End Sub
  604. Private Sub Test(ByVal sText As String, ByVal iCommandType As CommandTypeEnum)
  605.     ' for each cursor type, lock type, and cursor location
  606.     ' which has been selected, run the test
  607.     Dim iCursorType         As Integer
  608.     Dim iLockType           As Integer
  609.     Dim iCursorLocation     As Integer
  610.     If optTest(4) Then
  611.         TimeRecordset sText, _
  612.                   iCursorType, _
  613.                   iLockType, _
  614.                   iCursorLocation, _
  615.                   iCommandType, _
  616.                   txtTimes
  617.     Else
  618.         For iCursorType = chkCursorType.LBound To chkCursorType.UBound
  619.             If chkCursorType(iCursorType) Then
  620.                 For iLockType = chkLockType.LBound To chkLockType.UBound
  621.                     If chkLockType(iLockType) Then
  622.                         For iCursorLocation = chkCursorLocation.LBound To chkCursorLocation.UBound
  623.                             If chkCursorLocation(iCursorLocation) Then
  624.                                 TimeRecordset sText, _
  625.                                           iCursorType, _
  626.                                           iLockType, _
  627.                                           iCursorLocation, _
  628.                                           iCommandType, _
  629.                                           txtTimes
  630.                             End If
  631.                         Next
  632.                     End If
  633.                 Next
  634.             End If
  635.         Next
  636.     End If
  637. End Sub
  638. Private Sub TimeRecordset(ByVal sText As String, _
  639.                     ByVal iCursorTypeRequested As CursorTypeEnum, _
  640.                     ByVal iLockType As LockTypeEnum, _
  641.                     ByVal iCursorLocation As CursorLocationEnum, _
  642.                     ByVal iType As CommandTypeEnum, _
  643.                     ByVal iTimes As Integer)
  644.     ' run the test
  645.     
  646.     Dim oRec                As New ADODB.Recordset
  647.     Dim iCursorTypeReceived As CursorTypeEnum
  648.     Dim lTime               As Long
  649.     Dim sTest               As String
  650.     ' show what's going on
  651.     If Not optTest(4) Then
  652.         lblCursorType.Caption = chkCursorType(iCursorTypeRequested).Caption
  653.         lblLockType.Caption = chkLockType(iLockType).Caption
  654.         lblCursorLocation.Caption = chkCursorLocation(iCursorLocation).Caption
  655.         Me.Refresh
  656.     End If
  657.     ' run the actual test selected
  658.     If optTest(0) Then
  659.         lTime = Test1Run(sText, iCursorTypeRequested, iLockType, iCursorLocation, iType, iTimes)
  660.         sTest = optTest(0).Caption
  661.     End If
  662.     
  663.     If optTest(1) Then
  664.         lTime = Test2Run(sText, iCursorTypeRequested, iLockType, iCursorLocation, iType, iTimes)
  665.         sTest = optTest(1).Caption
  666.     End If
  667.     If optTest(2) Then
  668.         lTime = Test3Run(sText, iCursorTypeRequested, iLockType, iCursorLocation, iType, iTimes)
  669.         sTest = optTest(2).Caption
  670.     End If
  671.     If optTest(3) Then
  672.         lTime = Test4Run(sText, iCursorTypeRequested, iLockType, iCursorLocation, iType, iTimes)
  673.         sTest = optTest(3).Caption
  674.     End If
  675.     If optTest(4) Then
  676.         lTime = Test5Run(sText, iCursorTypeRequested, iLockType, iCursorLocation, iType, iTimes)
  677.         sTest = optTest(4).Caption
  678.         iCursorTypeReceived = iCursorTypeRequested
  679.     Else
  680.         ' get the cursor type actually returned
  681.         ' stops misleading results when the cursor type is not suported
  682.         oRec.ActiveConnection = m_oConn
  683.         oRec.CursorLocation = iCursorLocation
  684.         oRec.Open sText, , iCursorTypeRequested, iLockType, iType
  685.         iCursorTypeReceived = oRec.CursorType
  686.         oRec.Close
  687.     End If
  688.     ' finally log the times
  689.     LogTimes lTime, iTimes, sText, sTest, _
  690.             iCursorTypeRequested, iCursorTypeReceived, _
  691.             iLockType, iCursorLocation, iType
  692. End Sub
  693. Private Function Test1Run(ByVal sText As String, _
  694.                     ByVal iCursorTypeRequested As CursorTypeEnum, _
  695.                     ByVal iLockType As LockTypeEnum, _
  696.                     ByVal iCursorLocation As CursorLocationEnum, _
  697.                     ByVal iType As CommandTypeEnum, _
  698.                     ByVal iTimes As Integer) As Long
  699. '
  700. ' Test 1: Open and close the recordset
  701.     Dim ct                  As New CTimer
  702.     Dim oRec                As New ADODB.Recordset
  703.     Dim iLoop               As Integer
  704.     Dim lTime               As Long
  705.     m_oConn.CursorLocation = iCursorLocation
  706.     oRec.ActiveConnection = m_oConn
  707.     oRec.CacheSize = CLng(txtCacheSize)
  708.     For iLoop = 1 To iTimes
  709.         ct.StartTiming
  710.         oRec.Open sText, , iCursorTypeRequested, iLockType, iType
  711.         oRec.Close
  712.         ct.StopTiming
  713.         lTime = lTime + ct.TotalTime
  714.     Next
  715.     Test1Run = lTime
  716. End Function
  717. Private Function Test2Run(ByVal sText As String, _
  718.                     ByVal iCursorTypeRequested As CursorTypeEnum, _
  719.                     ByVal iLockType As LockTypeEnum, _
  720.                     ByVal iCursorLocation As CursorLocationEnum, _
  721.                     ByVal iType As CommandTypeEnum, _
  722.                     ByVal iTimes As Integer) As Long
  723. '
  724. ' test 2: open the recordset, move through the records, close the recordset
  725.     Dim ct                  As New CTimer
  726.     Dim oRec                As New ADODB.Recordset
  727.     Dim iLoop               As Integer
  728.     Dim lTime               As Long
  729.     m_oConn.CursorLocation = iCursorLocation
  730.     oRec.ActiveConnection = m_oConn
  731.     oRec.CacheSize = CLng(txtCacheSize)
  732.     For iLoop = 1 To iTimes
  733.         oRec.Open sText, , iCursorTypeRequested, iLockType, iType
  734.         ct.StartTiming
  735.         
  736.         While Not oRec.EOF
  737.             oRec.MoveNext
  738.         Wend
  739.         ct.StopTiming
  740.         oRec.Close
  741.         lTime = lTime + ct.TotalTime
  742.     Next
  743.     Test2Run = lTime
  744. End Function
  745. Private Function Test3Run(ByVal sText As String, _
  746.                     ByVal iCursorTypeRequested As CursorTypeEnum, _
  747.                     ByVal iLockType As LockTypeEnum, _
  748.                     ByVal iCursorLocation As CursorLocationEnum, _
  749.                     ByVal iType As CommandTypeEnum, _
  750.                     ByVal iTimes As Integer) As Long
  751. '
  752. ' test 3: open the recordset, get the rows (GetRows), close the recordset
  753.     Dim ct                  As New CTimer
  754.     Dim oRec                As New ADODB.Recordset
  755.     Dim iLoop               As Integer
  756.     Dim lTime               As Long
  757.     Dim avRows              As Variant
  758.     m_oConn.CursorLocation = iCursorLocation
  759.     oRec.ActiveConnection = m_oConn
  760.     oRec.CacheSize = CLng(txtCacheSize)
  761.     For iLoop = 1 To iTimes
  762.         oRec.Open sText, , iCursorTypeRequested, iLockType, iType
  763.         ct.StartTiming
  764.         avRows = oRec.GetRows
  765.         ct.StopTiming
  766.         oRec.Close
  767.         lTime = lTime + ct.TotalTime
  768.     Next
  769.     Test3Run = lTime
  770. End Function
  771. Private Function Test4Run(ByVal sText As String, _
  772.                     ByVal iCursorTypeRequested As CursorTypeEnum, _
  773.                     ByVal iLockType As LockTypeEnum, _
  774.                     ByVal iCursorLocation As CursorLocationEnum, _
  775.                     ByVal iType As CommandTypeEnum, _
  776.                     ByVal iTimes As Integer) As Long
  777. '
  778. ' Test 4: open the recordset, get the rows (GetRows) in chunks of 1000), close the recordset
  779.     Dim ct                  As New CTimer
  780.     Dim oRec                As New ADODB.Recordset
  781.     Dim iLoop               As Integer
  782.     Dim lTime               As Long
  783.     Dim avRows              As Variant
  784.     m_oConn.CursorLocation = iCursorLocation
  785.     oRec.ActiveConnection = m_oConn
  786.     oRec.CacheSize = CLng(txtCacheSize)
  787.     For iLoop = 1 To iTimes
  788.         oRec.Open sText, , iCursorTypeRequested, iLockType, iType
  789.         ct.StartTiming
  790.         While Not oRec.EOF
  791.             avRows = oRec.GetRows(1000)
  792.         Wend
  793.         ct.StopTiming
  794.         oRec.Close
  795.         lTime = lTime + ct.TotalTime
  796.     Next
  797.     Test4Run = lTime
  798. End Function
  799. Private Function Test5Run(ByVal sText As String, _
  800.                     ByVal iCursorTypeRequested As CursorTypeEnum, _
  801.                     ByVal iLockType As LockTypeEnum, _
  802.                     ByVal iCursorLocation As CursorLocationEnum, _
  803.                     ByVal iType As CommandTypeEnum, _
  804.                     ByVal iTimes As Integer) As Long
  805. '
  806. ' Test 5: Just run the command - no recordset created
  807.     Dim ct                  As New CTimer
  808.     Dim oCmd                As New ADODB.Command
  809.     Dim iLoop               As Integer
  810.     Dim lTime               As Long
  811.     Dim avRows              As Variant
  812.     oCmd.ActiveConnection = m_oConn
  813.     oCmd.CommandType = adCmdText
  814.     oCmd.CommandText = sText
  815.     oCmd.Prepared = Me!optPrepareYes.Value
  816.     For iLoop = 1 To iTimes
  817.         ct.StartTiming
  818.         oCmd.Execute
  819.         ct.StopTiming
  820.         lTime = lTime + ct.TotalTime
  821.     Next
  822.     Test5Run = lTime
  823. End Function
  824. Private Sub LogTimes(lTime As Long, _
  825.                     iTimes As Integer, _
  826.                     sText As String, _
  827.                     sTest As String, _
  828.                     iCursorTypeRequested As CursorTypeEnum, _
  829.                     iCursorTypeReceived As CursorTypeEnum, _
  830.                     iLockType As LockTypeEnum, _
  831.                     iCursorLocation As CursorLocationEnum, _
  832.                     iCommandType As CommandTypeEnum)
  833.     ' log the test times to the database
  834.     Dim db          As DAO.Database
  835.     Dim oRec        As DAO.Recordset
  836.     Set db = OpenDatabase(g_sLogdb)
  837.     Set oRec = db.OpenRecordset("tblPerformanceLog")
  838.     With oRec
  839.         .AddNew
  840.         !MarkerText = txtMarker
  841.         !Test = sTest
  842.         !Driver = g_sDriver
  843.         !CommandText = Left$(sText, 255)
  844.         !Provider = m_oConn.Provider
  845.         !ConnectionString = g_sConnectString
  846.         !CursorTypeRequested = CursorTypeDesc(iCursorTypeRequested)
  847.         !CursorTypeReceived = CursorTypeDesc(iCursorTypeReceived)
  848.         !LockType = LockTypeDesc(iLockType)
  849.         !CursorLocation = CursorLocationDesc(iCursorLocation)
  850.         !CommandType = CommandTypeDesc(iCommandType)
  851.         !NumTimes = iTimes
  852.         !TotalTime = lTime
  853.         !NumRows = m_iNumRows
  854.         !CacheSize = CLng(txtCacheSize)
  855.         .Update
  856.     End With
  857.     oRec.Close
  858.     db.Close
  859.     
  860.     Set oRec = Nothing
  861.     Set db = Nothing
  862. End Sub
  863. Private Function CursorTypeDesc(ByVal iCT As CursorTypeEnum) As String
  864.     ' return the description for the cursor type
  865.     
  866.     Select Case iCT
  867.     Case adOpenForwardOnly
  868.         CursorTypeDesc = "adOpenForwardOnly"
  869.     Case adOpenKeyset
  870.         CursorTypeDesc = "adOpenKeyset"
  871.     Case adOpenStatic
  872.         CursorTypeDesc = "adOpenStatic"
  873.     Case adOpenDynamic
  874.         CursorTypeDesc = "adOpenDynamic"
  875.     End Select
  876. End Function
  877. Private Function LockTypeDesc(ByVal iLT As LockTypeEnum) As String
  878.     ' return the description for the lock type
  879.     Select Case iLT
  880.     Case adLockReadOnly
  881.         LockTypeDesc = "adLockReadOnly"
  882.     Case adLockPessimistic
  883.         LockTypeDesc = "adLockPessimistic"
  884.     Case adLockOptimistic
  885.         LockTypeDesc = "adLockOptimistic"
  886.     Case adLockBatchOptimistic
  887.         LockTypeDesc = "adLockBatchOptimistic"
  888.     End Select
  889. End Function
  890. Private Function CursorLocationDesc(ByVal iCL As CursorLocationEnum) As String
  891.     ' return the description for the cursor location
  892.     Select Case iCL
  893.     Case adUseServer
  894.         CursorLocationDesc = "adUseServer"
  895.     Case adUseClient
  896.         CursorLocationDesc = "adUseClient"
  897.     End Select
  898. End Function
  899. Private Function CommandTypeDesc(ByVal iCT As CommandTypeEnum) As String
  900.     ' return the description for the command type
  901.     Select Case iCT
  902.     Case (adCmdText And m_iadExecuteNoRecords)
  903.         CommandTypeDesc = "adCmdText + NoRecs"
  904.     Case (adCmdStoredProc And m_iadExecuteNoRecords)
  905.         CommandTypeDesc = "adCmdStoredProc + NoRecs"
  906.     Case adCmdText
  907.         CommandTypeDesc = "adCmdText"
  908.     Case adCmdStoredProc
  909.         CommandTypeDesc = "adCmdStoredProc"
  910.     Case adCmdTable
  911.         CommandTypeDesc = "adCmdTable"
  912.     Case m_iadCmdTableDirect
  913.         CommandTypeDesc = "adCmdTableDirect"
  914.     Case adCmdUnknown
  915.         CommandTypeDesc = "adCmdUnknown"
  916.     End Select
  917. End Function
  918. Private Sub Form_Unload(Cancel As Integer)
  919.     If m_oConn.State = adStateOpen Then
  920.         m_oConn.Close
  921.         Set m_oConn = Nothing
  922.     End If
  923. End Sub
  924. Private Sub tabTables_Click()
  925.     ' make the appropriate frame containing the tables or
  926.     ' queries list box, or the SQL text box visible
  927.     
  928.     Dim iIndex      As Integer
  929.     iIndex = tabTables.SelectedItem.Index - 1
  930.     If iIndex <> m_iTab Then
  931.         fraTables(m_iTab).Visible = False
  932.         m_iTab = iIndex
  933.         fraTables(m_iTab).Visible = True
  934.     End If
  935.     chkNoRecords.Visible = (iIndex <> 0)
  936. End Sub
  937. Private Sub SchemaFill(lstList As ListBox, iSchemaType As SchemaEnum)
  938.     ' fill the tables/queries list boxes
  939.     ' Access queries appear in the tables schema as a view
  940.     Dim oRec        As ADODB.Recordset
  941.     Dim sField      As String
  942.     Dim sAccView    As String               ' access view name
  943.     Dim sType       As String
  944.     Select Case iSchemaType
  945.     Case adSchemaTables
  946.         sField = "TABLE_NAME"
  947.         sAccView = "TABLE"
  948.         sType = "TABLE_TYPE"
  949.     Case adSchemaProcedures
  950.         sField = "PROCEDURE_NAME"
  951.         sType = "PROCEDURE_TYPE"
  952.     Case adSchemaViews
  953.         iSchemaType = adSchemaTables
  954.         sField = "TABLE_NAME"
  955.         sAccView = "VIEW"
  956.         sType = "TABLE_TYPE"
  957.     End Select
  958.     
  959.     Set oRec = m_oConn.OpenSchema(iSchemaType)
  960.     lstList.Clear
  961.     While Not oRec.EOF
  962.         ' skip system tables
  963.         If oRec(sType) <> "SYSTEM TABLE" Then
  964.             If sAccView = "" Then
  965.                 lstList.AddItem oRec(sField)
  966.             Else
  967.                 If sAccView = oRec("TABLE_TYPE") Then
  968.                     lstList.AddItem oRec(sField)
  969.                 End If
  970.             End If
  971.         End If
  972.         oRec.MoveNext
  973.     Wend
  974.     
  975.     oRec.Close
  976.     Set oRec = Nothing
  977. End Sub
  978. Private Sub SetVersionSpecifics()
  979. '
  980. ' set the ado2 specifics
  981. ' needs to be compiler directives so that this will compile on
  982. ' an ado 1.5 system
  983. #If ADO15 Then
  984.     m_iadCmdTableDirect = adCmdTable
  985.     m_iadExecuteNoRecords = 128
  986. #Else
  987.     m_iadCmdTableDirect = adCmdTableDirect
  988.     m_iadExecuteNoRecords = adExecuteNoRecords
  989. #End If
  990. End Sub