• No results found

DELETE Where Current of Cursor

In document Power Script References Unidad 3 (Page 182-186)

DELETE Where Current of Cursor

Description Deletes the row in which the cursor is positioned.

DBMS-specific

Not all DBMSs support DELETE Where Current of Cursor.

Syntax DELETE FROM TableName WHERE CURRENT OF CursorName;

Usage The USING TransactionObject clause is not allowed with this form of DELETE Where Current of Cursor; the transaction object was specified in the statement that declared the cursor.

Error handling

It is good practice to test the success/failure code after executing a DELETE Where Current of Cursor statement.

Examples This statement deletes from the Employee table the row in which the cursor named Emp_cur is positioned:

DELETE FROM Employee WHERE current of Emp_curs ;

DISCONNECT

Description Executes a COMMIT for the specified transaction object and then disconnects from the specified database.

Syntax DISCONNECT {USING TransactionObject};

Parameter Description

TableName The name of the table from which you want to delete a row

CursorName The name of the cursor in which the table was specified

Parameter Description

TransactionObject The name of the transaction object that identifies the database you want to disconnect from and in which you want to permanently update all database operations since the previous COMMIT, ROLLBACK, or CONNECT. This clause is required only for transaction objects other than

Usage Error handling

It is good practice to test the success/failure code after executing a DISCONNECT statement.

Examples Example 1 This statement disconnects from the database specified in the default transaction object:

DISCONNECT ;

Example 2 This statement disconnects from the database specified in the transaction object named Emp_tran:

DISCONNECT USING Emp_tran ;

EXECUTE

Description Executes the previously declared procedure identified by ProcedureName.

Syntax EXECUTE ProcedureName;

Usage The USING TransactionObject clause is not allowed with EXECUTE; the transaction object was specified in the statement that declared the procedure.

Error handling

It is good practice to test the success/failure code after executing an EXECUTE statement.

Examples This statement executes the stored procedure Emp_proc:

EXECUTE Emp_proc ;

Parameter Description

ProcedureName The name assigned in the DECLARE statement of the stored procedure you want to execute. The procedure must have been declared previously. ProcedureName is not necessarily the name of the procedure stored in the database.

FETCH

FETCH

Description Fetches the row after the row on which Cursor | Procedure is positioned.

Syntax FETCH Cursor | Procedure INTO HostVariableList;

Usage The USING TransactionObject clause is not allowed with FETCH; the transaction object was specified in the statement that declared the cursor or procedure.

If your DBMS supports formats of FETCH other than the customary (and default) FETCH NEXT, you can specify FETCH FIRST, FETCH PRIOR, or FETCH LAST.

Error handling

It is good practice to test the success/failure code after executing a FETCH statement. To see if the FETCH was successful, you can test SLQCode for a failure code. However, if nothing matches the WHERE clause and no rows are fetched, SQLCode is still set to 100. To make sure the fetch affected at least one row, check the SQLNRows property of the transaction object.

Examples Example 1 This statement fetches data retrieved by the SELECT clause in the declaration of the cursor named Emp_cur and puts it into Emp_num and Emp_name:

int Emp_num string Emp_name

FETCH Emp_cur INTO :Emp_num, :Emp_name ;

Example 2 If sle_emp_num and sle_emp_name are SingleLineEdits, these statements fetch from the cursor named Emp_cur, store the data in Emp_num and Emp_name, and then convert Emp_num from an integer to a string, and put them in sle_emp_num and sle_emp_name:

int Emp_num string Emp_name

FETCH Emp_cur INTO :emp_num, :emp_name ; sle_emp_num.Text = string(Emp_num) Parameter Description

Cursor or Procedure The name of the cursor or procedure from which you want to fetch a row

HostVariableList PowerScript variables into which data values will be retrieved

INSERT

Description Inserts one or more new rows into the table specified in RestOfInsertStatement.

Syntax INSERT RestOfInsertStatement {USING TransactionObject} ;

Usage Error handling

It is good practice to test the success/failure code after executing an INSERT statement.

Examples Example 1 These statements insert a row with the values in EmpNbr and EmpName into the Emp_nbr and Emp_name columns of the Employee table identified in the default transaction object:

int EmpNbr string EmpName ...

INSERT INTO Employee (employee.Emp_nbr, employee.Emp_name)

VALUES (:EmpNbr, :EmpName) ;

Example 2 These statements insert a row with the values entered in the SingleLineEdits sle_number and sle_name into the Emp_nbr and Emp_name columns of the Employee table in the transaction object named Emp_tran:

int EmpNbr string EmpName

EmpNbr = Integer(sle_number.Text) EmpName = sle_name.Text

INSERT INTO Employee (employee.Emp_nbr, employee.Emp_name)

VALUES (:EmpNbr, :EmpName) USING Emp_tran ;

Parameter Description

RestOfInsertStatement The rest of the INSERT statement (the INTO clause, list of columns and values or source).

TransactionObject The name of the transaction object that identifies the database containing the table. This clause is required only for transaction objects other than the default (SQLCA).

In document Power Script References Unidad 3 (Page 182-186)