Other query types
Integer insert()
insert() adds a new row to an existing table. Here’s how you do it:
- Populate the fields in the new record with
addData(). - Call
insert(). - Optionally do something with the returned ID.
Void update()
update() changes existing data in the database. Here’s how you do it:
-
Populate the fields you want to change.
- Use
addData()to add a value - Use
addDataField()to add a foreign key
- Use
-
Optionally use
addCriteria()to place restrictions on the items to modify. -
Call
update().
Void delete()
delete() removes data from the database. Think carefully before you delete anything!
Here’s how you do it:
- Build a complete select query.
- Optionally inspect the result set to check that you are deleting what you intend to.
-
Call
delete().
Best-practice is to use the NetServer agent classes to remove data because they also remove data from related tables and log changes to the traveltransactionlog.
Adding data for update and insert
You must write field names prefixed by their table name. For example,
customer.name.Void addData(String field, String value)
Adds data for use in an update or insert query.Void addDataField(String field1, String field2)
Adds a data field to the SearchEngine for use in an update query. A data field doesn’t contain a value - it’s a foreign key to another field. The target field can be within the same table or in a related table.Void addDataField(String field1, String field2, String func)
A variant ofaddDataField() specifying an aggregate function to use for field2.
The following functions are available:
-
any of the functions you can use with
addField()- listed in the reference section for the select query. - castToVarchar
- date
- time