不要追求绝对的公平,红尘之中没有公平而言,人活一世,难得糊涂。                                           it is no use doing what you like, you have got to like what you do.

SQABasic数据库命令(续)

上一篇 / 下一篇  2007-02-05 16:02:56 / 个人分类:Robot技术

SQLRequest功能函数51Testing软件测试网b0q yeM-lN4P P
建立一个由connectionStr指定数据源的连接,执行包含在query内的SQL语句,返回请求的结果到ref()数组里,并关闭连接。51Testing软件测试网?;E!n Y"a"rj5AEs8M
SQLRequest( connectionStr$ , query$ , outputStr$ , prompt% , columnNames% , ref() )51Testing软件测试网"V No(Wv#h0]U'_
语法: 参数 解释51Testing软件测试网,LM L\(^Ru
connectionStr$ 必需项。51Testing软件测试网-c nl$K~GE3VE1o;]*S
query$         必需项51Testing软件测试网Y6ah"~dB8Q6xU
outputStr$      包含完整连接字符串。51Testing软件测试网2F ^zg k,qe7_
prompt%      Prompt指定何时驱动对话框出现。一个整数。(查看SQLOpen).
IS rMW$K5e6i1Mq0columnNames% 0或非0的一个整数。当columnNames为非0,栏列名称作为ref()数组的第一行被返回。如果columnNames缺省,默认值为0。51Testing软件测试网 l(Wn'jS/O5^\
ref()   必需项,2维变量数组。
IA;r*CY#LP0注解:
mQ3jG!K_ ]L0在连接不能被建立、查询不能用、或其它错误的情况下,返回一个负数。在请求成功情况下返回正数或受影响的行数。其它SQL语句返回0。51Testing软件测试网6lz iNZ HBC [
参数是必需的参数。结果为变量。
1A*?i b w2ou8t0SQLRequest Example
3WAI6dTs0This example will open the datasource SBLTESTW and execute the query specified by query and return the results in destination51Testing软件测试网$c|#R!L9F9i+is
Sub main
fmu-TXw Z p3a+Z0'  Declarations
*Fd+kg%M.}lS;s0'51Testing软件测试网6CO@bD ^ O;V6K8l
   Dim destination(1 To 50, 1 To 125)  As Variant51Testing软件测试网)qK FEw;yJ
   Dim prompt As integer
tZ8\ A Oo8f;H F0   Dim retcode as Variant51Testing软件测试网o{t5TG
   Dim query as String51Testing软件测试网F%T U2z w
   Dim outputStr as String51Testing软件测试网cQ kb(wVn'~
  
*`TO I{3V q pe0'  The following will open the datasource SBLTESTW and execute the query
~1s&E0_k P9qr0'  specified by query and return the results in destination51Testing软件测试网^I U"U:O
'   
tZ'q0hE0   query = "select * from class"   
#{p0r-?,L}wz%C4b0   retcode = SQLRequest("DSN=SBLTESTW;UID=DBA;PWD=SQL",query,outputStr,prompt,0,destination())
g5J7K BiG;U0End Sub
6Ql0N"~3KW:i051Testing软件测试网8Rw,W@0E9{Y0z
SQLRetrieve 功能函数
mO#g ^&c;FLa3|0在由connection指定的连接上获取待定查询结果并将结果返回到destination()数组里。51Testing软件测试网9jr,LP'rv5ru#M]
SQLRetrieve( connection& , destination() , maxColumns% , maxRows% , columnNames% , rowNumbers% , fetchFirst% )51Testing软件测试网"G?N+C5N|4e
语法:51Testing软件测试网)i&@0nl'F2}/dQJ)t4K
参   数 解             释51Testing软件测试网 N!t8LEtl [M
connection& 长型long51Testing软件测试网r)O8y Ev!Y%lP
destination() 2维变量数组51Testing软件测试网Y4Mo;hMqQz%zAm
maxColumns% 整形,可选参数,用来指定在查询中取回的栏列数目51Testing软件测试网r i#S7A8MW&X5_|X%i
maxRows% 整形,可选参数,用来指定在查询中取回的行的数目
rNqj3cE ]0columnNames% 整形,可选参数,默认为0
Di3\ R0r$KO0rowNumbers% 整形,可选参数,默认为051Testing软件测试网KS0u2i[R(J
fetchFirst% 整形,可选参数,默认为0
Z8m.Vr'PAc@J@ Lw!P0注解:51Testing软件测试网P jP `y6m
返回值是结果集的行的数目或请求的最大行。如果函数不能在指定连接上获得结果,返回-1。如果没有发现数据,函数返回0。51Testing软件测试网\Fw+zHQM
参数是必需参数。返回变量。51Testing软件测试网5f}DR k\-K8V
如果maxColumns或maxRows被缺省,数组大小被用来确定获得的行列的最大数目,并返回整个结果集是一个尝试。通过再次使用 SQLRetrieve和把fetchFirst设置为0,额外行可以被获得。如果maxColumns指定比结果中可用的更少的列, SQLRetrieve抛弃右边结果列只到结果与指定大小相适合。51Testing软件测试网`2u8M!`sEP dJ
当columnNames是非0,数组的第1行将放置数据库计划(database schema)指定的列名称。 当 rowNumbers是非0,行数目返回到destination()的第1列。SQLRetrieve将清空用户的数组来获得结果。
F,}vnv rI)B0当fetchFirst 是非0,它将结果重新配置到第一行,前提是如果数据库支持此功能。如果数据库不支持此功能,结果设置 –1错误被返回。51Testing软件测试网 Q @8d-jr%Kg/f-Q
如果结果集有比可以被destination()数组包含还多的行或比用maxRows请求还多的行,用户可以重复调用SQLRetrieve只到返回值为0为止。
b c+ti.s4S'RW0SQLRetrieve Example51Testing软件测试网f&y0\_+c(~*figl
This example retrieves information from a data source.51Testing软件测试网w$a,~R zl
Sub main51Testing软件测试网g*Lv X#J3b6|)J
'   Declarations51Testing软件测试网1W-f Bm7` U,@
'
jN;{#H5_QK)g,P0    Dim connection As Long51Testing软件测试网V ?E\5V)v~gT$n
    Dim destination(1 To 50, 1 To 125)  As Variant
z;Q!m}+oti'Y(p0    Dim retcode As long51Testing软件测试网,J VA"AO.W^
    Dim query as String
F@n4\.Bt4Grq(v4n0    Dim outputStr as String51Testing软件测试网3D V IX0V
    connection = SQLOpen("DSN=SblTest",outputStr,prompt:=3)
A(Wm@_3U&I$~0'51Testing软件测试网_\c*Pc.n%A
'  Execute the query
KC*Xi~_?0    query = "select * from customer"  51Testing软件测试网FHh.Q5GN
    retcode = SQLExecQuery(connection,query)
[V/Y'v mmz0  
X!Hz*vlz2AQ VG0'  retrieve the first 50 rows with the first 6 columns of each row into51Testing软件测试网{$};M$P3EZ7K8g*f
'  the array destination, omit row numbers and put column names in the51Testing软件测试网!x@ _.C+?fCI9v
'  first row of the array   
xhU*U0KE:s0   
lUZ!QnGM*Ue0    retcode = SQLRetrieve(connection:=connection,destination:=destination, columnNames:=1,rowNumbers:=0,maxRows:=50, maxColumns:=6,fetchFirst:=0)
^MEate Z051Testing软件测试网;GW-J5W8S k*i
'   Get the next 50 rows of from the result set51Testing软件测试网&Z:S?5U6i `3{2]
    retcode = SQLRetrieve(connection:=connection,destination:=destination,columnNames:=1,rowNumbers:=0,maxRows:=50, maxColumns:=6)51Testing软件测试网6Sf5g#Fb9}/XI"D
'   Close the connection
P&D1r)S2Z ^A0    retcode = SQLClose(connection)
ulVHn-^ y%W0End Sub51Testing软件测试网 K.o5vRm$\i
51Testing软件测试网K1iN2R;C@s
SQLRetrieveToFile 功能函数51Testing软件测试网A-o haGS
在connection指定的连接上获取待定查询结果并存储到destination指定的文件。  51Testing软件测试网 jH#@&GX\ Q m
SQLRetrieveToFile( connection& , destination$ , columnNames% , columnDelimiter$ )51Testing软件测试网7`q Z Az_\Q+b
语法: 参数 解释51Testing软件测试网 Kz2w"M0A s|~6MC0b
connection&  必需项,long
+]5^Db8^)Tb HA0destination$  必需项,包含用来存储结果的文件和路径的字符串。
/w*MJ+O!?G;xu0columnNames% 整型,非0时,文件首行将存储数据库计划指定的栏列名称。如果缺省,默认为0。51Testing软件测试网9quE'c?M
columnDelimiter$ 每行内界定域用的字符串。如果缺省,tab键用来分隔域。
Zh*C A2y;a_!K6Y0注解:51Testing软件测试网H$|1L$t `
成功完成操作情况下,返回值是结果集的行数目。如果函数不能在指定连接上获得结果,返回-1。51Testing软件测试网&?y6nd|!q9OVgK
参数是必需参数。返回变量。51Testing软件测试网A Yx-a3x^q9N2U0H#q
SQLRetrieveToFile Example
k#aU$wx JCU0This example opens a connection to a data source and retrieves information to a file.
}s)b#bgR"x k a][H0Sub main51Testing软件测试网2r/X#nyc7U
'   Declarations51Testing软件测试网:W3? Q4iD#g
'51Testing软件测试网 Z @~SO_dcr
    Dim connection As Long51Testing软件测试网g"_.W&u"a*N}tSA
    Dim destination As String
u8c:l!wWy0    Dim retcode As Long51Testing软件测试网+Bi!Ee-V-a/Q
    Dim query as String51Testing软件测试网m[/Yl7mK
    Dim outputStr as String51Testing软件测试网wP&op'Ta
    Dim filename as String51Testing软件测试网.?4N1JX7?s
    Dim columnDelimiter as String51Testing软件测试网AsmEu R
'51Testing软件测试网5c2s V9js F;t
'  Open the connection51Testing软件测试网-m-[AnUH(X
    connection = SQLOpen("DSN=SblTest",outputStr,prompt:=3)51Testing软件测试网(I ao1G@+xcv"R8Ty!L8d
'  Execute the query
$qHn1b| Q{p0'
?IV:mi1i#|0O \0    query = "select * from customer"  51Testing软件测试网_SY@En!k^q
    retcode = SQLExecQuery(connection,query)51Testing软件测试网6DdCa{3t
'  Place the results of the previous query in the file named by51Testing软件测试网c)D'i{"KN1m3NlFP
'  filename and put the column names in the file as the first row.
zi \'tpW!A_M^0'  The field delimiter is %51Testing软件测试网bSB#|w1I:J ]pL
'  51Testing软件测试网%MR)U*vW n
    filename = "c:\myfile.txt"51Testing软件测试网)Xq!a v \;E
    columnDelimiter = "%"51Testing软件测试网!zk'dfW v!^7{4dT
    retcode = SQLRetrieveToFile(connection:=connection,destination:=filename, columnNames:=1,columnDelimiter:=columnDelimiter)
nX x6^:R0   
)G T(@%m~^a8_0    retcode = SQLClose(connection)
PQIod+p:z0End Sub

TAG: 数据库 软件测试技术 SQABasic 命令 Robot技术

 

评分:0

我来说两句

Open Toolbar