Friday 20 November 2015

VBScript Data base function-Execute SQL query in UFT

Function uf_DB_ORA_ExecuteQuery(ByVal DSNName, User, Password, QueryText)
    Const adOpenStatic = 3
    Const adLockOptimistic = 3
    Const adUseClient = 3

    connectionString ="DSN=" & DSNName  & ";UID=" & User & ";PWD=" & Password

    Set objConnection = CreateObject("ADODB.Connection")
    Set objRecordSet = CreateObject("ADODB.RecordSet")
   
    objConnection.Open connectionString

    If Instr(1,UCase(QueryText),"UPDATE") > 0 OR Instr(1,UCase(QueryText),"DELETE") > 0 OR Instr(1,UCase(QueryText),"INSERT") > 0Then
        objConnection.Execute(QueryText)
        objConnection.Execute("Commit;")

        If Err.Number <> 0 Then rc = micFail Else rc = micPass
        uf_DB_ORA_ExecuteQuery = rc

    ElseIf Instr(1,UCase(QueryText),"SELECT") > 0 Then
        objRecordSet.Open QueryText, objConnection
        Set uf_DB_ORA_ExecuteQuery = objRecordSet
    End If

    Set objConnection=Nothing
    Set objRecordSet = Nothing
End Function


1 comment:

  1. I like your post there is a lot of information about software testing, which i would like to learn, thank you for the great guide. Very useful post and I think it is rather easy to see from the other comments as well that this post is well written and useful. I bookmarked this blog a while ago because of the useful content and I am never being disappointed. Keep up the good work.. Read more about QA Services

    ReplyDelete