Updating a row in a relational table

The database update snippet in the EGL drawer of the Snippets view is a function that updates a single row of a relational table when passed a record from a JSF Handler. This snippet is intended to be placed in an EGL library.

To insert and configure this snippet:

  1. In the EGL editor, place the cursor where you want the snippet to go. Because this snippet is a complete EGL function, the cursor must be placed where a function is legal.
  2. In the EGL drawer of the Snippets view, double-click the database update snippet. The Insert Template window opens.
  3. In the Insert Template window, set the value of TableName to the name of the table you are updating.
  4. Set the value of KeyColumn to the primary key column of the table.
  5. Click Insert.
  6. Save the file.
This snippet inserts the following code:
Function updateRec(EGL_RecordNameNew  EGL_RecordName) 
    //Function name - call this function passing 
    //the EGL_RecordName Record as a parameter
    EGL_RecordNameOld EGL_RecordName;   //A copy of the Record, 
    //used to lock the table row, and obtain the existing row values 
    //prior to update
    try
        EGL_RecordNameOld.Table_Key_column_ID 
            = EGL_RecordNameNew.Table_Key_column_ID;
        get EGL_RecordNameOld forUpdate;  //Get the existing row.  
        //Note that if you had custom processing to do, 
        //you would insert after this call
        move EGL_RecordNameNew to EGL_RecordNameOld byName;  
        //Move the updated values to the copy-row         
        replace EGL_RecordNameOld;  //And replace the row in the database.
        sysLib.commit();  //Commit your changes to the Database
    onException (ex AnyException)   //If the update fails...
        sysLib.rollback();  //cancel all database updates 
        //(assuming this is permitted by your database)
        // and call a custom error handling routine or something
    end
end

Feedback