Method Mysql.SqlTable()->insert()


Method insert

int insert(mapping(string:mixed) ... records)

Description

Inserts one or more records into the table using an INSERT command. An SQL error is thrown if a record conflicts with an existing one.

A record is represented as a mapping with one entry for each column or property (if prop_col is used). The values must be of the right type for the column: Integers for integer columns, floats for floating point columns, strings for all other data types, and Val.null for the SQL NULL value.

If the property feature is used (i.e. if prop_col is set) then any entries in the record mapping that don't match a column are treated as properties and are stored encoded in the prop_col column. Note that column names are matched with case sensitivity. Properties may store any pike data type (as long as it is accepted by encode_value_canonic).

If id_col is set and that column doesn't exist in a record mapping then the field is added to the mapping with the value that the record got. This currently only works for the first record mapping if there are several.

Returns

The value of the id_col column for the new record. If several records are inserted at once then the value for the first one is returned. Zero is returned if there is no id_col column.

See also

insert_ignore, replace, insert_or_update