PowerDesigner LDM/PDM 中的自动重命名列

发布于 2024-08-23 07:07:20 字数 284 浏览 8 评论 0原文

我想根据主复选框的状态重命名 PowerDesigner LDM/PDM 中的列。更具体地说,如果选中 Primary,我希望将该列从“oldname”重命名为“id_oldname”。

我认为可以使用自定义检查/自动修复脚本,例如“MSSQLSRV2008::Profile\Column\Custom Checks\Identity Seed and Incrementvalidity”中的脚本,但我真的不是 VBScript 专家:)

有没有一种简单的方法可以在 PowerDesigner 15 中实现这一点吗?

I want to rename columns in a PowerDesigner LDM/PDM according to the state of the Primary checkbox. To be more specific, I want the column renamed from "oldname" to "id_oldname" if Primary is checked.

I think it is possible with a custom check/autofix script like the one in "MSSQLSRV2008::Profile\Column\Custom Checks\Identity Seed and Increment validity" but I'm really not a VBScript expert :)

Is there an easy way to achieve that in PowerDesigner 15?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小鸟爱天空丶 2024-08-30 07:07:20

解决方案非常简单。不幸的是,这并不是一个完美的方案,因为 PowerDesigner 在某些情况下(由于某种未知的原因)无法执行事件处理程序。下面的小vb脚本应该能够处理它。将创建扩展模型定义文件并将其附加到项目中。该脚本是表元类的验证事件处理程序(尽管它是自动修复而不是验证)。

Function %Validate%(obj, ByRef message) 
   ' Implement your object validation rule on <parent> here 
   ' and return True in case of success, False otherwise with a message 
   dim col    
   for each col in obj.columns      
      if col.Primary = true then 
         if left(col.name,3) <> "id_" then 
            With col 
               .name = "id_" & .name 
               .SetNameAndCode .Name, "", True 
            End With 
         end if 
      else 
         if left(col.name,3) = "id_" then 
            with col 
               .name = right(.name, len(.name)-3) 
               .SetNameAndCode .Name, "", True 
            end with 
         end if 
      end if 
   next 
   %Validate% = True
End Function 

这要归功于提供原始代码的 Richard Kier。谢谢,理查德。

The solution is quite simple. Unfortunately not a flawless one, because PowerDesigner fails to execute the event handler in some cases (for some unknown reason). The small vbscript below should be able to handle it. An extended model definition file is to be created and attached to the project. The script is a Validate Event Handler of the Table metaclass (though it's rather an autofix than a validation).

Function %Validate%(obj, ByRef message) 
   ' Implement your object validation rule on <parent> here 
   ' and return True in case of success, False otherwise with a message 
   dim col    
   for each col in obj.columns      
      if col.Primary = true then 
         if left(col.name,3) <> "id_" then 
            With col 
               .name = "id_" & .name 
               .SetNameAndCode .Name, "", True 
            End With 
         end if 
      else 
         if left(col.name,3) = "id_" then 
            with col 
               .name = right(.name, len(.name)-3) 
               .SetNameAndCode .Name, "", True 
            end with 
         end if 
      end if 
   next 
   %Validate% = True
End Function 

The credit goes to Richard Kier who supplied the original code. Thanks, Richard.

瑾夏年华 2024-08-30 07:07:20

人们可以编写 VBScript 来搜索对象模型,查找作为主键成员的列并重命名它们。

或者:

  • 可以调出一列列表
    (右键单击一个包或
    型号、列表->列)

  • 按 control-U(或单击
    漏斗和铅笔图标)来调出
    自定义列和过滤器。

    • 在“列标题”列中查找主键条目。
    • 在过滤器表达式中,将表达式设置为 True。
    • 检查 U 列中的主键条目,并确保没有
      其他行已检查。
    • 按“应用”。

您现在应该看到作为键一部分的所有列。您可以类似地使用通配符过滤不合规的名称。您还可以选择多行并同时重命名它们。

One can write the VBScript to trawl the object model, looking for columns that are members of primary keys and renaming them.

Or:

  • One can bring up a list of columns
    (Right click on a package or the
    model, List of -> Columns)

  • Press control-U (or click on the
    funnel-and-pencil icon) to bring up
    Customize Columns and Filter.

    • Find the Primary Key entry in the Column Heading column.
    • In the Filter Expression, set the expression to True.
    • Check the U column for the Primary Key entry, and make sure no
      other rows have that checked.
    • Press Apply.

You should now see all the columns that are part of keys. You can similarly filter with wildcards for non-compliant names. You can also select multiple rows and rename them at the same time.

沉鱼一梦 2024-08-30 07:07:20

有一个更简单的方法。

  1. 转到数据库 - 生成数据库 - 保存生成的 sql 文件。
  2. 使用文本编辑器进行重命名或进行任何所需的编辑。
  3. 转到数据库 - 从数据库更新模型 - 指向生成的 sql 文件。

该工具显示更新后的模型。

There is a much simpler method to this.

  1. Go to Database - Generate Database - Save the generated sql file.
  2. Use a text editor to rename or whatever edits are needed.
  3. Go to Database - Update Model from Database - point to the sql file generated.

The tool shows the updated model.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文