Inserts a record into an existing relation. You can add a record to only one relation with a single STORE statement. The statements between the keywords STORE and END_STORE form a context block. You cannot store records into views defined by any of the following record selection expression (RSE) clauses: o WITH o CROSS o REDUCED o FIRST Trying to store into views that were defined with any of the above clauses could cause unexpected results in your database. You can use the GET statement within the bounds of the STORE ... END_STORE block. Note that any valid format of the GET statement is permitted within this block. You may find it particularly useful to use the GET statement to place the database key (dbkey) of the record you are storing into a host variable. Use the GET...RDB$DB_KEY construct to assign the value of the dbkey to the host variable.
1 – Examples
The following programs demonstrate the use of the STORE statement. The programs: o Prompt the user for information to store in the COLLEGES relation o Start a READ_WRITE transaction o Use a STORE statement to store the user input into the COLLEGES relation o Use the GET statement to store the value of the dbkey for the newly stored record into the host variable my_db_key. (Retrieving the dbkey is not a required part of the STORE statement syntax, but may be helpful in some applications.)
1.1 – C Example
DATABASE PERS = FILENAME "PERSONNEL"; extern void read_string(); static DEFINE_TYPE coll_code SAME AS COLLEGES.COLLEGE_CODE; static DEFINE_TYPE coll_name SAME AS COLLEGES.COLLEGE_NAME; static DEFINE_TYPE coll_city SAME AS COLLEGES.CITY; static DEFINE_TYPE coll_state SAME AS COLLEGES.STATE; static DEFINE_TYPE post_code SAME AS COLLEGES.POSTAL_CODE; static DEFINE_TYPE my_db_key SAME AS COLLEGES.RDB$DB_KEY; main() { read_string ("Enter College Code: ", coll_code, sizeof(coll_code)); read_string ("Enter College Name: ", coll_name, sizeof(coll_name)); read_string ("Enter College City: ", coll_city, sizeof(coll_city)); read_string ("Enter College State: ",coll_state, sizeof(coll_state)); read_string ("Enter Postal Code: ", post_code, sizeof(post_code)); READY PERS; START_TRANSACTION READ_WRITE; STORE C IN COLLEGES USING strcpy (C.COLLEGE_CODE, coll_code); strcpy (C.COLLEGE_NAME, coll_name); strcpy (C.CITY, coll_city); strcpy (C.STATE, coll_state); strcpy (C.POSTAL_CODE, post_code); GET my_db_key = C.RDB$DB_KEY; END_GET; END_STORE; COMMIT; FINISH; }
1.2 – Pascal Example
program store_with_host_lang (input,output); DATABASE PERS = FILENAME 'PERSONNEL'; var DECLARE_VARIABLE coll_code SAME AS COLLEGES.COLLEGE_CODE; DECLARE_VARIABLE coll_name SAME AS COLLEGES.COLLEGE_NAME; DECLARE_VARIABLE coll_city SAME AS COLLEGES.CITY; DECLARE_VARIABLE coll_state SAME AS COLLEGES.STATE; DECLARE_VARIABLE post_code SAME AS COLLEGES.POSTAL_CODE; DECLARE_VARIABLE my_db_key SAME AS COLLEGES.RDB$DB_KEY; begin writeln ('Enter College Code:'); readln (coll_code); writeln ('Enter College Name:'); readln (coll_name); writeln ('Enter College City:'); readln (coll_city); writeln ('Enter College State:'); readln (coll_state); writeln ('Enter College Postal Code:'); readln (post_code); READY PERS; START_TRANSACTION READ_WRITE; STORE C IN COLLEGES USING C.COLLEGE_CODE := coll_code; C.COLLEGE_NAME := coll_name; C.CITY := coll_city; C.STATE := coll_state; C.POSTAL_CODE := post_code; GET my_db_key = C.RDB$DB_KEY; END_GET; END_STORE; COMMIT; FINISH; end.
2 – Format
(B)0[mSTORE qqqqwqq>qqqqqqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk mqq> handle-options qj x x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq<qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj mqq> context-var qqq> [4mIN[m qqqqqqqqqqqqqqqqqqqqqqqqqqq>qqqqqqqqqqqk lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq<qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj mqqwq>qqqqqqqqqqqqqqqqqqwqq> relation-name qqqqq> USING qqqqqqqk mq> db-handle qq> . qj x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq<qqqqqqqqqqqqqqqqqqqqqqqqqqqj mqqwq>qqqqqqqqqqqwqqwq> statement qqqqqqqqqqqqqqqqqqqqqqqqqqqqwk mq> on-error qj tq> context-var.* qq> = qq> record-descr qux mqqqqqqqqqqqqqqqqqq <qqqqqqqqqqqqqqqqqqqqqqjx lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq<qqqqqqqqqqqqqqqqqqqqqqqqqqqj mqqqqqqqqwqqqqqqqqqqqqqqqqqqwqqqqqqqqqq> [4mEND_STORE[m mq> get-statement qj (B)0[mhandle-options = q> ( qwqqqqqq> [4mREQUEST_HANDLE[m qqqqq> var qqqqqqqqwq> ) q> tqqqqqq> [4mTRANSACTION_HANDLE[m qqq> var qqqqqqqqu mqqqqqq> [4mREQUEST_HANDLE[m q> var q> , qqqqqqqk x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x mqqqq> [4mTRANSACTION_HANDLE[m q> var qqqqqqqqqqqj (B)0[mget-statement = [4mGET[m qqwqqqq>qqqqqqqqwqqwq> get-item qqwqqqqq> [4mEND_GET[m qqq> mq> on-error qj mqqqqq ; <qqqqqqj (B)0[mget-item = qqqqwqq> host-var qqqqqqqq> = qqqqq> value-expr qqqqqqqqqqwqqqq> tqq> record-descr qqqq> = qqqqq> context-var.* qqqqqqqu mqq> host-var qqqqqqqq> = qqqqq> statistical-expr qqqqj
2.1 – Format arguments
handle-options A request handle, a transaction handle, or both. REQUEST_HANDLE var The REQUEST_HANDLE keyword followed by a host language variable. A request handle identifies a compiled Oracle Rdb request. If you do not supply a request handle explicitly, RDML associates a unique request handle for the compiled request. TRANSACTION_HANDLE The TRANSACTION_HANDLE keyword followed by var a host language variable. A transaction handle identifies a transaction. If you do not supply a transaction handle explicitly, RDML uses the default transaction handle. context-var A context variable. A temporary name that you associate with a relation. You define a context variable in a relation clause. For more information see the entry on Context Variables. 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. on-error The ON ERROR clause. The first occurrence specifies host language or RDML statement(s) to be performed if an error occurs during the STORE operation. The second occurrence specifies host language or RDML statement(s) to be performed if an error occurs during the GET operation. For more information see the entry on ON ERROR. statement Any valid RDML or host language statement, except the GET statement, to be executed during the STORE operation. Use a semicolon (;) at the end of each RDML, Pascal, or C statement. get-item The GET statement includes an assignment statement specifying a host variable and a database value. The database value is assigned to the host variable from the Oracle Rdb value expression or statistical expression. Note that the GET statement must be the last statement to appear before the END_STORE statement. host-var A valid variable name declared in the host program. value-expr A valid RDML value expression. The value expression can include the "<context- variable>.RDB$DB_KEY" expression. record-descr A valid host language record descriptor that contains an entry for each field in fields of the relation. Each field of the record descriptor must match exactly the field names and data types of the fields in the Oracle Rdb relation referenced by the context variable. statistical-expr A statistical expression; calculates values based on a value expression for every record in the record stream.