Description:
Create a database cursor by executing an SQL statement and return it.
Syntax:
db. cursor(sql {,args …}) |
|
Note:
The function creates a database cursor by executing SQL and returns it. The cursor will be automatically closed after a full data scan.
Parameter:
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 |
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 |
=demo.cursor("select * from dept where deptid<? and father=?",arg1,arg2) |
arg1 and arg2 are cellset parameters, whose default values are set as 10 and 1 |
||
17 |
=A16.fetch() |
|
Related functions: