MvADD#
Adds a new record to the end of the specified database and positions the record pointer at that record. If NAME is omitted, the record is added to the primary database.
Syntax#
<MvADD NAME = "string: { expression } | literal"
VIEW = "string: { expression } | literal">
NAME
(optional): Alias of the database (as opened with<MvOPEN>
). Defaults to the primary database if omitted.
Attributes#
Attribute | Description |
---|---|
NAME |
(Optional) Database alias. Specifies which open database to add the record to. |
VIEW |
(Deprecated) ODBC support removed; do not use. |
Note
Fields in bold are required. Fields in italic are Deprecated.
Field Variable Assignment#
Before executing <MvADD>
, assign each field you wish to insert to a database variable of the form:
db_alias.d.fieldname
.d.
is the prefix denoting a database field.- Unassigned fields retain their current values (or null for a brand-new table).
Warning
The same set of field variables is used for both reading and writing records.
Any variable you do not explicitly assign will remain unchanged and will be written into the new record.
To avoid unintended data, always assign or clear all relevant fields before calling <MvADD>
.
Examples#
1. Inserting a New Record#
<MvOPEN NAME="worker_db"
DATABASE="dbs/workers.dbf"
INDEXES="work_name.mvx,work_sal.mvx">
<MvASSIGN NAME="worker_db.d.employee" VALUE="Walter Skinner">
<MvASSIGN NAME="worker_db.d.title" VALUE="Assistant Director">
<MvASSIGN NAME="worker_db.d.salary" VALUE="150000">
<MvADD NAME="worker_db">
<MvCLOSE NAME="worker_db">
Index files (work_name.mvx
, work_sal.mvx
) are automatically updated. Unassigned fields will be null.
2. Using the Primary Database#
Immediately after <MvOPEN>
, the opened database becomes primary. You can omit the alias when assigning fields:
<MvASSIGN NAME="d.employee" VALUE="Walter Skinner">
<MvASSIGN NAME="d.title" VALUE="Assistant Director">
<MvASSIGN NAME="d.salary" VALUE="150000">
<MvADD>
3. Copying and Clearing Fields#
If you load an existing record first, any fields you don’t clear will carry over into the new record:
<MvGO NAME="worker_db" ROW="TOP">
<MvASSIGN NAME="d.employee" VALUE="Fox Mulder">
<MvASSIGN NAME="d.title" VALUE="">
<MvASSIGN NAME="d.salary" VALUE="">
<MvASSIGN NAME="d.started" VALUE="">
<MvADD>
Working with Date Fields#
Assigning YYYYMMDD
#
For fields defined as dates, assign an 8-digit number:
<MvASSIGN NAME="worker_db.d.started" VALUE="{ '19990102' }"> <!-- January 2 1999 -->
<MvADD NAME="worker_db">
Storing Unix time_t
#
To capture both date and time, store a Unix timestamp using mktime_t()
or system variables:
<MvCOMMENT>Specific date/time</MvCOMMENT>
<MvASSIGN NAME="worker_db.d.started"
VALUE="{ mktime_t(9999,12,02,08,15,00,timezone()) }">
<MvADD NAME="worker_db">
<MvCOMMENT>Current server time</MvCOMMENT>
<MvASSIGN NAME="worker_db.d.started" VALUE="{ s.time_t }">
<MvADD NAME="worker_db">