Save Data
DataMgr makes it easy to save data to the database. DataMgr takes the data to be saved in a structure (any scope - Form or Arguments, for example - in ColdFusion will work) and saves it to the indicated table. There are three primary methods for saving data. Each key in the structure is associated with a field in the database.
See Structure in DataMgr for more information.
Note that all of these methods will also automatically convert special MS-Word characters to standard HTML.
insertRecord
The "insertRecord method typically inserts a new record into the database table. It takes the following arguments:
- tablename (string, required): The name of the table to which data should be saved.
- data (struct, required): The data to save.
- OnExists (string, insert): Describes how to handle data that matches an existing record (see below).
- fieldlist (string, optional): A list of insertable fields. If left blank, any field can be inserted.
- truncate (boolean, default=false): If true, automatically calls truncate() on data.
Here are the possible values and effects of the "OnExists" argument
- insert: DataMgr tries to insert the record anyway. (default)
- error: DataMgr throws an error
- update: DataMgr updates the existing record (saveRecord calls insertRecord with this argument)
- skip: DataMgr performs no action
- save: DataMgr updates the record only if it is given matching values for the primary key field(s), otherwise it inserts a new record.
updateRecord
The "updateRecord" method updates and existing record in the database table. It takes the following arguments:
- tablename (string, required): The name of the table to which data should be saved.
- data (struct, required): The data to save.
- advsql (struct): A structure of sqlarrays for each area of a query (SET,WHERE).
- truncate (boolean, default=false): If true, automatically calls truncate() on data.
- fieldlist (string, optional): A list of updateable fields. If left blank, any field can be updated.
saveRecord
The "saveRecord" method inserts or updates a record based on the incoming data. It does this by internally calling the "insertRecord" method with an "OnExists" argument of "update".
- tablename (string, required): The name of the table to which data should be saved.
- data (struct, required): The data to save.
- fieldlist (string, optional): A list of updateable fields. If left blank, any field can be updated.
- truncate (boolean, default=false): If true, automatically calls truncate() on data.