• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

robot函数实例讲解(二)

发布: 2008-9-18 14:42 | 作者: sincky | 来源: 51testing论坛 | 查看: 36次 | 进入软件测试论坛讨论

领测软件测试网

注解:
关于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

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/

55/5<12345

关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网