1. 程式人生 > >PowerDesigner中使用vbscript訪問物件進行批量操作

PowerDesigner中使用vbscript訪問物件進行批量操作

Power Designer是資料建模中一個比較常用的工具,比較擅長大規模的E-R模型的設計。
對於一些批量操作,可以通過vbscript指令碼進行。
用法:開啟物理模型,點選選單“Tools->Execute Commands -> Edit/Run Script...",或者快捷鍵(Ctrl+Shift+X)。
下面指令碼是一個將模型中的表名、欄位名均改成大寫的一個簡易指令碼。在Power Designer 9.5中通過執行。
vbscript,其實我不會用,所以我會選擇一個比較複雜的例子,這個例子很簡單。
至於vbscript,可以去網上看看那些函式以及結構的用法,用起來也很簡單。
關於Power

Designer中用到的一些固定屬性或者實體,可以參照Power Designer的幫助,可以查到。

'*****************************************************************************
'檔案:powerdesigner.ucase.VBs
'版本:1.0
'功能:遍歷物理模型中的所有表,將表名、表程式碼、欄位名、欄位程式碼全部由小寫改成大寫;
' 並將序列的名和程式碼由小寫改成大寫。
'用法:開啟物理模型,執行本指令碼(Ctrl+Shift+X)
'備註:
'*****************************************************************************
dim model 'current model
set model = ActiveModel

If (model Is Nothing) Then
MsgBox "There is no current Model"
ElseIf Not model.IsKindOf(PdPDM.cls_Model) Then
MsgBox "The current model is not an Physical Data model."
Else
ProcessTables model
ProcessSequences model
End If

'*****************************************************************************
'函式:ProcessSequences
'功能:遞迴遍歷所有的序列
'*****************************************************************************
sub ProcessSequences(folder)
'處理模型中的序列:小寫改大寫
dim sequence
for each sequence in folder.sequences
sequence.name = UCase(sequence.name)
sequence.code = UCase(sequence.code)
next
end sub

'*****************************************************************************
'函式:ProcessTables
'功能:遞迴遍歷所有的表
'*****************************************************************************
sub ProcessTables(folder)
'處理模型中的表
dim table
for each table in folder.tables
if not table.IsShortCut then
ProcessTable table
end if
next
'對子目錄進行遞迴
dim subFolder
for each subFolder in folder.Packages
ProcessTables subFolder
next
end sub

'*****************************************************************************
'函式:ProcessTable
'功能:遍歷指定table的所有欄位,將欄位名由小寫改成大寫,
' 欄位程式碼由小寫改成大寫
' 表名由小寫改成大寫
'*****************************************************************************
sub ProcessTable(table)
dim col
for each col in table.Columns
'將欄位名由小寫改成大寫
col.code = UCase(col.code)
col.name = UCase(col.name)
next
table.name = UCase(table.name)
table.code = UCase(table.code)
end sub