3.2.5. Updating Existing Rows in a Database

To update an existing row in a database, you must know the primary key for the row you wish to update. Normally you find this key by performing a query on the database:

local   result = .conn.QueryToClass (tableclass, string
                                      ("select * from ",
                                       tableclass.__table,
                                       " where name = '",
                                       "the_point_name", "'"));
local   record = result[0];

The primary key column of the record will identify the row in the database. You can now modify the record:

record.ptvalue = new_point_value;

and update the record in the database:

.conn.Update (record);

If an error occurs, the Update method will throw an error that can be handled by a try/catch block.