描述:
根据sql创建数据库游标返回。
语法:
db. cursor(sql {,args …}) |
|
db.cursor(call dfx(){,args …}) |
通过esProc-ODBC数据源db调用dfx文件,将结果返回成游标。 |
备注:
根据sql创建数据库游标返回,数据扫描完将自动关闭游标。
参数:
db |
数据库连接 |
sql |
需要查询的sql语句,如select * from table。 |
args |
sql中如果用到参数,就必须转入参数值,这里可以是直接写好的参数值,或者是查询定义的args。注意,各个参数之间用逗号分隔。 |
dfx |
网格文件。网格文件可使用相对路径或绝对路径,相对路径时相对于寻址路径。 |
选项:
@i |
结果集只有1列时返回的游标内容为序列 |
@d |
将numeric型数据转换成double型数据而非decimal型数据 |
@x |
关闭游标时自动关闭数据库连接,只限用connect连接的 |
返回值:
游标
示例:
|
A |
B |
C |
|
1 |
=connect("demo") |
|
||
2 |
=A1.cursor("select * from SCORES") |
返回取数游标 |
||
3 |
=create(CLASS,STUDENTID,SUBJECT,SCORE) |
构造新序表 |
||
4 |
for |
|
|
|
5 |
|
if A4==1 |
=A2.skip(5) |
当循环序号为1时,连跳5行 |
6 |
|
=A2.fetch(3) |
从游标A1取数,每次取3条 |
|
7 |
|
if B6==null |
当B5为空时跳出循环 |
|
8 |
|
|
break |
|
9 |
|
else |
|
|
10 |
|
|
>A3.insert(0:B6,CLASS,STUDENTID,SUBJECT,SCORE) |
把B5记录插入到A2中 |
11 |
=A1.cursor@ix("select NAME from STUDENTS") |
添加@x选项,游标关闭时自动关闭数据库连接 |
||
12 |
=A11.fetch() |
游标内容为序列 |
||
13 |
=A1.cursor@i("select NAME from STUDENTS") |
报错:Data Source demo is shutdown or wrong setup.,提示数据源未启动,这是由于A11中的游标关闭时,自动关闭了数据库连接。 |
||
14 |
=mysql.cursor@d("select * from ta") |
|
||
15 |
=A14.fetch() |
|
||
16 |
=myproc.cursor("call hsql(?)",10).fetch() |
hsql.dfx位于寻址路径中,内容如下: myproc为esProc-ODBC数据源名称。参数值为10。结果如下: |
||
17 |
=demo.cursor(“select * from dept deptid<? and father=?”,arg1,arg2) |
arg1、arg2为网格参数,设置参数默认值分别为10、1 |
||
18 |
=A17.fetch() |
|
相关概念: