Saturday, June 21, 2014

UFT 12 Introduction

UFT provides a unified solution to test your application,combining the ability to test the user interface of your application and the non GUI sections of your application.

We can create a test of your application from start to finish,or you can test sections of it through the creation of individual actions or components to test each process in your application or application sections.

 UFT also works with ALM,we can save the tests,components,function libraries and application areas with your ALM project and make them available to multiple users and testing projects.

UFT Main Window overview:

By default when we open UFT we will get a window like this

Here

if you are unable to find the start page just go through View-->Startpage

Recent Tests/Components:

Enables us to create a test or component or solution by clicking new button  or you can open the existing test by clicking on open button by selecting the project or solution.

Options:

Here we can select "Display the start page on Startup" to display the start page immediately when the UFT launch,we can select the "Close start page after the test loads" if you want to close the start page after loading a test.

Whats new Area:

Click on what's new button to display information on the list of the newest features,enhancements and supported environments in the latest version of UFT.

Community:

Click the community button to open the news about UFT, links to UFT in HP software site and links to the GUI/API/BPT testing forums or the UFT blog.


Links Area:

Click on links button to open links to the UFT help,the HP UFT Object model referencing for GUI testing and tutorials for GUI and API testing.

Support Area:

 click on support button to open the links to UFT support,the knowledge base and trouble shooting areas of the Hp software support web site.








Thursday, June 19, 2014

Security in SQL Server

A login is a security principal, or an entity that can be authenticated by a secure system. Users need a login to connect to SQL Server

As a security principal, permissions can be granted to logins. The scope of a login is the whole Database Engine. To connect to a specific database on the instance of SQL Server, a login must be mapped to a database user. Permissions inside the database are granted and denied to the database user, not the login. Permissions that have the scope of the whole instance of SQL Server can be granted to a login.


To create a SQL Server login Using SQl Server Management studio:

  1. In Object Explorer, expand the folder of the server instance in which you want to create the new login.
  2. Right-click the Security folder, point to New, and select Login….
  3. In the Login – New dialog box, on the General page, enter the name of a user in the Login name box. Alternately, click Search… to open the Select User or Group dialog box.
    If you click Search…:
    1. Under Select this object type, click Object Types… to open the Object Types dialog box and select any or all of the following: Built-in security principals, Groups, and Users. Built-in security principals and Users are selected by default. When finished, click OK.
    2. Under From this location, click Locations… to open the Locations dialog box and select one of the available server locations. When finished, click OK.
    3. Under Enter the object name to select (examples), enter the user or group name that you want to find. For more information, see Select Users, Computers, or Groups Dialog Box.
    4. Click Advanced… for more advanced search options. For more information, see Select Users, Computers, or Groups Dialog Box - Advanced Page.
    5. Click OK.
  4. To create a login based on a Windows principal, select Windows authentication. This is the default selection.
  5. To create a login that is saved on a SQL Server database, select SQL Server authentication.
    1. In the Password box, enter a password for the new user. Enter that password again into the Confirm Password box.
    2. When changing an existing password, select Specify old password, and then type the old password in the Old password box.
    3. To enforce password policy options for complexity and enforcement, select Enforce password policy. For more information, see Password Policy. This is a default option when SQL Server authentication is selected.
    4. To enforce password policy options for expiration, select Enforce password expiration. Enforce password policy must be selected to enable this checkbox. This is a default option when SQL Server authentication is selected.
    5. To force the user to create a new password after the first time the login is used, select User must change password at next login. Enforce password expiration must be selected to enable this checkbox. This is a default option when SQL Server authentication is selected.
  6. To associate the login with a stand-alone security certificate, select Mapped to certificate and then select the name of an existing certificate from the list.
  7. To associate the login with a stand-alone asymmetric key, select Mapped to asymmetric key to, and then select the name of an existing key from the list.
  8. To associate the login with a security credential, select the Mapped to Credential check box, and then either select an existing credential from the list or click Add to create a new credential. To remove a mapping to a security credential from the login, select the credential from Mapped Credentials and click Remove. For more information about credentials in general, see Credentials (Database Engine).
  9. From the Default database list, select a default database for the login. Master is the default for this option.
  10. From the Default language list, select a default language for the login.
  11. Click OK.

Sunday, June 15, 2014

Exception Handling in SQL Server


STRUCTURED EXCEPTION HANDLING:

   
    In SQL Server 2005 exception handling is carried out using Strucuted Exception, which supports to write 2 blocks.

1. TRY : It is used to monitor all those instructions in which run time errors are expected
2. CATCH : It is used to catch the thrown exceptions. This block is executed only when a exception is raised.

Syntax:

    BEGIN TRY
        statements
    END TRY
    BEGIN CATCH
        statements
    END CATCH

Note:  Following are the functions is used to display information about errors.

   
ERROR_NUMBER()      -returns the number of the error.
ERROR_STATE()      -returns the error state number.
ERROR_PROCEDURE()- returns the name of the stored procedure or trigger where the error occurred.
ERROR_LINE()      - returns the line number inside the routine that caused the error.
ERROR_MESSAGE()  - returns the complete text of the error message.

Example 1:
   
DECLARE @A INT,@B INT,@C INT
SET @A=5
SET @B=0
BEGIN TRY
   SET @C=@A/@B
   PRINT 'QUOTIENT IS.....'+CAST(@C AS VARCHAR(5))
END TRY
BEGIN CATCH
   PRINT 'CANT DIVIDE THE NUMBER BY 0'
   PRINT ERROR_NUMBER()
   PRINT ERROR_LINE()
   PRINT ERROR_MESSAGE()
   PRINT ERROR_STATE()
END CATCH
PRINT 'THANX'

EXAMPLE 2:

CREATE PROCEDURE PROC3
AS
SELECT * FROM EMP3

BEGIN TRY
     EXECUTE PROC3
END TRY

BEGIN CATCH
     SELECT
          ERROR_NUMBER() as ErrorNumber,
          ERROR_MESSAGE() as ErrorMessage;
END CATCH

Thanks
GSV

Tuesday, June 10, 2014

Data types in SQL Server



Data Types In SQL Server


Category
Data Type
Bytes
Rannge
Integer
Tiny int
1
0 To 255

Small int
2
-32768 To 32767

Int
4
-2147483648 To 2147483647

Big int
8
-263 To 263 – 1
Float
Decimal(P,S)
5 to 17
Decimal(7,2) will allow a total of 7 digits where 2 digits will be after the decimal point. (ex : 12345.67)

Float(P)
If P<25  4 Bytes
If P>=25 8 Bytes


Small Money
4 Byte Decimal


Money
8 Byte Decimal

Character
Char (n)

Fixed Length Char Data and n can be up to maximum 8000

Varchar(n)

Variable Length Char Data And n Can be up to maximum 8000

NChar(n)
a Unicode character will occupy 2 bytes in memory
Fixed Length Unicode char data and n can be up to maximum 4000.

Nvarchar(n)

Variable Length Unicode char data and n can be up to maximum 4000.

Text(n)
n can be up to maximum 2GB
Variable length char Data

Ntext(n)
N can be up to maximum 230 – 1
Variable length Unicode char data
Binary
Binary(n)
N can be up to maximum 8000
Fixed length binary data

VarBinary(n)
N can be up to maximum 8000
Variable Length Binary Data

Image(n)
N can be up to maximum 231 – 1
Variable Length Binary data

Bit
1
True/False/NULL
Large Objects
Varchar(Max)
231 – 1
Variable Length Char Data

NVarchar(Max)
231 – 1
Variable Length Unicode Char Data

VarBinary(Max)
231 – 1
Variable Length Binary Data
DateTime
SmallDatetime
2
Jan 1st 1900 to june 6th 2079

DateTime
4
Jan 1st 1753 to Dec 31st 9999
Miscellaneous
SQL_variant
Size varies
Can Store any Type of Data

Table
Size varies
Can Store a Table

XML
Size Varies
Can store XML documents

Thanks
GSV

Sunday, June 8, 2014

Triggers in SQL Server

Database Trigger:

Database trigger is a stored procedure that is fired when an insert,update or delete statement is issued against the associated table.

uses:
1.To generate data automatically.
2.To enforce complex integrity constraints(checking with sysdate,checking with data in another table)
3.To customize complex security authorization
4.To maintain replicate tables.
5.To audit data modification

    bank_master 
accno    balance
1001    5000
1002    20000
1003    25000
1004    40000
1005    55230

    bank_transaction
cname    accno    ttype    amount
xxx         1003    db        5000
yyy         1005    cr         5230
zzz          1001    db        5000
zzz          1001    db        15000

syntax for creating a trigger:

create/alter trigger <trigger_name>
on <tablename>
after/instead of/for insert,update,delete
as
begin
statements
end

CREATE TRIGGER T11
ON BANK_TRANSACTION
AFTER INSERT
AS
BEGIN
DECLARE C1 CURSOR FOR SELECT * FROM BANK_TRANSACTION
DECLARE @CNAME VARCHAR(20),@ACCNO INT,@TTYPE VARCHAR(2),@AMOUNT INT
OPEN C1
FETCH NEXT FROM C1 INTO @CNAME,@ACCNO,@TTYPE,@AMOUNT --START THE LOOP
WHILE(@@FETCH_STATUS=0)
BEGIN
FETCH NEXT FROM C1 INTO @CNAME,@ACCNO,@TTYPE,@AMOUNT -- CONTINUE THE LOOP
END
IF @TTYPE='CR'
UPDATE bank_MASTER SET BALANCE=BALANCE +@AMOUNT WHERE ACCNO=@ACCNO
ELSE
UPDATE bank_MASTER SET BALANCE=BALANCE -@AMOUNT WHERE ACCNO=@ACCNO
CLOSE C1
DEALLOCATE C1
END

create trigger t5
on student
after insert
as
begin
DECLARE C1 CURSOR
FOR SELECT SNO,S1,S2,S3 FROM STUDENT
DECLARE @SNO INT,@S1 INT,@S2 INT,@S3 INT
DECLARE @STOT INT ,@SAVG INT
DECLARE @SRES VARCHAR(4)

OPEN C1

FETCH NEXT FROM C1 INTO @SNO,@S1,@S2,@S3
WHILE (@@FETCH_STATUS=0)
BEGIN
SET @STOT=@S1+@S2+@S3
SET @SAVG=CEILING((@STOT)/3)
IF @S1 >35 AND @S2 >35 AND @S3 > 35
SET @SRES='PASS'
ELSE
SET @SRES='FAIL'
INSERT INTO RESULT VALUES(@SNO,@STOT,@SAVG,@SRES);
FETCH NEXT FROM C1 INTO @SNO,@S1,@S2,@S3
END
CLOSE C1
DEALLOCATE C1
end

 create a trigger tr1 for INSERT,DELETE triggering event where trigger should be fired if the transactions are performed on SUNDAY?
CREATE TRIGGER tr1
ON bank_master
FOR INSERT,DELETE
AS
BEGIN
  IF DATENAME(DW,GETDATE())='Sunday'
  BEGIN
    ROLLBACK
    RAISERROR('CANT INSERT OR DELETE THE DATA ON SUNDAY',1,1)
  END
END

Create a trigger tr2 For INSERT,DELETE Triggering event where trigger should be fired if the transaction
is performed before 10AM and After 5PM?


CREATE TRIGGER tr2
ON bank_master
FOR INSERT,DELETE
AS
BEGIN
    IF DATEPART(HH,GETDATE()) not in(10,11,12,13,14,15,16,17)
    BEGIN
        ROLLBACK
        RAISERROR('INVALID TIME',1,1)
    END
END

CREATE TRIGGER T1 ON EMP AFTER INSERT,UPDATE,DELETE
AS
BEGIN
IF DATEPART(DW,GETDATE())=1
BEGIN
ROLLBACK
RAISERROR('SUNDAY NOT ALLOWED' ,15,1)
END
END

CREATE TRIGGER T2 ON EMP
AFTER INSERT,UPDATE,DELETE
AS BEGIN
IF DATEPART(HH,GETDATE() )< 10
BEGIN
ROLLBACK
RAISERROR('INVALID TIME',15,1)
END
END

CREATE a trigger tr4 for DELETE triggering event on DEPT table,where trigger should be fired by deleting the records from emp table?

CREATE TRIGGER TR7
ON DEPT
FOR DELETE
AS
BEGIN
    DELETE FROM EMP WHERE DEPTNO IN(SELECT DEPTNO FROM DELETED)
    PRINT CAST((@@ROWCOUNT AS VARCHAR(5))+ 'ROWS ARE DELETED'
END

Difference between procedures and Triggers:


procedures                                             Triggers

1.called Explicitly                                   1.called implicitly
2.can be created without a table.            2.can't be created without a table.
3.it accepts parameters                          3.it won't accept parameters
4.it returns a value                                 4.it won't return a value.

VIRTUAL TABLES (MAGIC TABLES)

    SQL SERVER provides 2 virtual tables which can be used only in triggers. These tables are provided by TempDB(System database).These tables play major role to have backup of data.

Tables are Identified as INSERTED , DELETED

INSERTED :
    This table will store the same data which is provided in target table(user defined table).   
    If a record is inserted into a target table then the same record is available in this virtual table

Data avaiable in this table can be used to perform operations and can be again stored into the other
 user defined tables.
    If the record is updated in a target table, new value is stored in this magic table and old value is transfered to DELETED Table.

DELETED :

    This magic table stores the removed rows from a target table.It also stores the old value when update operation is performed over a target table.
   
note:
These tables will store the data for temporary.
These tables can be used at once in a single trigger.

INSTEADOF TRIGGERS:

    These triggers is used to make the modifications into base table thru a complex view.(Non updateable view)

    By default a complex view is not updatable view (i.e. read only view). A complex view consists of joins,mathematical expressions, group by clause, group functions, distinct operator.

examples:


create a complex view on emp table that stores a query for empno,sal and annual salary?

CREATE VIEW V1
AS
SELECT EMPNO,SAL M_SAL,SAL*12 A_SAL FROM EMP

CREATE TRIGGER tr6
ON v1
INSTEAD OF INSERT
AS
BEGIN
   INSERT EMP(EMPNO,SAL) SELECT EMPNO,M_SAL FROM INSERTED
end

create a database trigger do not allow to enter more than four employees in a emp4 table.
create trigger tr1 on
emp4
instead of insert
as
begin
declare @cnt int
declare @ename varchar(20),@eno int,@salary int,@deptno int
select @ename=ename,@eno=eno,@salary=salary,@deptno=deptno from
inserted
select @cnt=count(*) from emp4 where deptno=@deptno
if @cnt=4
raiserror('max 4 employees',15,1)
else
insert into emp4 values(@ename,@eno,@salary,@deptno)
end

select * from emp4

Create a trigger tr4 for DELETE triggering event on DEPT table, where trigger should be fired by deleting the records from emp table?
CREATE TRIGGER TR4
ON DEPT
FOR DELETE
AS
BEGIN
    SET NOCOUNT ON
    DELETE FROM EMP WHERE DEPTNO IN(SELECT DEPTNO FROM DELETED)
    PRINT CAST(@@ROWCOUNT AS VARCHAR(5))+' Rows Are Deleted'
END

Create a trigger for DDL triggering event that restricts the dropping and altering of a table in a database?

CREATE TRIGGER tr5
ON DATABASE
FOR DROP_TABLE,ALTER_TABLE
AS
BEGIN
   ROLLBACK
   RAISERROR('CANT ALTER OR DROP THE TABLES',15,16)
END

To display list of triggers created in a database:

* SELECT NAME FROM SYSOBJECTS WHERE XTYPE='TR'

* select * from sys.all_objects where type='tr'

VIEWING TRIGGER INFORMATION:

SP_HELPTEXT trigger_name

SP_HELPTEXT tr2

DISABLE / ENABLE THE TRIGGERS:

ALTER TABLE table_name
DISABLE/ENABLE TRIGGER trigger_name

DROPING A TRIGGER:


DROP TRIGGER trigger_name

Thanks
GSV