天天看点

powerdesigner逆向工程生成PDM时的列注释解决方案的补充

在《powerdesigner逆向工程生成PDM时的列注释解决方案 》一文中,我介绍了如何在逆向工程中从现有数据库中生成PDM文件时将数据库中的Description直接带到PDM中,主要解释了我的解决思路,有些乱。有的朋友不是很清楚,在本文中再次补充一个清晰的思路,希望能给大家带来帮助。

总体思路是根据PD自带的模板修改而成。修改前请备份Sybase安装路径/Resource Files/DBMS文件夹。

  邀月使用的是Powerdesigner 15.3,数据库为SQL Server 2008 r2

步骤:

1、创建DBMS

  Powerdesigner界 面-tools-Resources-DBMS,点击左上角的New,选择copy from templete,如果你的数据库是sql server 2005,选择系统自带的SQL server 2005,如果是sql server 2008,选择系统自带的sqlsv2k8.xdb。本例中是sql server 2008 r2,故选择 sqlsv2k8.xdb,起一个新名字,如 SQL2008_Mod_201105。

powerdesigner逆向工程生成PDM时的列注释解决方案的补充

2、建立数据源,逆向生成测试,顺利成功!

powerdesigner逆向工程生成PDM时的列注释解决方案的补充

此时再生成数据库脚本时,会自动将Comment中的中文注释带入到脚本中。

powerdesigner逆向工程生成PDM时的列注释解决方案的补充

美中不足的是Name还是英文 ,在一个包中查看表时,感觉怪怪的。

有两个解决办法:

3-1、改进脚本

Powerdesigner界面-Database-Edit Current DBMS

如下: (本文以sql server 2008为例,sql server 2005类同。 )

将表的Name换为Comment

powerdesigner逆向工程生成PDM时的列注释解决方案的补充

将列的Name换为Comment

powerdesigner逆向工程生成PDM时的列注释解决方案的补充

此时生成的效果最为理想。

powerdesigner逆向工程生成PDM时的列注释解决方案的补充

3-2、利用vbs脚本完成。

在Sybase安装路径/VB Scripts 下新建Comments2Name.vbs,内容如下:

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 code 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

if len(tab.comment) <> 0 then

tab.name = tab.comment

end if

On Error Resume Next

Dim col 'running column

for each col in tab.columns

if len(col.comment) <>0 then

col.name =col.comment

end if

On Error Resume Next

next

end if

next

end sub

在生成的PDM中,Powerdesigner界面-tools-Execute Cmmands-Edit/Run Scripts 在打开的界面中,左上角,选择打开,Ctrl+O,选取刚才的 Comments2Name.vbs,并Run,效果同上。

powerdesigner逆向工程生成PDM时的列注释解决方案的补充
powerdesigner逆向工程生成PDM时的列注释解决方案的补充

邀月注:本文版权由邀月和CSDN共同所有,转载请注明出处。

助人等于自助!  [email protected]