db .cursor()

Description:

Create a database cursor by executing an SQL statement and return it.

Syntax:

db. cursor(sql {,args …})

 

db.cursor(call dfx(){,args })

Connect to esProc-ODBC data source db to call the specified dfx file, and return result as a cursor

Note:

The function creates a database cursor by executing SQL and returns it. The cursor will be automatically closed after a full data scan.

Parameters:

db

Database connection

sql

A SQL statement, like select * from table.

args

If there are parameters in the SQL, they must get assigned; their values can be actual ones or args specified in query statement

Note: Parameters shall be separated by commas

dfx

A cellset file; can be specified using a relative path, which is relative to the search path, or an absolute path

Options:

@i

If the result set has only one column, the content of the returned cursor is a sequence

@d

Convert the numeric data type to the double data type, instead of the decimal data type

@x

Disconnect from the database automatically when the cursor is closed. This option applies to the database connection with connect only

Return value:

A cursor

Example:

 

A

B

C

 

1

=connect("demo")

 

2

=A1.cursor("select * from SCORES")

Return a cursor for retrieving data

3

=create(CLASS,STUDENTID,SUBJECT,SCORE)

Create a table sequence

4

for

 

 

5

 

if A4==1

=A2.skip(5)

When the loop number is 1, jump five rows forward

6

 

=A2.fetch(3)

Fetch three records from cursor A2 at once

7

 

if B6==null

If B6 is empty, break the loop

8

 

 

Break

 

9

 

else

 

 

10

 

 

>A3.insert(0:B6,CLASS,STUDENTID,SUBJECT,SCORE)

Insert the records in B6 into A3

11

=A1.cursor@ix("select NAME from STUDENTS")

Use @x option to automatically disconnect from the database when the cursor is closed

12

=A11.fetch()

The content of the cursor is a sequence

13

=A1.cursor@i("select NAME from STUDENTS")

Error message saying Data Source demo is shutdown or wrong setup suggests that the data source hasn’t been enabled appears. This is because database connection is automatically closed when A11’s cursor is closed

14

=mysql.cursor@d("select * from ta")

 

15

=A14.fetch()

16

=myproc.cursor("call hsql(?)",10).fetch()

hsql.dfx is in the search path. Below is the file:

myproc is the esProc-ODBC data source name; the parameter value is 10. Below is the result:

17

=demo.cursor("select * from dept  deptid<? and father=?",arg1,arg2)

arg1 and arg2 are cellset parameters, whose default values are set as 10 and 1

18

=A17.fetch()

Related functions:

cs.fetch()

cs.skip()