Rational javascript:;" onClick="javascript:tagshow(event, 'Robot');" target="_self">Robot中提供了一個文件操作命令,語法如下:
Open filename$ [For mode] [Aclearcase/" target="_blank" >ccess access] [lock] As [#] filenumber% [Len = reclen]
這里我們把它的語法分為兩部分,因為這個文件操作命令有兩種文件操作模式,一種是順序文件,一種是隨機文件。
下邊是對順序文件操作的語法:
Open filename$ [??For [Input |Output |Append] As [#]filenumber [Len = buffersize]
參數說明:
說明:
?。?)參數filename$表示要打開的文件名,文件名可以包含有驅動器和目錄
?。?)Input Output 和Append用于設置順序文件的打開方式。其中,Input表示從打開的文件中讀取數據。以這種方式打開文件時,文件必須存在,否則會產生錯誤。Output表示向打開的文件中寫入數據。以這種方式打開文件時,文件中原有的數據將被覆蓋,新的數據將從文件開始寫入。如果文件不存在,則創建一個新文件。Append表示向打開的文件中添加數據。以這種方式打開時,文件中原有的數據將被保留,新的數據將從文件為開始添加。如果文件不存在,則創建一個新文件。
?。?)As[#]filenumber 子句用于為打開的文件指定文件號.對文件進行讀寫操作時,要用文件號表示該文件.文件號是介于1~511之間的整數,既可以是數字,又可以是變量.也可以省略不用.
(4)當在文件與程序之間拷貝數據時,Len=buffersize子句指定緩沖區的字符數.
例子:
Open “c:\test.dat" For Output As 1
Open “c:\test.dat" For Output As 1
這兩句代碼在c盤所在目錄下創建了一個名為test.dat的文本文件,分配文件號為1.
Open “c:\test.dat"??For Input As [#]filenumber 這條語句是從文本文件中讀取數據.
Open App.Path + "\test.dat" For Append As [#]filenumber?? 這條語句則是向文本文件中添加數據
隨機文件的操作:
操作隨機文件之前,首先必須定義用于保存數據項的記錄類型.該記錄是用戶自定義數據類型,他們是隨機文件中存儲數據的基本結構.例如:
Type Student
No As Integer
Name As String * 20
age As Integer
End Type
Dim Stud As Student ‘定義一個可以存放學生材料的變量
隨機文件中,所有的數據都將保存到若干個結構為Student類型的記錄中, 而從隨機文件中讀出的數據則可以存放到變量Stud中.之后我們就可以打開并讀寫文件了.
隨機文件的操作語法格式:
Open filename For Random as [#]filenumber Len = Reclength
說明:
(1)參數filename 和filenumber 分別表示文件名或文件號.
(2)關鍵字Random 表示打開的是隨機文件
(3)Len子句用于設置記錄長度,長度由參數Reclength指定.Reclength的值必須大于0,而且必須與定義的記錄結構的長度一致.計算記錄長度的方法是將記錄結構中每個元素的長度相加.例如前面聲明的Student的長度應該是2+20+2=24字節.
打開一個記錄類型為Student 的隨機文件的方法是:
Open "c:\Student.txt " For Random As #1 Len = 25
這里還有一種文件操作方式二進制文件,下邊是他的語法格式:
Open pathname For Binary As [#]filenumber
說明:
(1) 參數filename 和filenumber 分別表示文件名或文件號.
(2)關鍵字Binary 表示打開的是二進制文件
(3)對于二進制文件,不能指定字節長度.每個打開的二進制文件都有一個自己的指針,文件指針是一個數字值,指向下一次讀寫操作的文件中的位置.二進制文件中的每個”位置”對應一個數據字節,因此,有n個字節的文件,就有1到n個位置.
我們可以用Seek()函數返回當前的文件指針位置(即下一個要讀寫的字節 );用Loc()函數返回上一次讀寫的字節位置,除非用Seek語句移動了指針,Loc()返回值總比Seek()的小1.我們來看下面的例子:
Open “路徑:\student.txt” for Binary as #1? ? 該語句用二進制的方式打開了student.txt文件.
二)寫文件
1、 順序文件
寫順序文件我們可以用Write # 和Print #語句向一個已經打開的文件中寫入數據.
下面是他們的格式和說明:
Print # 的語法格式:
Print # 文件號,變量列表
例如,將文本框中的文本寫到文件中,代碼如下:
Open "file.txt" For Output As #filenum
Input #filenum, text1.text
Write # 語句的語法格式:
Write # 文件號,變量列表
說明:用Write # 語句寫入的信息便于以后用Input #語句來讀取數據,因為Write #語句自動將寫入到文件中的信息用逗號分開,并為字符串數據加上雙引號.例如:
Open "student.txt" For Output As #filenum
Write #filenum, "張三", "初一年級", 14
Write #filenum, "李四", "職業高中", 18
2、 隨機文件
向隨機文件中寫入數據,使用Put?。UZ句.語法格式如下:
Put [#] FileNum ,[RecNum],UserType
說明:
(1) FileNum 是要打開的文件號;RecNum是要寫入的記錄號,若省略,則再上一次用Get 和Put語句所讀寫過的記錄的后一條記錄中寫入,如果沒有執行過Get 和Put語句,就從第一條記錄開始
(2)UserType 是包含要寫入數據的用戶自定義的數據類型變量.例如:我們向前面的student.txt文件中的第5個記錄寫入數據,可用這些語句:
stud.No = 0301
stud.Name = “王武”
stud.Age =20
Put #1 ,5,stud
如果要插入的數據不只一兩條的話,首先要確定文件和每條記錄的長度,這樣就可以計算出文件中究竟有多少條記錄.我們可以用Lof()函數返回文件的長度,Len()函數返回每個記錄的長度,計算文件中的記錄個數可以用文件的長度除以給個記錄的長度.示例如下:
Nextrec= (Lof(1)\Len(UserType))+1
Put #1,Nextrec,UserType
3、二進制文件
下面是以二進制方式寫入文件的語句格式及其說明:
格式:
Put [#]fileNumber ,[Pos], Var
功能: 用二進制方式,從文件的中指定的位置開始寫入,所給變量長度的數據
說明:
(1)FileNumber是以二進制方式打開的文件號.
(2)Pos用來指定寫操作發生時的字節位置,若省略,則使用當前文件指針位置.
(3)Var是用來存放寫入的數據的變量.該語句會自動根據var變量包含的字節長度寫入文件,如果Var是一個可變長度的字符串變量,則傳送的字節數等于Var中目前的字節數.
使用方法可參考二進制文件的讀操作.
用Excel做Datapool實現Rational Robot 功能測試的一個實例
Rational Robot是一個比較通用的軟件測試工具。她主要通過錄制(自動或手工)腳本用于功能測試和性能測試。
在手工修改Robot錄制的GUI腳本時,經常用到Datapool這一概念,由于Rational自帶的Datapool工具只能支持2000行的數據池紀錄,而且編輯不是很方便?,F用比較方便的Excel作為數據源,實現自動測試的功能。
前提條件:OS系統中已經安裝Office。
[源碼]
'$include "sqautil.sbh"
Sub Main
Dim Result As Integer
dim excel as Object
dim book as Object
dim worksheet as Object
dim s_name as String
dim s_pass as String
dim count as Integer
'Initially Recorded: 2004-4-2 :16:55
'Script Name: AUT_1_Login
Window SetContext, "Caption=Program Manager", ""
StartBrowser "C:\Program Files\Internet Explorer\IEXPLORE.EXE", "WindowTag=WEBBrowser"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Initiliaze excel
on error resume next
Set excel = GetObject(,"excel.application")
if(excel Is Nothing) then
Set excel = CreateObject("excel.application")
if(excel Is Nothing) then
MsgBox "Couldn't find Excel!"
Exit Sub
End if
End if
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set book = excel.Workbooks.Open("Your Book1.xls")
Set worksheet = book.Worksheets("Your Excel sheet's name")
For count=1 To 2
s_name = worksheet.Cells(1,count).value
s_pass = worksheet.Cells(2,count).value
'print s_name,s_pass
Window SetContext, "Caption=Web應用系統 - Microsoft Internet Explorer", ""
Browser SetFrame,"Type=HTMLFrame;HTMLId=mainframe",""
Browser NewPage,"HTMLTitle=Title",""
EditBox Click, "Type=EditBox;Name=userAccount", "Coords=26,10"
InputKeys s_name &"{TAB}"&s_pass
PushButton Click, "Type=PushButton;HTMLText=登錄"
Window SetTestContext, "Caption=Web應用系統 - Microsoft Internet Explorer", ""
Browser SetFrame,"Type=HTMLFrame;HTMLId=mainframe",""
Window SetTestContext, "Caption=Microsoft Internet Explorer", ""
Result = LabelVP (CompareProperties, "Text=輸入錯誤,請重新輸入!", "VP=Object Properties;ExpectedResult=FAIL")
Window ResetTestContext, "", ""
Next count
'Quit Excel'''''''''''''''''''''
excel.Quit
Set excel = Nothing
Window CloseWin, "", ""
End Sub
數據池(DATAPOOL)應用技巧――如何生成定制數據
數據池可以按一定的規則生成測試數據列,但是它不能直接生成定制的數據。下面介紹使用數據池生成定制數據的一種方法:
測試數據要求:數據由用戶和產品數據組成,依次為用戶名、用戶密碼、產品ID、產品價格。用戶名和用戶密碼一一對應,產品ID和產品價格一一對應。要求用戶數據和產品數據隨機組合,生成大量測試數據。
數據生成過程:
1、從數據庫中用Select語句分別從用戶表和產品表中檢索出用戶數據和產品數據,檢索結果分別存為CSV文件,文件名為user.csv和product.csv;
2、在Testmanager中新建DATAPOOL,命名為testdata,插入兩個字段,TYPE選擇“Read from File”,分別選擇上一步生成的CSV文件,Sequense按需要選擇;
3、按“Generate Data”按鈕生成數據,close關閉窗口;
4、“Edit Datapool Data”查看生成的數據,可以看到只有兩列數據,關閉窗口;
5、Manage Datapools窗口上點擊“Import”按鈕,選擇測試項目目錄中的..\TestDatastore\DefaultTestScriptDatastore\TMS_Datapools\ testdata.csv(上一步生成的數據池的CSV文件),輸入新的DATAPOOL名afterdata,按“確定”按鈕;
6、打開afterdata查看生成的數據,數據為4列,數據成功生成。
Rational Robot如何測試幫助c++程序員識別自定義或則第三方控件
大家都知道Rational Robot利用Delphi Enabler支持識別Delphi第三方控件和自定義控件,但是識別C++程序中遇到的第三方控件呢?我將在下邊介紹識別他的方法,希望對大家有所幫助。
SQA Object Testing Control
如果你測試軟件是vb編寫的,那么利用SQA Object Testing Control: (SQAOTE32.ocx)來獲得控件信息很對你來說很熟悉,通過它可以獲取到軟件運行時候的控件信息和方法。Robot可以根據提供的信息建立強壯的腳本,驗證那些方法或功能是否正確,也就是最后的驗證點。
如果你的c或則c++程序中包含自定義或者第三方的ActiveX(ocx)控件,你可以同樣把這個控件放到每一個包含第三方控件或者用到自定義控件的窗體上。
安裝Rational TeamTest或者Robot,Object Testing Control (SQAOTE32.ocx)會默認安裝到系統目錄system32中:C:\WINNT\system32\sqaote32.ocx.。
添加Rational ActiveX Test Control
如果想讓ActiveX Test Control起作用,需要在VC中設置ActiveX可用。以下用MFC舉例
第一.建立工程,設置ActiveX控件可用
第二.在有第三方控件的地方添加Rational ActiveX Test Control
有一個窗體中包含MSTreeView,運行Rational Robot利用object properties來抓取MSTreeView屬性,Rational Robot無法識別該對象(對象為UNKNOW)。添加SQA Object Testing Control(右鍵插入ActiveX控件,出現下圖窗體)。
添加Rational ActiveX Test Control后窗體上出現一個robot的圖標,你不用在代碼中做任何處理就可以使用他。SQA Object Testing Control是個不可見控件,運行軟件后他不會顯示在窗體上。
再沒有添加SQA Object Testing Control的時候Robot只能識別這個控件的通用屬性,添加后Robot可以識別自定義控件或者插件的大部分屬性。
注意
如果用到得自定義控件繼承自MFC或者用APIS實現,即使添加SQA Object Testing Control控件Robot也無法有效的工作。那么定義該對象繼承相近的類別。
方法1:運行的時候當用Object properties識別對象為unknow的時候,在出現的對話框中定義無法識別控件到相近的基類中。
方法2:打開robot,Tools->General Options,切換到object mapping頁面。選擇基類,然后添加無法是別的控件到該類中。
這樣做可以識別該控件的通用類別屬性。
總結:針對無法識別自定義和第三方控件建議添加Rational ActiveX Test Control,通過他能使Robot識別對象的大多數屬性,幫助Robot建立強壯的腳本。
Rational Robot SQABasic數據庫操作相關命令
SQLClose 功能函數
斷開由SQLOpen確定的與ODBC數據源連接。
SQLClose ( connection& )
語法: 參數 解釋
connection& 由SQLOpen返回的一個長整型的名稱參數。
注解:
返回的是一個變量。成功返回0并連接隨后關閉或斷開。如果連接不正常,返回-1。
This example opens the data source named "SblTest," gets the names in the ODBC data sources, and closes the connection.
Sub main
' Declarations
'
Dim outputStr As String
Dim connection As Long
Dim prompt As Integer
Dim datasources(1 To 50) As Variant
Dim retcode As Variant
Dim action1 as Integer
Dim qualifier as String
prompt = 5
' Open the datasource "SblTest"
connection = SQLOpen("DSN=SblTest", outputStr, prompt:=5)
action1 = 1 ' Get the names of the ODBC datasources
retcode = SQLGetSchema(connection:=connection,action:=1, qualifier:=qualifier, ref:=datasources())
' Close the datasource connection
retcode = SQLClose(connection)
End Sub
SQLError功能函數
可以用來接收做ODBC函數調用時發生的多條錯誤的詳細信息。為最近ODBC函數調用和連接返回錯誤信息。
SQLError ( destination() )
語法: 參數 解釋
destination() 兩維數組的每行包含一個錯誤。名稱參數是必要的,必須是變量的數組。
注解
沒有返回值。域: 1) 表示ODBC錯誤類型/下級分類的字符串, 2)表示數據源錯誤編碼的數字值, 3)表示錯誤的文本信息。
如果沒有錯誤從先前的ODBC函數調用發生,則0被返回到調用者數組的(1,1)里。如果數組不是2維的或不支持上面提到的三個域,則一個錯誤信息被返回到調用者數組的(1,1)里。
SQLError Example
This example forces an error to test SQLError function.
sub main
' Declarations
Dim connection As long
Dim prompt as integer
Dim retcode as long
Dim errors(1 To 3, 1 To 10) as Variant
Dim outputStr as String
' Open the datasource
connection = SQLOpen("DSN=SBLTESTW;UID=DBA;PWD=SQL",outputStr,prompt:=3)
' force an error to test SQLError select a nonexistent table
retcode = SQLExecQuery(connection:=connection,query:="select * from notable ")
' Retrieve the detailed error message information into the errors array
SQLError destination:=errors
retcode = SQLClose(connection)
end sub
SQLExecQuery Function
在SQLOpen確定的連接上執行一個SQL語句。
SQLExecQuery ( connection& , query$ )
語法: 參數 解釋
connection& 指定參數、必須。長整形、由SQLOpen返回。
query$ 包含一個有效SQL語句的字符串,返回值是個變量。
注解:
對于SQL SELECT返回結果集的欄數目;對于UPDATE, INSERT, 或 DELETE返回受語句作用的行的數目。任何其它SQL語句返回0。如果函數在指定數據源不能執行此查詢,或如果連接不可用,則返回為負的錯誤編碼。
如果SQLExecQuery被調用但連接上還有一些未處理結果,則這些等待結果被新的結果所代替。
SQLExecQuery Example
This example performs a query on the data source.
Sub main
' Declarations
'
Dim connection As Long
Dim destination(1 To 50, 1 To 125) As Variant
Dim retcode As long
Dim outputStr as String
Dim query as String
' open the connection
connection = SQLOpen("DSN=SblTest",outputStr,prompt:=3)
'
' Execute the query
query = "select * from customer"
retcode = SQLExecQuery(connection,query)
'
' retrieve the first 50 rows with the first 6 columns of each row into
' the array destination, omit row numbers and put column names in the
' first row of the array
'
retcode = SQLRetrieve(connection:=connection,destination:=destination,columnNames:=1,rowNumbers:=0,maxRows:=50, maxColumns:=6,fetchFirst:=0)
' Get the next 50 rows of from the result set
retcode = SQLRetrieve(connection:=connection,destination:=destination,columnNames:=1,rowNumbers:=0,maxRows:=50, maxColumns:=6)
' Close the connection
retcode = SQLClose(connection)
End Sub
SQLGetSchema功能函數
返回各類信息,包括數據源可用的信息,當前用戶ID、表格名稱、表格列的名稱和類型、及其它數據源/數據庫相關信息。
SQLGetSchema (connection& , action% , qualifier$ , ref() )
語法: 參數 解釋
connection& 由SQLOpen返回的一個長整形。
action% 必需項。
qualifier$ 必需項。
ref() 動作請求的對應的結果的變量數組,必須有一個數組即使僅一個參數的一維數組。返回值是一個變量。
注解:
返回一個負數表示一個錯誤。如果請求信息不能被訪問或連接不能用,將返回-1。目標數組必須適當地定制以支持動作或錯誤返回。動作2和3不是普遍被支持的。動作4返回所有表格并不支持權限使用。不是所有數據庫產品和ODBC驅動支持所有動作。
動作對應解釋表:
動作 具體注釋說明
1 現有可用數據源列表(dimension of ref() is one)
2 當前連接上的數據庫列表(不支持)
3 當前連接上數據庫的所有者列表(不支持)
4 指定連接上的表格列表
5 由合法用戶指定表格的欄列的列表(ref() 必須2維)。返回列欄名稱和SQL數據類型。
6 當前連接使用者的用戶ID
7 當前數據庫的名稱
8 當前連接的數據源的名稱。
9 數據源使用的DBMS的名稱(例如Oracle)。
10 數據源的服務器名稱
11 數據源表示擁有者的術語
12 數據源表示表格的術語
13 數據源表示合法用戶的術語
14 數據源表示過程的術語
SQLGetSchema Example
This example opens the data source named "SblTest," gets the names in the ODBC data sources, and closes the connection.
Sub main
' Declarations
'
Dim outputStr As String
Dim connection As Long
Dim prompt As Integer
Dim datasources(1 To 50) As Variant
Dim retcode As Variant
Dim action1 as Integer
Dim qualifier as String
prompt = 5
' Open the datasource "SblTest"
connection = SQLOpen("DSN=SblTest", outputStr, prompt:=5)
action1 = 1 ' Get the names of the ODBC datasources
retcode = SQLGetSchema(connection:=connection,action:=1, qualifier:=qualifier, ref:=datasources())
' Close the datasource connection
retcode = SQLClose(connection)
End Sub
SQLOpen 功能函數
建立一個到在connectStr里指定的ODBC數據源的連接并返回一個連接ID,并將完全的連接字符串賦予outputStr變量。如果連接不可用,返回ODBC錯誤的負數。
SQLOpen ( connectStr$ [ , outputStr$] [ , prompt%] )
語法: 參數 解釋
connectStr$ 指定參數,必須參數。
outputStr$ 可選
prompt% 可選。Prompt指定何時驅動對話框出現??蛇x項:
1 對話框永遠出現
2 說明不夠充分以建立連接時打開驅動對話框
3 同2,對話框內容為灰色,不能修改
4 對話框不出現,連接不成功,則返回一個錯誤
注解:
關于connectStr的內容描述在ODBC微軟程序員參考手冊。典型字符串形式為"DSN=datasourcename; UID=myid; PWD=mypassword"。返回長型long型。
當prompt缺省時,SQLOpen使用2作為默認值。
SQLOpen Example
This example opens the data source named "SblTest," gets the names in the ODBC data sources, and closes the connection.
Sub main
' Declarations
'
Dim outputStr As String
Dim connection As Long
Dim prompt As Integer
Dim datasources(1 To 50) As Variant
Dim retcode As Variant
Dim action1 as Integer
Dim qualifier as String
prompt = 5
' Open the datasource "SblTest"
connection = SQLOpen("DSN=SblTest", outputStr, prompt:=5)
action1 = 1 ' Get the names of the ODBC datasources
retcode = SQLGetSchema(connection:=connection,action:=1, qualifier:=qualifier, ref:=datasources())
' Close the datasource connection
retcode = SQLClose(connection)
End Sub
SQLRequest功能函數
建立一個由connectionStr指定數據源的連接,執行包含在query內的SQL語句,返回請求的結果到ref()數組里,并關閉連接。
SQLRequest( connectionStr$ , query$ , outputStr$ , prompt% , columnNames% , ref() )
語法: 參數 解釋
connectionStr$ 必需項。
query$ 必需項
outputStr$ 包含完整連接字符串。
prompt% Prompt指定何時驅動對話框出現。一個整數。(查看SQLOpen).
columnNames% 0或非0的一個整數。當columnNames為非0,欄列名稱作為ref()數組的第一行被返回。如果columnNames缺省,默認值為0。
ref() 必需項,2維變量數組。
注解:
在連接不能被建立、查詢不能用、或其它錯誤的情況下,返回一個負數。在請求成功情況下返回正數或受影響的行數。其它SQL語句返回0。
參數是必需的參數。結果為變量。
SQLRequest Example
This example will open the datasource SBLTESTW and execute the query specified by query and return the results in destination
Sub main
' Declarations
'
Dim destination(1 To 50, 1 To 125) As Variant
Dim prompt As integer
Dim retcode as Variant
Dim query as String
Dim outputStr as String
' The following will open the datasource SBLTESTW and execute the query
' specified by query and return the results in destination
'
query = "select * from class"
retcode = SQLRequest("DSN=SBLTESTW;UID=DBA;PWD=SQL",query,outputStr,prompt,0,destination())
End Sub
SQLRetrieve 功能函數
在由connection指定的連接上獲取待定查詢結果并將結果返回到destination()數組里。
SQLRetrieve( connection& , destination() , maxColumns% , maxRows% , columnNames% , rowNumbers% , fetchFirst% )
語法:
參 數 解 釋
connection& 長型long
destination() 2維變量數組
maxColumns% 整形,可選參數,用來指定在查詢中取回的欄列數目
maxRows% 整形,可選參數,用來指定在查詢中取回的行的數目
columnNames% 整形,可選參數,默認為0
rowNumbers% 整形,可選參數,默認為0
fetchFirst% 整形,可選參數,默認為0
注解:
返回值是結果集的行的數目或請求的最大行。如果函數不能在指定連接上獲得結果,返回-1。如果沒有發現數據,函數返回0。
參數是必需參數。返回變量。
如果maxColumns或maxRows被缺省,數組大小被用來確定獲得的行列的最大數目,并返回整個結果集是一個嘗試。通過再次使用SQLRetrieve和把fetchFirst設置為0,額外行可以被獲得。如果maxColumns指定比結果中可用的更少的列,SQLRetrieve拋棄右邊結果列只到結果與指定大小相適合。
當columnNames是非0,數組的第1行將放置數據庫計劃(database schema)指定的列名稱。 當 rowNumbers是非0,行數目返回到destination()的第1列。SQLRetrieve將清空用戶的數組來獲得結果。
當fetchFirst 是非0,它將結果重新配置到第一行,前提是如果數據庫支持此功能。如果數據庫不支持此功能,結果設置 –1錯誤被返回。
如果結果集有比可以被destination()數組包含還多的行或比用maxRows請求還多的行,用戶可以重復調用SQLRetrieve只到返回值為0為止。
SQLRetrieve Example
This example retrieves information from a data source.
Sub main
' Declarations
'
Dim connection As Long
Dim destination(1 To 50, 1 To 125) As Variant
Dim retcode As long
Dim query as String
Dim outputStr as String
connection = SQLOpen("DSN=SblTest",outputStr,prompt:=3)
'
' Execute the query
query = "select * from customer"
retcode = SQLExecQuery(connection,query)
' retrieve the first 50 rows with the first 6 columns of each row into
' the array destination, omit row numbers and put column names in the
' first row of the array
retcode = SQLRetrieve(connection:=connection,destination:=destination, columnNames:=1,rowNumbers:=0,maxRows:=50, maxColumns:=6,fetchFirst:=0)
' Get the next 50 rows of from the result set
retcode = SQLRetrieve(connection:=connection,destination:=destination,columnNames:=1,rowNumbers:=0,maxRows:=50, maxColumns:=6)
' Close the connection
retcode = SQLClose(connection)
End Sub
SQLRetrieveToFile 功能函數
在connection指定的連接上獲取待定查詢結果并存儲到destination指定的文件。
SQLRetrieveToFile( connection& , destination$ , columnNames% , columnDelimiter$ )
語法: 參數 解釋
connection& 必需項,long
destination$ 必需項,包含用來存儲結果的文件和路徑的字符串。
columnNames% 整型,非0時,文件首行將存儲數據庫計劃指定的欄列名稱。如果缺省,默認為0。
columnDelimiter$ 每行內界定域用的字符串。如果缺省,tab鍵用來分隔域。
注解:
成功完成操作情況下,返回值是結果集的行數目。如果函數不能在指定連接上獲得結果,返回-1。
參數是必需參數。返回變量。
SQLRetrieveToFile Example
This example opens a connection to a data source and retrieves information to a file.
Sub main
' Declarations
'
Dim connection As Long
Dim destination As String
Dim retcode As Long
Dim query as String
Dim outputStr as String
Dim filename as String
Dim columnDelimiter as String
'
' Open the connection
connection = SQLOpen("DSN=SblTest",outputStr,prompt:=3)
' Execute the query
'
query = "select * from customer"
retcode = SQLExecQuery(connection,query)
' Place the results of the previous query in the file named by
' filename and put the column names in the file as the first row.
' The field delimiter is %
'
filename = "c:\myfile.txt"
columnDelimiter = "%"
retcode = SQLRetrieveToFile(connection:=connection,destination:=filename, columnNames:=1,columnDelimiter:=columnDelimiter)
retcode = SQLClose(connection)
End Sub
轉載請注明信息來自51testing