打印本文 打印本文 关闭窗口 关闭窗口
DAO Advanced Programming
作者:武汉SEO闵涛  文章来源:敏韬网  点击数4801  更新时间:2009/4/23 16:38:42  文章录入:mintao  责任编辑:mintao
" & tdfTmp.Name, 1) If fProps Then Call WriteProps(tdfTmp, 2) '''' Iterate the fields collection For Each fldTmp In tdfTmp.Fields Call WriteOutput("TABLE FIELD: " & fldTmp.Name, 2) If fProps Then Call WriteProps(fldTmp, 3) Next fldTmp '''' Iterate the Indexes collection For Each idxTmp In tdfTmp.Indexes Call WriteOutput("INDEX: " & idxTmp.Name, 2) If fProps Then Call WriteProps(idxTmp, 3) '''' Iterate the index fields collection For Each fldTmp In idxTmp.Fields Call WriteOutput("INDEX FIELD: " & fldTmp.Name, 3) If fProps Then Call WriteProps(fldTmp, 4) Next fldTmp Next idxTmp Next tdfTmp '''' Iterate the Relations collection For Each relTmp In dbsCurrent.Relations Call WriteOutput("RELATION: " & relTmp.Name, 1) If fProps Then Call WriteProps(relTmp, 2) '''' Iterate the fields collection For Each fldTmp In relTmp.Fields Call WriteOutput("RELATION FIELD: " & fldTmp.Name, 2) If fProps Then Call WriteProps(fldTmp, 2) Next fldTmp Next relTmp '''' Iterate the querydefs collection For Each qdfTmp In dbsCurrent.QueryDefs Call WriteOutput("QUERY: " & qdfTmp.Name, 1) If fProps Then Call WriteProps(qdfTmp, 2) '''' Iterate the fields collection For Each fldTmp In qdfTmp.Fields Call WriteOutput("QUERY FIELD: " & fldTmp.Name, 2) If fProps Then Call WriteProps(fldTmp, 2) Next fldTmp Next qdfTmp '''' Iterate the Containers collection For Each cntTmp In dbsCurrent.Containers Call WriteOutput("CONTAINER: " & cntTmp.Name, 1) If fProps Then Call WriteProps(cntTmp, 2) '''' Iterate the Documents collection For Each docTmp In cntTmp.Documents Call WriteOutput("DOCUMENT: " & docTmp.Name, 2) If fProps Then Call WriteProps(docTmp, 3) Next docTmp Next cntTmp fDumpDAO = True Close intFileOut fDumpDAO_Exit: Exit Function fDumpDAO_Err: If fErrors Then WriteOutput "************** Error: " & Error$, 0 End If Resume Next End Function Private Sub Form_Open(Cancel As Integer) Me!lblVersion.Caption = "Version " & FMSVersion Me!txtFileName = "C:\DAO_DUMP.TXT" Me!chkProperties = True Me!chkErrors = True Me!txtTabs = 4 End Sub Private Sub WriteOutput(strOut As String, intIndent As Integer) '''' Comments : Writes the string out to the file '''' In : strOut - string to write '''' intIndent - number of indents '''' Out '''' Revisions '''' Dim strTabs As String strTabs = Space(intIndent * intTabs) Print #intFileOut, strTabs & strOut lngLines = lngLines + 1 End Sub Private Sub WriteProps(objIn As Object, intIndent As Integer) '''' Comments : Writes the name and value of the supplied property '''' In : objIn - object '''' intIndent - number of indents (hobo variable) '''' Out : '''' Revisions '''' Dim intSaveErr As Integer Dim strSaveErr As String Dim strName As String Dim varVal As Variant Dim prpTmp As Property For Each prpTmp In objIn.Properties '''' Disable error handler On Error Resume Next '''' Get the property name and value strName = prpTmp.Name varVal = prpTmp.Value intSaveErr = Err strSaveErr = Error$ '''' Reset error handler On Error GoTo 0 If intSaveErr = 0 Then Call WriteOutput(strName & ": " & varVal, intIndent) Else If fErrors Then Call WriteOutput("************** " & strName & ": Error (" & strSaveErr & ")", intIndent) End If End If Next prpTmp End Sub

Exercises for the Reader

You are welcome to extend this add-in add more functionality. For example, you may want to add the ability to write the results to a set of tables in the current database, rather than text files. Additionally, you may want to add to ability to get the structure of non-DAO objects such as forms and reports.

[Dividing Line Image]

Semi-Documented Tools and Resources

There are several Microsoft-Jet specific tools that you can use that are not fully documented in the documentation that ships with Microsoft products. Although these tools are not DAO-specific, they can make it easier to develop and maintain DAO applications.

TypeLib Browsers

Since the DAO 3.0 component includes an OLE Type Library, you can use a TypeLib browser to view all of the objects, collections, methods and properties, including stuff that is not documented. I have used the following two products with great success:

  • OLE2View, from Microsoft which ships as part of Visual C++
  • VBA Companion, from Apex Software

ISAMStats

Microsoft Jet contains an undocumented function called ISAMStats that shows various internal values. The syntax of the function is:

ISAMStats ((StatNum As Long [, Reset As Boolean]) As Long

Where StatNum is one of the following values:

StatNum Description 0 Number of disk reads 1 Number of disk writes 2 Number of reads from cache 3 Number of reads from read-ahead cache 4 Number of locks placed 5 Number of release lock calls

See the included add-in (JETMETER.EXE) for an example of how to use this function.

ShowPlan

Microsoft Jet implements a cost-based query optimize in its query engine. During the compilation process of the query, Jet determines the most effective way to execute the query. You can view this plan using the ShowPlan registry setting.

To use this setting, use the Registry Editor that comes with your operating system (REGEDIT.EXE for Windows 95 or REGEDT32.EXE for Windows NT) and add the following key to the registry:

\\HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\Jet\3.0\Engines\Debug

Under this key, add a string data type entry named JETSHOWPLAN in all capital letters. To turn ShowPlan on, set the value of this new entry to "ON". To turn the feature off, set the value to "OFF". When the feature is on, a text file called SHOWPLAN.OUT is created (or appended to if it already exists) in the current directory. This file contains the query plan(s).

MSLDBUSR.DLL

You can use the 32-bit program LDBVIEW.EXE program to view the users currently logged into a database, or you can use the MSLDBUSR.DLL component for programmatic access to this information. These files and associated documentation are included with this paper.

上一页  [1] [2] [3] [4] [5] 

打印本文 打印本文 关闭窗口 关闭窗口