The online community for software testing & quality assurance professionals
 
 
Calendar   Today's Topics
Sponsors:
Lost Password?

Home
BetaSoft
Blogs
Jobs
Training
News
Links
Downloads



Testing Tools >> HP Functional Testing / Mercury QuickTest Pro / QTP

Pages: 1
ohman
Member


Reged: 10/27/10
Posts: 41
QTP SQL related problem
      #701165 - 03/12/12 01:43 PM

I have been able to connect to SQL database using QTP and QTP is able to read results of query as well. However, one test case checks to see that query should not return any value at all. In this case, only column name of SQL table displays but no value is return at all. So, how do I tell QTP that if no value is returned then test case passes??


Dim con, rs

'OPEN DATABASE CONNECTION
set con=createobject("ADODB.Connection")
set rs=createobject("ADODB.Recordset")
con.Provider = "sqloledb"
con.Open("Server=SDRQA;Database=SDR;Trusted_Connection=yes")
'WRITE QUERY
'THIS QUERY RETURNS NO VALUE AT ALL
rs.open "SELECT DISTINCT GroupProgramID FROM GroupProgramLinkage (NOLOCK) EXCEPT SELECT DISTINCT GroupProgramID FROM GroupProgram (NOLOCK)" , con

Dim a
'I AM STORING VALUE IN a
Set a = rs.fields("0")

Problems:
(1) When I write "print a", QTP fails.
(2) When I write if a = " " QTP fails.
(3) When I write if a = NULL QTP fails.

so how do I tell QTP that if query don't return any value at all, then its a PASS test case??


Post Extras: Print Post   Remind Me!   Notify Moderator  
AnshooArora
Advanced Member


Reged: 10/27/07
Posts: 612
Loc: New Delhi, India
Re: QTP SQL related problem [Re: ohman]
      #701167 - 03/12/12 01:49 PM

Its because you cannot directly print an "object". You need to print the output of its method.

try:

print a.name
print a.value

--------------------
Regards,

Anshoo Arora
[AdvancedQTP] [LinkedIn] [Relevant Codes]



Post Extras: Print Post   Remind Me!   Notify Moderator  
Tarun LalwaniModerator
Veteran


Reged: 07/21/05
Posts: 15329
Loc: Milwaukee, Wisconsin
Re: QTP SQL related problem [Re: AnshooArora]
      #701171 - 03/12/12 05:01 PM

Few issue. Its not "0" it is 0

You should use

a = rs.fields(0)

Also do away with the Set operator, else you will get the field object

--------------------
Regards,
Tarun
** First ever technical novel - And I thought I knew QTP! **
** Download QTP Unplugged 2nd Edition eBook for FREE **

KnowledgeInbox RSS


Post Extras: Print Post   Remind Me!   Notify Moderator  
ohman
Member


Reged: 10/27/10
Posts: 41
Re: QTP SQL related problem [Re: Tarun Lalwani]
      #701221 - 03/13/12 06:51 AM Attachment (54 downloads)

I am attaching screenshot of SQL query here. When I run above mention code, I receive following error message from QTP...

Code:
Dim con, rs

'OPEN DATABASE CONNECTION
set con=createobject("ADODB.Connection")
set rs=createobject("ADODB.Recordset")
con.Provider = "sqloledb"
con.Open("Server=SDRQA;Database=SDR;Trusted_Connection=yes")
'WRITE QUERY
'THIS QUERY RETURNS NO VALUE AT ALL
rs.open "SELECT DISTINCT GroupProgramID FROM GroupProgramLinkage (NOLOCK) EXCEPT SELECT DISTINCT GroupProgramID FROM GroupProgram (NOLOCK)" , con

Set a = rs.fields(0)
print a.Value

at print a.Value line, I am getting this error message from QTP:

Run Error: Either BOF or EOF is True, or the record has been deleted. Requested operation requires a current record.

Basically, QTP throws error message since there isn't any record. But, what do I write to check whethere no record is returns at all??


Post Extras: Print Post   Remind Me!   Notify Moderator  
Rajkumar_RajangamModerator
Veteran


Reged: 10/22/10
Posts: 3136
Loc: Norway
Re: QTP SQL related problem [Re: ohman]
      #701252 - 03/13/12 09:51 AM

If Not rs.EOF Then
Set a = rs.fields(0)
print a.Value
Else
'Report no records found
End If

--------------------
Rajkumar


Post Extras: Print Post   Remind Me!   Notify Moderator  
ohman
Member


Reged: 10/27/10
Posts: 41
Re: QTP SQL related problem [Re: Rajkumar_Rajangam]
      #701255 - 03/13/12 10:30 AM

Thank you Mr.Raj. Appreicate it!!

Post Extras: Print Post   Remind Me!   Notify Moderator  
AnemUday
Member


Reged: 01/18/08
Posts: 226
Re: QTP SQL related problem [Re: ohman]
      #701262 - 03/13/12 12:08 PM

If you are sure that the query returns a single value, no need of verifying the EOF.

And just add to the Raj's reply, u can directly get the value like below:
print rs.fields(0).value

0r

print rs.fields("give your columnname").value

Or

print rs.fields.Item("give your columnname").value

--------------------
For more tips and resources visit my below blogs:
http://qtpftvideos.blogspot.in/
http://hpsqtp.blogspot.com/

Edited by AnemUday (03/13/12 12:12 PM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 49 anonymous users are browsing this forum.

Moderator:  IanFraser, Rajkumar_Rajangam, thorwath, TReddy, AJ, Tarun Lalwani, mwsrosso 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 1737

Rate this topic

Jump to

Contact Us | Privacy statement SQAForums

Powered by UBB.threads™ 6.5.5