51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 3955|回复: 7
打印 上一主题 下一主题

[Robot] Rational robot SQABasic数据库操作相关命令(转)

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2004-9-14 19:08:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏

该用户从未签到

2#
 楼主| 发表于 2004-9-14 19:09:02 | 只看该作者
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
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2004-9-14 19:09:13 | 只看该作者
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
回复 支持 反对

使用道具 举报

该用户从未签到

4#
 楼主| 发表于 2004-9-14 19:09:24 | 只看该作者
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
回复 支持 反对

使用道具 举报

该用户从未签到

5#
发表于 2004-9-17 17:13:26 | 只看该作者
谢谢
回复 支持 反对

使用道具 举报

该用户从未签到

6#
发表于 2004-9-23 14:51:33 | 只看该作者
thank you very much
回复 支持 反对

使用道具 举报

该用户从未签到

7#
发表于 2004-10-14 14:53:25 | 只看该作者
谢谢
回复 支持 反对

使用道具 举报

该用户从未签到

8#
发表于 2004-10-15 15:38:03 | 只看该作者
不错呀。呵呵。
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-12 12:48 , Processed in 0.074780 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表