In the following example, we look at extracts of a GetEstimatedSize event handler defined on the Table metaclass to estimate the size of the database by calculating the size of each table as the total size of all its columns plus the total size of all its indexes.
Note: For examples of the GetEstimatedSize event handler in use on the Table and other metaclasses, see the Sybase IQ v15.2 and HP Neoview R2.4 DBMS definition files.
In this first extract from the script, the
GetEstimatedSize function opens and the size of each table is obtained by looping through the size of each of its columns. The actual work of calculating the column size is done by the line:
ColSize = C.GetEstimatedSize(message, false)
, which calls the
GetEstimatedSize event handler
on the
Column metaclass (see
Calling the GetEstimatedSize Event Handler on Another Metaclass):
Function %GetEstimatedSize%(obj, ByRef message)
' First compute global database setting variable we will need.
' Get table size and keep column size for future use
Dim ColSizes, TblSize, ColSize, C
Set ColSizes = CreateObject("Scripting.Dictionary")
TblSize = 0 ' May be changed to take into account table definition initial size.
for each C in obj.Columns
' Start browsing table columns and use event handler defined on column metaclass (if it exists).
ColSize = C.GetEstimatedSize(message, false)
' Store column size in the map for future use in indexes.
ColSizes.Add C, ColSize
' Increase the table global size.
TblSize = TblSize + ColSize
next
Dim RawDataSize
RawDataSize = BlockSize * int(obj.Number * TblSize / BlockSize)
' At this point, the RawDataSize is the size of table in database.
Next the size of the table indexes is calculated directly in the script without making a call to an event handler on the Index metaclass, the line outputting index sizes is formatted and the size of the indexes added to the total database size:
' Now calculate index sizes. Set up variables to store indexes sizes.
Dim X, XMsg, XDataSize
XMsg = ""
for each X in obj.Indexes
XDataSize = 0
' Browsing index columns and get their size added in XDataSize
For each C in X.IndexColumns
XDataSize = XDataSize + ColSizes.Item(C.Column)
next
XDataSize = BlockSize * int(obj.Number * XDataSize / BlockSize)
' Format the display message in order to get size information in output and result list.
XMsg = XMsg & CStr(XDataSize) & "|" & X.ObjectID & vbCrLf
' Add the index size to table size.
RawDataSize = RawDataSize + XDataSize
next
Finally the size information is formatted for output (see
Formatting the Database Size Estimation Output). Each table is printed on a separate line in both the Output and Result List windows, and its total size including all columns and indexes is given:
' set the global message to table size and all indexes (separate with carriage return).
message = CStr(RawDataSize) & "||" & obj.ShortDescription & vbCrLf & XMsg
%GetEstimatedSize% = RawDataSize
End Function
Once all the tables have been processed, PowerDesigner calculates and prints the total estimated size of the database.