The DECLARE_VARIABLE clause lets you declare a host language
variable by referring to a field associated with a database
relation. The variable inherits the data type and size
attributes associated with the field. See the BASED ON clause
for information on declaring program functions: Pascal TYPE(s),
and C typedef(s).
The DECLARE_VARIABLE and DEFINE_TYPE clauses have exactly the
same function. Oracle Rdb decided to rename the clause to clarify
that its function is to declare host language variables, not to
define host language types. Note that the DEFINE_TYPE clause
may still be used; however, Rdb recommends that all new
applications use the DECLARE_VARIABLE clause in place of the
DEFINE_TYPE clause.
1 – Examples
The following programs demonstrate the use of the
DECLARE_VARIABLE clause to declare a program variable. These
programs:
o Declare the variable, badge, to have the same data type and
size attributes as EMPLOYEE_ID in the EMPLOYEES relation.
o Use this variable for interactive processing. Note that the
interactive portion of the programs appear before the READY
statement. This keeps locks on the database to a minimum.
o Select the record from the EMPLOYEES relation that has the
same value for EMPLOYEE_ID as is stored in badge.
o Modify the STATUS_CODE field of this record
Note that the C program uses the read_string function to prompt
for and receive a value for badge. For more information on this
function see Appendix B of the "RDML Reference Manual".
1.1 – C Example
#include <stdio.h>
DATABASE PERS = FILENAME "PERSONNEL";
extern void read_string();
static DECLARE_VARIABLE badge SAME AS EMPLOYEES.EMPLOYEE_ID;
main()
{
read_string ("Employee ID: ", badge, sizeof(badge));
READY PERS;
START_TRANSACTION READ_WRITE;
FOR E IN EMPLOYEES WITH E.EMPLOYEE_ID = badge
MODIFY E USING
strcpy(E.STATUS_CODE,"1");
END_MODIFY;
END_FOR;
ROLLBACK;
FINISH;
}
1.2 – Pascal Example
program modify_with_host (input,output);
DATABASE PERS = FILENAME 'PERSONNEL';
var
DECLARE_VARIABLE badge SAME AS EMPLOYEES.EMPLOYEE_ID;
begin
write ('Employee ID: ');
readln (badge);
READY PERS;
START_TRANSACTION READ_WRITE;
FOR E IN EMPLOYEES WITH E.EMPLOYEE_ID = badge
MODIFY E USING
E.STATUS_CODE := '1';
END_MODIFY;
END_FOR;
ROLLBACK;
FINISH;
end.
2 – Format
(B)0[m[4mDECLARE_VARIABLE [m qqqqqqqqqqqqqqqqqq> host-variable qqqk
x
lqqqqqqqqqqqqqqqqqqqqqqqqqqq<qqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
mqqwqq>qqqqqqqwqq> [4mAS[m qqwqq>qqqqqqqqqqqqqqqqqqqwqqk
mqq> SAME qj mqq> db-handle qq> . qqj x
x
lqqqqqqqqqqqqqqqqqqqq<qqqqqqqqqqqqqqqqqqqqqqqqqqqj
mqqqqqqqqqqqq> relation-name qqq> . qqq> field-name qqq>
2.1 – Format arguments
host-variable A valid host language variable.
db-handle Database handle. A host variable used
to refer to a specific database you have
invoked. For more information see the
entry on the Database Handle clause.
relation-name The name of a relation in the database.
field-name The name of a field in a relation. For
example, once you have defined E as
the context variable for the EMPLOYEES
relation, E.LAST_NAME is a value
expression that refers to a value from
the LAST_NAME field of EMPLOYEES.