gpt4 book ai didi

sql - 将 SQL 转换为 OCL?

转载 作者:行者123 更新时间:2023-12-03 15:53:30 25 4
gpt4 key购买 nike

我有一段 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com