How do I always insert new records at the end of a table?


Problem

The XiDB_PRE_INSERT operation normally inserts a new record just before the current row of a table. Some applications want an insert button to always open a new row at the end of a table.

Solution

You can get the desired behavior by moving to the last record and then doing an XiDB_NEXT_RECORD operation (providing XmNautoInsertAtEnd is True).

XiDBInsertAtEndCB is a routine which will do all the steps neccessary to perform this operation transparently. It will do an XiDB_LAST_RECORD, set XmNautoInsertAtEnd to True and then to an XiDB_NEXT_RECORD. Finally, it resets XmNautoInsertAtEnd to False, if neccessary.

Create an XiDBPushButton.

  • Set XmNquery to the controlling Query
  • Set XmNactivateCallback to XiDBInsertAtEnd("")
  • Set XmNqueryOpcode to XiDB_NOP
  • Set XmNcreateCallback to XiDBQueryRegisterControlCB("XiDB_PRE_INSERT")

Adding this feature to DX

  • Install XiDBInsertAtEndCB in ${DXHOME}/gen/common
  • cd ${DXHOME}/examples
  • Compile it by including it in a small C wrapper, insertAtEndCB.c .
  • Edit customize.c. Add the line
    • RegisterUserTypedCallback("XiDBInsertAtEndCB", XiDBInsertAtEndCB, XmRString);

    to the end of the AddUserFunctions routine

  • Compile and link DX as described in the DX & BX Users Guide and Makefile.dx

${DXHOME}/gen/common/XiDBInsertAtEndCB

${DXHOME}/examples/insertAtEndCB.c

${DXHOME}/examples/customize.c


HOME Call Us Send Email