从 ODBC Openedge 10.2B 确定主键

Determining Primary Keys from ODBC Openedge 10.2B

我目前正在为 Yii2 实现一个 ActiveRecord 驱动程序,这样我就可以通过他们推荐的 API 在我的 Yii 应用程序中利用我的进度数据库。但是,因为在 ActiveRecord 中需要设置主键才能正常运行(它必须知道哪些字段是记录的唯一标识符),所以我不得不在我创建的每个模型 class 上手动设置这些. (驱动可以在https://github.com/ExchangeCore/yii2-progress-driver/tree/10.2.x查看)

我想知道的是,如果我忽略了某些方法或 SYSPROGRESS table(或其他 ODBC 函数),它们实际上可能具有哪些字段是主键。我对 SYSINDEXES table 抱有希望,但我不确定如何正确识别哪个索引是主键。

Progress DB 没有 "primary key" - 最接近 PK 的是在 table.

上使用唯一索引

如果您在 _Index table 中查找给定的 _File._file-名称,您需要一条 _Unique 为真的记录。

_file._prime-index 是描述标记为 "primary".

的索引的 _index 记录的 RECID

它可能是唯一的,也可能不是唯一的(这不是必需的)。

我不是 SQL 人(我也不在电视上玩)但是这个 4GL 代码会找到 "activity" table 的主索引(如果你有这样一个table), 告诉你它是否唯一并列出构成索引的字段:

find _file no-lock where _file-name = "activity".

find _index no-lock where recid( _index ) = _file._prime-index no-error.

if available _index then
  do:
    display _index._unique.
    for each _index-field no-lock where _index-field._index-recid = recid( _index ):
      find _field no-lock where recid( _field ) = _index-field._field-recid.
      display _field-name.
    end.
  end.