| View previous topic :: View next topic |
| Author |
Message |
mf_user Intermediate

Joined: 01 Jun 2003 Posts: 372 Topics: 105
|
Posted: Thu Nov 22, 2007 7:54 am Post subject: Having a CLOSE CURSOR is not necessary !? |
|
|
Hi,
During a discussion, somebody raised a doubt:
Is it advisable to have Declare, Open, Fetch of Curor only? They say it is not necessary to have Close cursor statement because the DB2 takes care of it internally whether it's a rollback or commit.
They justify that having CLOSE CURSOR is necessary only if you are acting multiple times on same cursor because it requires open and close of the same cursor again and again.
Can somebody explain the technical fators please?
Thanks. _________________ MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
== |
|
| Back to top |
|
 |
CZerfas Intermediate
Joined: 31 Jan 2003 Posts: 211 Topics: 8
|
Posted: Fri Nov 23, 2007 4:40 am Post subject: |
|
|
Hello MF,
yes, the described mechanism is correct, you don't need a CLOSE CURSOR.
Nevertheless it is good programming practice to have a CLOSE in your code. It eases maintenance, if the same cursor has to be opened with different parameters again, for instance.
It is advisable, as well, to code the "unnecessary" COMMIT into your programm, so that your coding is complete and nothing is done "automatically" by the system. Those things could change over time.
just my two cents
Christian |
|
| Back to top |
|
 |
mf_user Intermediate

Joined: 01 Jun 2003 Posts: 372 Topics: 105
|
Posted: Fri Nov 23, 2007 7:06 am Post subject: |
|
|
CZerfas, Thank you.
I wrote a small DB2-COBOL program without CLOSE CURSOR and it was closed automatically.
Actually, I have never seen an explicit COMMIT in any of our programs. _________________ MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
== |
|
| Back to top |
|
 |
videlord Beginner
Joined: 09 Dec 2004 Posts: 147 Topics: 19
|
Posted: Fri Nov 23, 2007 3:10 pm Post subject: |
|
|
most of time it's ok, even you allocate some memory without freeing in your code, system can handle it.
But i will say it's not a good code. It may depend on the compiler, the operation system. Some time it may cause problem.
Keep a good habit, make your code clear, clean. |
|
| Back to top |
|
 |
mf_user Intermediate

Joined: 01 Jun 2003 Posts: 372 Topics: 105
|
Posted: Mon Nov 26, 2007 5:42 am Post subject: |
|
|
Ok. Thank you videlord. _________________ MF
==
Any training that does not include the emotions, mind and body is incomplete; knowledge fades without feeling.
== |
|
| Back to top |
|
 |
dr_te_z Beginner
Joined: 08 Feb 2007 Posts: 18 Topics: 3
|
Posted: Tue Nov 27, 2007 7:08 am Post subject: |
|
|
| mf_user wrote: | | I wrote a small DB2-COBOL program without CLOSE CURSOR and it was closed automatically. | Yeah? Did your program have an iteration where you open/fetch/close more than once?
In the old days (using adabas/ADASQL) I once encountered a program error where the "close" was not coded. The "open" following that did not select any rows and did not throw an abnormal SQLCODE. the next "open", however, did select the required data.
So the typical pattern: OK, not found, OK, not found, OK, not found... indicates a missing "close cursor".
I agree with CZerfas and advice to code the "close" always. This cursor technique is used in a lot of databases and some can handle a missing "close", others cannot. |
|
| Back to top |
|
 |
|
|
|