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

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

robot函数实例讲解(二)

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

领测软件测试网

如果没有错误从先前的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 对话框不出现,连接不成功,则返回一个错误

延伸阅读

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

54/5<12345>

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

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