Sunday, April 21, 2013

SilkTest Database Operation



hdbc = DB_Connect (con_string)
Opens a connection to a database system and returns a handle to that system. This allows you to submit SQL statements to the database for execution.

hstmnt = DB_ExecuteSql (hdbc, sql_stmnt)
Sends an SQL statement to the specified database for execution.

status = DB_FetchPrev (hstmnt, ...)
Retrieves the previous row from the database. If the current row is the first row in the database, this function returns a status value of FALSE. If the returned status value is TRUE, the retrieved row becomes the current row.

status = DB_FetchNext (hstmnt, ...)
Retrieves the next row from the database. If this is the first DB_FetchNext call after DB_ExecuteSql, this function retrieves the first row. The retrieved row becomes the current row.

DB_FinishSql (hstmnt)
Removes the results of the SQL statement and releases the associated system resource (the statement handle).

DB_Disconnect (hdbc)
Disconnects SilkTest from the database system and releases all resources.

Example:.
hDBC = DB_Connect("DSN=Segue DDA Excel;DBQ=FileName.xls;UID=;PWD=;")
hStatement = DB_Columns(hDBC, NULL, NULL, "Suite$", csPERCENT)
hStatement = DB_ExecuteSql(hDBC, "Update [Suite$] SET { ColumnValue } = 'PASS' WHERE  TestID = '{ RowValue }'")
DB_FinishSQL(hStatement)
DB_Disconnect(hDBC)

Example:.
   testcase DBTest () appstate none
           INTEGER id, iheadID
           STRING sDeptName
           HDATABASE hdbc
           HSQL hstmnt
           // connect to SQL 2000 Server Test DB
           hdbc = DB_Connect ("dsn=SQLServer;PWD=sql;UID=dba")
           // retrieve info from Department table
           hstmnt = DB_ExecuteSql (hdbc, "SELECT * FROM department")
           // process the information that came back
           while (DB_FetchNext (hstmnt, id, sDeptName, iheadID))
              print ("Dept: {id}  Name: {sDeptName}  Head: {iheadID}")
           // release resources (unneeded really because immediately followed by disconnect)
           DB_FinishSQL (hstmnt)
           // disconnect
           DB_Disconnect (hdbc)


File Operation


hFile = FileOpen (sPath, fmMode [, fsShare[, ftType]])

bDidRead = FileReadLine (hFile, sLine)

FileWriteLine (hFile, sLine)

FileClose (hFile)



Example:
TestCase FileCreate ()
                    HANDLE hFile
                   
                    hFile = FileOpen ("c:\myfile.txt", FM_WRITE, NULL)
                    FileWriteLine (hFile, "This is a Test File line one.")
                    FileWriteLine(hFile, "This is line two.")
                    FileClose (hFile)
    // end of  TestCase
   


TestCase FileRead ()
                    HANDLE hFile
                    STRING sMyData
                    BOOL bDidRead
   
                    hFile = FileOpen ("c:\myfile.txt", FM_READ)
                    bDidRead = FileReadLine (hFile, sMyData)
                   
                    Print (sMyData)

FileClose (hFile)
       
       


No comments:

Post a Comment