天天看点

powerdesigner连接mysql生成pdm,及常用脚本使用

本文主要介绍三节内容:

1.安装odbc驱动——用于powerdesigner连接mysql

2.数据库生成模型

3.脚本的使用,如:如何将name拷贝给comment

4.如何显示原字段,并修改显示顺序

一:下载odbc驱动并进行安装

1.先查看mysql版本:

客户端:select version(); select @@version;

dos或linux:mysql -V;mysql --help |grep Distrib;status;select version(); select @@version;

2.选择合适的odbc版本,比如我的mysql大版本为5.6,仍可下载5.3.13的odbc插件。

直通车:https://dev.mysql.com/downloads/connector/odbc/5.3.html

无论PC是32位操作系统,还是64位,均可安装32位版本odbc。

3.安装

直接next–>finish

powerdesigner连接mysql生成pdm,及常用脚本使用
powerdesigner连接mysql生成pdm,及常用脚本使用

4.odbcad32.exe添加数据源

A.直接左下角开始处搜索odbc,点击弹出配置界面。

powerdesigner连接mysql生成pdm,及常用脚本使用
powerdesigner连接mysql生成pdm,及常用脚本使用

点击test,若成功点击OK。配置成功后显示如下图所示。

powerdesigner连接mysql生成pdm,及常用脚本使用

**

二.数据库生成模型

**

打开PowerDesigner软件,进行导入生成模型

A、选择菜单,导入数据源

powerdesigner连接mysql生成pdm,及常用脚本使用

B.选择数据库版本

powerdesigner连接mysql生成pdm,及常用脚本使用

C.点击添加odbc驱动

powerdesigner连接mysql生成pdm,及常用脚本使用
powerdesigner连接mysql生成pdm,及常用脚本使用

D.选中需要生成pdm的表,点击OK后即可生成数据库模型

powerdesigner连接mysql生成pdm,及常用脚本使用
powerdesigner连接mysql生成pdm,及常用脚本使用

三.使用vbs脚本对模型进行添加comment的操作

powerdesigner连接mysql生成pdm,及常用脚本使用
powerdesigner连接mysql生成pdm,及常用脚本使用
powerdesigner连接mysql生成pdm,及常用脚本使用

脚本一:显示备注信息

Option   Explicit   
    ValidationMode   =   True   
    InteractiveMode   =   im_Batch
    Dim blankStr
    blankStr   =   Space(1)
    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 = "" or replace(col.comment," ", "")="" Then
                            col.name = blankStr
                            blankStr = blankStr & Space(1)
                      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
           

脚本二:Name转到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
                     if  trim(tab.comment)="" then'如果有表的注释,则不改变它.如果没有表注释.则把name添加到注释里面.
                        tab.comment   =   tab.name
                     end if  
                  Dim   col   '   running   column    
                  for   each   col   in   tab.columns   
                        if trim(col.comment)="" then '如果col的comment为空,则填入name,如果已有注释,则不添加;这样可以避免已有注释丢失.
                           col.comment=   col.name   
                        end if 
                  next    
            end   if    
      next    
  
      Dim   view   'running   view    
      for   each   view   in   folder.Views    
            if   not   view.isShortcut and trim(view.comment)=""  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
           

脚本三:Comment注释字段转到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
           

脚本四:字段都转到大写的

Option Explicit
ValidationMode = True
InteractiveMode = im_Batch
Dim mdl 
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)
 Dim Tab
 for each Tab in folder.tables
   tab.code = UCase(tab.code)
   Dim col
   for each col in tab.columns
    col.code= UCase(col.code)
   next
   Dim idx
   for each idx in tab.indexes
    idx.code= UCase(idx.code)
   next
   Dim key
   for each key in tab.keys
    key.code= UCase(key.code)
   next
 next
 Dim f  
 For Each f In folder.Packages
  if not f.IsShortcut then
   ProcessFolder f
  end if
 Next
end sub
           

四.显示原字段,并修改字段顺序

A.显示原字段

powerdesigner连接mysql生成pdm,及常用脚本使用
powerdesigner连接mysql生成pdm,及常用脚本使用
powerdesigner连接mysql生成pdm,及常用脚本使用
powerdesigner连接mysql生成pdm,及常用脚本使用
powerdesigner连接mysql生成pdm,及常用脚本使用

B.修改字段顺序

powerdesigner连接mysql生成pdm,及常用脚本使用

参考:https://www.cnblogs.com/xmyjcs/p/8536233.html