Sunday, 18 August 2013

How to take ScreenShot in QTP

Public Function ScreenShotError
Dim path_error_file
Error_file_Path=Pathfinder.Locate(”ABC”) & rnd & “.png”
ScreenShot=path_error_file
Browser(”Browser”).Page(”Page”).CaptureBitmap Error_file_Path,True
End Function
ScreenShotError

Type of Parameter in QTP

There are 4 type of parameter in QTP
1. Data table parameter
2. Action parameter
3. Test parameter
4. Environment parameter

Introduction of Column- and Table Constraints

If a constraint is defined within the create table command or added using the alter table command, the constraint is automatically enabled. A constraint can be disabled using the command
alter table disable constraint | primary key | unique[]
[cascade];
To disable a primary key, one must disable all foreign key constraints that depend on this primary key. The clause cascade automatically disables foreign key constraints that depend on the (disabled) primary key. Example: Disable the primary key of the table DEPT and disable the foreign key constraint in the table EMP:
alter table DEPT disable primary key cascade;
In order to enable an integrity constraint, the clause enable is used instead of disable. A constraint can only be enabled successfully if no tuple in the table violates the constraint. Otherwise an error message is displayed. Note that for enabling/disabling an integrity constraint it is important that you have named the constraints. In order to identify those tuples that violate an integrity constraint whose activation failed, one can use the clause exceptions into EXCEPTIONS with the alter table statement.
EXCEPTIONS is a table that stores information about violating tuples.3 Each tuple in this table is identified by the attribute ROWID. Every tuple in a database has a pseudo-column ROWID that is used to identify tuples. Besides the rowid, the name of the table, the table owner as well as the name of the violated constraint are stored.
Example: Assume we want to add an integrity constraint to our table EMP which requires that each manager must earn more than 4000:
alter table EMP add constraint manager sal
check(JOB != ’MANAGER’ or SAL >= 4000)
exceptions into EXCEPTIONS;
If the table EMP already contains tuples that violate the constraint, the constraint cannot be activated and information about violating tuples is automatically inserted into the table
EXCEPTIONS.
Detailed information about the violating tuples can be obtained by joining the tables EMP and EXCEPTIONS, based on the join attribute ROWID:
select EMP._, CONSTRAINT from EMP, EXCEPTIONS where EMP.ROWID = EXCEPTIONS.ROW ID;
Before this table can be used, it must be created using the SQL script utlexcept.sql which can be found in the directory $ORACLE HOME/rdbms/admin.
Tuples contained in the query result now can be modified (e.g., by increasing the salary of managers) such that adding the constraint can be performed successfully. Note that it is important to delete “old” violations from the relation EXCEPTIONS before it is used again. If a table is used as a reference of a foreign key, this table can only be dropped using the command
drop table cascade constraints;.
All other database objects that refer to this table remain in the database system, but they are not valid. Information about integrity constraints, their status (enabled, disabled) etc. is stored in the data dictionary, more precisely, in the tables USER CONSTRAINTS and USER CONS CONSTRAINTS.

Detail Introduction of Triggers

Triggers provide a procedural technique to specify and maintain integrity constraints.
Triggers even allow users to specify more complex integrity constraints since a trigger essentially is a PL/SQL procedure. Such a procedure is associated with a table and is automatically called by the database system whenever a certain modification (event) occurs on that table.
Modifications on a table may include insert, update, and delete operations.
Structure of Triggers
A trigger definition consists of the following (optional) components:
• trigger name create [or replace] trigger
• trigger time point before | after
• triggering event(s) insert or update [of ] or delete on
• trigger type (optional) for each row
• trigger restriction (only for for each row triggers !) when ()
• trigger body
The clause replace re-creates a previous trigger definition having the same . The name of a trigger can be chosen arbitrarily, but it is a good programming style to use a trigger name that reflects the table and the event(s), e.g., upd ins EMP. A trigger can be invoked before or after the triggering event. The triggering event specifies before (after) which operations on the table the trigger is executed. A single event is an insert, an update, or a delete; events can be combined using the logical connective or. If for an update trigger no columns are specified, the trigger is executed after (before) is updated. If the trigger should only be executed when certain columns are updated, these columns must be
specified after the event update. If a trigger is used to maintain an integrity constraint, the triggering events typically correspond to the operations that can violate the integrity constraint.
it is essential to understand the difference between a row level trigger and a statement level trigger. A row level trigger is defined using the clause for each row. If this clause is not given, the trigger is assumed to be a statement trigger. A row trigger executes once for each row after (before) the event. A statement trigger is executed once after (before) the event, independent of how many rows are affected by the event. For example, a row trigger with the event specification after update is executed once for each row affected by the update. Thus, if the update affects 20 tuples, the trigger is executed 20 times, for each row at a time. In contrast, a statement trigger is only executed once. When combining the different types of triggers, there are twelve possible trigger configurations that can be defined for a table:
trigger time point trigger type event before after statement row
insert X X X X
update X X X X
delete X X X X
Row triggers have some special features that are not provided by statement triggers:
Only with a row trigger it is possible to access the attribute values of a tuple before and after the modification (because the trigger is executed once for each tuple). For an update trigger, the old attribute value can be accessed using :o ld. and the new attribute value can be accessed using :new.. For an insert trigger, only :new. can be used, and for a delete trigger only :o ld. can be used (because there exists no old, respectively, new value of the tuple). In these cases, :new. refers to the attribute value of of the inserted tuple, and :o ld. refers to the attribute value of of the deleted tuple. In a row trigger thus it is possible to specify comparisons between old and new attribute values in the PL/SQL block, e.g., “if :old.SAL < :new.SAL then . . . ”. If for a row trigger the trigger time point before is specified, it is even possible to
modify the new values of the row, e.g., :new.SAL := :new.SAL _ 1.05 or :new.SAL := :o ld.SAL.
Such modifications are not possible with after row triggers. In general, it is advisable to use a after row trigger if the new row is not modified in the PL/SQL block. Oracle then can process these triggers more efficiently. Statement level triggers are in general only used in combination with the trigger time point after.
In a trigger definition the when clause can only be used in combination with a for each row trigger. The clause is used to further restrict when the trigger is executed. For the specification of the condition in the when clause, the same restrictions as for the check clause hold. The only exceptions are that the functions sysdate and user can be used, and that it is possible to refer to the old/new attribute values of the actual row. In the latter case, the colon “:” must not be used, i.e., only old. and new..
The trigger body consists of a PL/SQL block. All SQL and PL/SQL commands except the two statements commit and rollback can be used in a trigger’s PL/SQL block.
if constructs allow to execute certain parts of the PL/SQL block depending on the
triggering event. For this, the three constructs if inserting, if updating[(’’)], and
if deleting exist. They can be used as shown in the following example:
create or replace trigger emp check after insert or delete or update on EMP
for each row begin
if inserting then
end if ;
if updating then
end if ;
if deleting then
end if ;
end;
It is important to understand that the execution of a trigger’s PL/SQL block builds a part of the transaction that contains the triggering event. Thus, for example, an insert statement in a PL/SQL block can cause another trigger to be executed. Multiple triggers and modifications thus can lead to a cascading execution of triggers. Such a sequence of triggers terminates successfully if (1) no exception is raised within a PL/SQL block, and (2) no declaratively specified integrity constraint is violated. If a trigger raises an exception in a PL/SQL block, all modifications up to the beginning of the transaction are rolled back. In the PL/SQL block of a trigger, an exception can be raised using the statement raise application error. This statement causes an implicit rollback. In combination with a row trigger, raise application error can refer to old/new values of modified rows:
raise application error(−20020, ’Salary increase from ’ || to char(:old.SAL) || ’ to ’
to char(:new.SAL) || ’ is too high’); or
raise application error(−20030, ’Employee Id ’ || to char(:new .EMPNO) || ’ does not exist.’);

Example of Triggers

Suppose we have to maintain the following integrity constraint: “The salary of an employee different from the president cannot be decreased and must also not be increased more than 10%. Furthermore, depending on the job title, each salary must lie within a certain salary range.
We assume a table SALGRADE that stores the minimum (MINSAL) and maximum (MAXSAL) salary for each job title (JOB).
Since the above condition can be checked for each employee individually,
we define the following row trigger:
trig1.sql
create or replace trigger check salary EMP after insert or update of SAL, JOB on EMP
for each row when (new.JOB != ’PRESIDENT’) – – trigger restriction
declare minsal, maxsal SALGRADE.MAXSAL%TYPE;
begin
– – retrieve minimum and maximum salary for JOB
select MINSAL, MAXSAL into minsal, maxsal from SALGRADE where JOB = :new.JOB;
– – If the new salary has been decreased or does not lie within the salary range,
– – raise an exception
if (:new.SAL maxsal) then raise application error(-20225, ’Salary range exceeded’);
elsif (:new.SAL 1.1 _ :o ld.SAL) then
raise application error(-20235, ’More than 10% salary increase’);
end if ;
end;
We use an after trigger because the inserted or updated row is not changed within the PL/SQL block (e.g., in case of a constraint violation, it would be possible to restore the old attribute values). Note that also modifications on the table SALGRADE can cause a constraint violation. In order to maintain the complete condition we define the following trigger on the table SALGRADE. In case of a violation by an update modification, however, we do not raise an exception, but restore the old attribute values.
trig2.sql
create or replace trigger check salary SALGRADE before update or delete on SALGRADE for each row when (new.MINSAL > old.MINSAL
or new.MAXSAL ALLSAL then
raise application error(-20325, ’Total of salaries in the department ’ || to char(DNO) || ’ exceeds budget’);
end if ;
end loop;
close DEPT CUR;
end;
In this case we use a statement trigger on the relation EMP because we have to apply an aggregate function on the salary of all employees that work in a particular department. For the relation DEPT, we also have to define a trigger which, however, can be formulated as a row trigger.