3 Programming the DB Connection Function
3-15
NJ/NX-series Database Connection CPU Units User’s Manual (W527)
3
3-3 Creating a DB Map Variable
3-3-1 DB Map Variables and DB Mapping
3-3 Creating a DB Map Variable
After creating a user-defined structure data type for DB access, you create a variable using the
data type. The variable is called “DB Map Variable”.
This section describes the specifications and creation procedure of DB Map Variables.
3-3-1 DB Map Variables and DB Mapping
Each DB Map Variable uses a structure data type for DB access as its data type.
You create a mapping* for a DB Map Variable to the connected DB for each SQL type (i.e.,
INSERT, UPDATE, and SELECT) by executing a DB_CreateMapping (Create DB Map)
instruction.
After creating the DB mapping, you can execute each record processing for inserting, updating,
and retrieving records using the DB Map Variable by executing a DB_Insert (Insert DB Record),
DB_Update (Update DB Record), or DB_Select (Retrieve DB Record) instruction.
Structure data type for
DB access
DB
Map Variable
Var_Insert
DB Map Variable
Var_Update
DB Map Variable
Var_Select
By executing a
DB_CreateMapping (Create DB Map) instruction
Var_Update
can be used in
DB_Update (Update DB Record) instructions.
Var_Insert can be used in DB_Insert (Insert
DB Record) instructions.
Var_Select can be used in
DB_Select (Retrieve
DB Record) instruction
s.
* The DB mapping means to assign each member of a DB Map Variable to the corresponding column of
a table in the connected DB. You need to execute the DB mapping for each record processing for
inserting, updating, and retrieving records.
You can map more than one DB Map Variable for a DB Connection.
The following table shows the operation of each record processing (i.e., INSERT, UPDATE, and
SELECT) to be performed when you create a structure where not all, but some of the columns
are specified as members.
Inserting records (INSERT) The record values are written to the specified columns of the DB.
NULL is entered in the unspecified columns. You need to make a setting for allowing
Updating records (UPDATE) Values are updated only in the specified columns.
Values are not changed in the unspecified columns.
Retrieving records (SELECT) Values are retrieved only from the specified columns.
You need to specify only the columns that do not contain NULL.
Precautions for Correct Use
If you retrieve a record that includes a column of NULL value when executing a DB_Select
(Retrieve DB Record) instruction, the instruction will result in an instruction error (SQL
Execution Error).