sql - 将 SQL 转换为 OCL?

标签 sql delphi ocl bold-delphi

我有一段 SQL 想要转换为 OCL。我不擅长 SQL,所以我想通过它来提高可维护性。我们使用 Interbase 2009、Delphi 2007 进行 Bold 和模型驱动开发。现在我希望这里有人能讲好 SQL 和 OCL :-) 原始SQL:

Select Bold_Id, MessageId, ScaniaId, MessageType, MessageTime, Cancellation, ChassieNumber, UserFriendlyFormat, ReceivingOwner, Invalidated, InvalidationReason,
(Select Parcel.MCurrentStates From Parcel
Where ScaniaEdiSolMessage.ReceivingOwner = Parcel.Bold_Id) as ParcelState From ScaniaEdiSolMessage
Where MessageType = 'IFTMBP' and
not Exists (Select * From ScaniaEdiSolMessage EdiSolMsg
Where EdiSolMsg.ChassieNumber = ScaniaEdiSolMessage.ChassieNumber and EdiSolMsg.ShipFromFinland = ScaniaEdiSolMessage.ShipFromFinland and EdiSolMsg.MessageType = 'IFTMBF') and
invalidated = 0 Order By MessageTime desc

稍作简化后:

Select Bold_Id, (Select Parcel.MCurrentStates From Parcel 
where ScaniaEdiSolMessage.ReceivingOwner = Parcel.Bold_Id) From ScaniaEdiSolMessage
Where MessageType = 'IFTMBP' and not Exists (Select * From ScaniaEdiSolMessage
EdiSolMsg Where EdiSolMsg.ChassieNumber = ScaniaEdiSolMessage.ChassieNumber and
EdiSolMsg.ShipFromFinland = ScaniaEdiSolMessage.ShipFromFinland and 
EdiSolMsg.MessageType = 'IFTMBF') and invalidated = 0

注意:MessageType 有 2 种情况:“IFTMBP”和“IFTMBF”。

因此要列出的表是 ScaniaEdiSolMessage。 它具有如下属性:

  • 消息类型:字符串
  • 底盘编号:字符串
  • 从芬兰发货: bool 值
  • 无效: bool 值

它还有一个指向名为 ReceivingOwner 的表 Parcel 的链接,其中 BoldId 作为键。

所以看起来它列出了 ScaniaEdiSolMessage 的所有行,然后有一个子查询也列出了 ScaniaEdiSolMessage 的所有行并将其命名为 EdiSolMsg。然后它排除几乎所有行。事实上,上面的查询从 28000 条记录中给出了一次命中。

在 OCL 中,很容易列出所有实例:

ScaniaEdiSolMessage.allinstances

还可以轻松地通过选择来过滤行,例如:

ScaniaEdiSolMessage.allinstances->select(shipFromFinland and not invalidated)

但是我不明白应该如何制作 OCL 来匹配上面的 SQL。

最佳答案

听 Gabriel 和 Stephanie 的讲解,了解更多 SQL。

您声称希望使代码更易于维护,但了解 SQL 的开发人员数量远远多于了解 OCL 的开发人员数量。

如果您在将其转换为 OCL 后明天离开该项目,那么您找到可以维护 OCL 的人的机会非常渺茫。然而,您找到人来维护 SQL 的机会非常高。

不要仅仅因为你擅长使用圆锤就试图将方钉插入圆孔:)

关于sql - 将 SQL 转换为 OCL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3017937/

相关文章:

mysql - 多列高分,高效查询,正确做法

mysql - sql insert into, select, where 语句

delphi - 具有相同 GUID 的两个接口(interface)的相关性交互是什么

OCL at0 运算符语法错误

mysql - 想要仅根据列值消除重复记录

sql - 文本数组中的 Postgres 检查约束值的有效性

delphi - Chrome : How to keep session alive

delphi - 在 DWScript 中的 OnFastEval 事件中获取结果数据上下文

java - 将 OCL 表达式解析为 AST(抽象语法树)

linux - 将 hashCat 与 RAR 文件一起使用?