给出 table 和列名时如何在连接的 openge 数据库中插入字段值

how to insert the field values in the connected openedge database when table and column names are given

我通过直接给 table 名称检索了 table 的字段名称(INS_TEST 是我的 table 的名称)。我使用了 _Field 系统的 _Field-Name、_Data-Type 列 table 并检索了字段名称及其数据类型。

我想使用检索到的字段名称并将字段值插入到这些字段中。

FOR EACH _File WHERE _File-Name = "INS_TEST":

    FOR EACH _Field WHERE _File-Recid = RECID(_File):
        DISPLAY _Field._Field-Name.
        DISPLAY _Field._Data-Type.
        ASSIGN _File._File-Name._Field._Field-Name = 1 WHEN (_Field._Data-Type EQ "INTEGER").
    END.
END.

但是ASSIGN语句报错。请提建议!

不要为此使用 _field table。 _file 和 _field(实际上,任何以下划线开头的 table)是您的元模式 table。他们是您学习动态编程甚至理解您的模式当前是如何定义的朋友,但我强烈建议您不要尝试自己操作它们。如果我没理解错的话,听起来你并没有真正尝试这样做。 所以一旦你有了 ins_test 字段,你就可以在一个块中进行静态分配(同样,在这种情况下不需要查询或循环下划线 tables):

CREATE ins_test.
ASSIGN ins_test.field1 = value1
       ins_test.field2 = value2
       ins_test.field3 = value3 NO-ERROR.
IF ERROR-STATUS:ERROR THEN DO:
   /* Treat your error here */
END.

或者,如果您真的在研究动态分配(考虑到您可能仍在起步,这会更难),您需要研究动态查询和动态缓冲区以便理解它们,然后您可以创建通过获取缓冲区的句柄来记录记录,然后使用 BUFFER-FIELD 属性分配 table 以循环字段名称。

希望对您有所帮助。

下面的过程以table名称、字段名称和字符值作为参数。它将使用提供的值更新 table 的第一条记录中的相关字段。

显然,您可以编写更复杂的 WHERE 子句并做其他事情来满足您的特定需求。

procedure x:

  define input parameter tbl as character no-undo.
  define input parameter fld as character no-undo.
  define input parameter xyz as character no-undo.

  define variable qh as handle no-undo. 
  define variable bh as handle no-undo.
  define variable fh as handle no-undo.

  create buffer bh for table tbl.
  create query qh.
  qh:set-buffers( bh ).
  qh:query-prepare( "for each " + tbl ).
  qh:query-open.

  do transaction:
    qh:get-first( exclusive-lock ).
    fh = bh:buffer-field( fld ).
    display fh:buffer-value.
    fh:buffer-value = xyz.
  end.

  delete object bh.
  delete object qh.

  return.

end.

run x ( "customer", "name", "fred" ).

/* prove that we really did change it...
 */

find first customer no-lock.

display name.