我不在办公室就在星巴克,我不在星巴克就在去星巴克的路上

robot函数实例讲解(二)【转载】

上一篇 / 下一篇  2008-01-26 23:50:45 / 个人分类:robot

RationalRobot中提供了一个文件操作命令,语法如下:
Open filename$ [For mode] [Access access] [lock] As [#] filenumber% [Len = reclen]
这里我们把它的语法分为两部分,因为这个文件操作命令有两种文件操作模式,一种是顺序文件,一种是随机文件。

下边是对顺序文件操作的语法:
Open filename$ [??For [Input |Output |Append] As [#]filenumber [Len = buffersize]
参数说明:
说明:

  (1)参数filename$表示要打开的文件名,文件名可以包含有驱动器和目录

  (2)Input Output 和Append用于设置顺序文件的打开方式。其中,Input表示从打开的文件中读取数据。以这种方式打开文件时,文件必须存在,否则会产生错误。Output表示向打开的文件中写入数据。以这种方式打开文件时,文件中原有的数据将被覆盖,新的数据将从文件开始写入。如果文件不存在,则创建一个新文件。Append表示向打开的文件中添加数据。以这种方式打开时,文件中原有的数据将被保留,新的数据将从文件为开始添加。如果文件不存在,则创建一个新文件。

  (3)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 #语句.语法格式如下:

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行的数据池纪录,而且编辑不是很方便。现用比较方便的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
    'scrīpt 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\DefaultTestscrīptDatastore\TMS_Datapools\ testdata.csv(上一步生成的数据池的CSV文件),输入新的DATAPOOL名afterdata,按“确定”按钮;

6、打开afterdata查看生成的数据,数据为4列,数据成功生成。

Rational Robot如何测试帮助c++程序员识别自定义或则第三方控件

大家都知道Rational Robot利用Delphi Enabler支持识别Delphi第三方控件和自定义控件,但是识别C++程序中遇到的第三方控件呢?我将在下边介绍识别他的方法,希望对大家有所帮助。

SQA ObjectTestingControl

如果你测试软件是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指定何时驱动对话框出现。可选项:
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


TAG: robot

 

评分:0

我来说两句

Open Toolbar