码迷,mamicode.com
首页 > 其他好文 > 详细

PowerDesigner中遍历物理模型中的所有表,检查表代码、字段代码

时间:2015-07-01 20:11:30      阅读:347      评论:0      收藏:0      [点我收藏+]

标签:

‘*****************************************************************************
‘文件:CheckCode4SqlServer.vbs
‘版本:1.0
‘功能:遍历物理模型中的所有表,检查表代码、字段代码
‘      是否包含空格、是否包含中文、是否为系统关键字、是否长度超过116
‘用法:打开物理模型,运行本脚本(Ctrl+Shift+X)
‘备注:
‘*****************************************************************************
 dim model ‘current model
 set model = ActiveModel
 If (model Is Nothing) Then
   MsgBox "没有选择模型,请选择一个模型并打开."
 ElseIf Not model.IsKindOf(PdPDM.cls_Model) Then
   MsgBox "当前选择的不是一个物理模型(PDM)."
 Else
   ProcessTables model
 End If
 
‘*****************************************************************************
‘过程:ProcessTables
‘功能:递归遍历所有的表
‘*****************************************************************************
 sub ProcessTables(folder)
   ‘处理模型中的表
   dim table
   for each table in folder.tables
     if not table.IsShortCut then 
       on error resume next   

       ‘检查表名中是否有特殊字符、是否为关键字
       Check table.code, ""
    
       Dim col
       for each col in table.Columns     
         ‘检查字段名中是否有特殊字符、是否为关键字
         Check col.code, table.code
       next 
     end if
   next
   
   ‘对子目录进行递归
   dim subFolder
   for each subFolder in folder.Packages
     ProcessTables subFolder
   next    
end sub

‘*****************************************************************************
‘过程:Check
‘功能:检查表名 或 字段名
‘*****************************************************************************
sub Check(str, tableCode)
  dim outStr
  if len(tableCode) > 0 then
    outStr = "字段名 " & tableCode & "."
  else 
  	outStr = "表名 " 
  end if

  ‘检查表明是否含有特殊字符
  if InStr(str, " ") then     
    outStr = outStr & str & " 包含空格"
    Output outStr
  end if

  ‘是否包含中文
  if HasChinese(str) then 
    outStr = outStr & str & " 包含中文"
    Output outStr
  end if

  ‘检测系统关键字
  dim arr
  arr = array("ADD","EXTERNAL","PROCEDURE","ALL","FETCH","PUBLIC","ALTER","FILE","RAISERROR","AND","FILLFACTOR","READ","ANY","FOR","READTEXT","AS","FOREIGN","RECONFIGURE","ASC","FREETEXT","REFERENCES","AUTHORIZATION","FREETEXTTABLE","REPLICATION","BACKUP","RESTORE","BEGIN","FULL","RESTRICT","BETWEEN","FUNCTION","RETURN","BREAK","GOTO","REVERT","BROWSE","GRANT","REVOKE","BULK","GROUP","RIGHT","BY","HAVING","ROLLBACK","CASCADE","HOLDLOCK","ROWCOUNT","CASE","IDENTITY","ROWGUIDCOL","CHECK","IDENTITY_INSERT","RULE","CHECKPOINT","IDENTITYCOL","SAVE","CLOSE","IF","SCHEMA","CLUSTERED","IN","SECURITYAUDIT","COALESCE","INDEX","SELECT","COLLATE","INNER","SEMANTICKEYPHRASETABLE","COLUMN","INSERT","SEMANTICSIMILARITYDETAILSTABLE","COMMIT","INTERSECT","SEMANTICSIMILARITYTABLE","COMPUTE","INTO","SESSION_USER","CONSTRAINT","IS","SET","CONTAINS","JOIN","SETUSER","CONTAINSTABLE","KEY","SHUTDOWN","CONTINUE","KILL","SOME","CONVERT","LEFT","STATISTICS","CREATE","LIKE","SYSTEM_USER","CROSS","LINENO","TABLE","CURRENT","LOAD","TABLESAMPLE","CURRENT_DATE","MERGE","TEXTSIZE","CURRENT_TIME","NATIONAL","THEN","CURRENT_TIMESTAMP","NOCHECK","CURRENT_USER","NONCLUSTERED","TOP","CURSOR","NOT","TRAN","DATABASE","NULL","TRANSACTION","DBCC","NULLIF","TRIGGER","DEALLOCATE","OF","TRUNCATE","DECLARE","OFF","TRY_CONVERT","DEFAULT","OFFSETS","TSEQUAL","DELETE","ON","UNION","DENY","OPEN","UNIQUE","DESC","OPENDATASOURCE","UNPIVOT","DISK","OPENQUERY","UPDATE","DISTINCT","OPENROWSET","UPDATETEXT","DISTRIBUTED","OPENXML","USE","DOUBLE","OPTION","USER","DROP","OR","VALUES","DUMP","ORDER","VARYING","ELSE","OUTER","VIEW","END","OVER","WAITFOR","ERRLVL","PERCENT","WHEN","ESCAPE","PIVOT","WHERE","EXCEPT","PLAN","WHILE","EXEC","PRECISION","WITH","EXECUTE","PRIMARY","WITHIN GROUP","EXISTS","PRINT","WRITETEXT","EXIT","PROC")
  for each keyword in arr 
    if UCase(str) = keyword then
      outStr = outStr & str & " 为系统关键字"
      Output outStr
    end if
  next 

  ‘字符串长度是否超出限制
  if Len(str) >= 116 then
    outStr = outStr & str & " 命名的长度不应超过116"
    Output outStr
  end if
end sub

‘*****************************************************************************
‘函数:HasChinese
‘功能:是否包含中文
‘*****************************************************************************
function HasChinese(str) 
  HasChinese = false 

  dim i 
  for i=1 to Len(str) 
    if Asc(Mid(str,i,1)) < 0 then 
      HasChinese = true 
      exit for 
    end if 
  next 
end function 

 

PowerDesigner中遍历物理模型中的所有表,检查表代码、字段代码

标签:

原文地址:http://www.cnblogs.com/smallidea/p/4613785.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!