(轉)PowerDesigner 把Comment寫到name中 和把name寫到Comment中 pd7以後版本可用

denniswwh發表於2009-09-16

作者:劍飄紅 原文連結:http://www.cnblogs.com/cxd4321/archive/2009/03/07/1405475.html

在使用PowerDesigner對資料庫進行概念模型和物理模型設計時,一般在NAME或Comment中寫中文,在Code中寫英文。Name用來顯 示,Code在程式碼中使用,但Comment中的文字會儲存到資料庫Table或Column的Comment中,當Name已經存在的時候,再寫一次 Comment很麻煩,可以使用以下程式碼來解決這個問題:

[@more@]
  • 程式碼一:將Name中的字元COPY至Comment中

    Option Explicit
    ValidationMode = True
    InteractiveMode = im_Batch

    Dim mdl ' the current model

    ' get the current active model
    Set mdl = ActiveModel
    If (mdl Is Nothing) Then
    MsgBox "There is no current Model "
    ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
    MsgBox "The current model is not an Physical Data model. "
    Else
    ProcessFolder mdl
    End If

    ' This routine copy name into comment for each table, each column and each view
    ' of the current folder
    Private sub ProcessFolder(folder)
    Dim Tab 'running table
    for each Tab in folder.tables
    if not tab.isShortcut then
    tab.comment = tab.name
    Dim col ' running column
    for each col in tab.columns
    col.comment= col.name
    next
    end if
    next

    Dim view 'running view
    for each view in folder.Views
    if not view.isShortcut then
    view.comment = view.name
    end if
    next

    ' go into the sub-packages
    Dim f ' running folder
    For Each f In folder.Packages
    if not f.IsShortcut then
    ProcessFolder f
    end if
    Next
    end sub

--------------------------------------------

另外在使用REVERSE ENGINEER從資料庫反向生成PDM的時候,PDM中的表的NAME和CODE事實上都是CODE,為了把NAME替換為資料庫中Table或Column的中文Comment,可以使用以下指令碼:

  • 程式碼二:將Comment中的字元COPY至Name中


    Option Explicit
    ValidationMode = True
    InteractiveMode = im_Batch

    Dim mdl ' the current model

    ' get the current active model
    Set mdl = ActiveModel
    If (mdl Is Nothing) Then
    MsgBox "There is no current Model "
    ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
    MsgBox "The current model is not an Physical Data model. "
    Else
    ProcessFolder mdl
    End If

    Private sub ProcessFolder(folder)
    On Error Resume Next
    Dim Tab 'running table
    for each Tab in folder.tables
    if not tab.isShortcut then
    tab.name = tab.comment
    Dim col ' running column
    for each col in tab.columns
    if col.comment="" then
    else
    col.name= col.comment
    end if
    next
    end if
    next

    Dim view 'running view
    for each view in folder.Views
    if not view.isShortcut then
    view.name = view.comment
    end if
    next

    ' go into the sub-packages
    Dim f ' running folder
    For Each f In folder.Packages
    if not f.IsShortcut then
    ProcessFolder f
    end if
    Next
    end sub

-----------------------------------------------------------------------

以上兩段程式碼都是VB指令碼,在PowerDesigner中使用方法為:

PowerDesigner->Tools->Execute Commands->Edit/Run Scripts

將程式碼Copy進去執行就可以了,是對整個CDM或PDM進行操作

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/124805/viewspace-1026983/,如需轉載,請註明出處,否則將追究法律責任。

相關文章