You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/docs/asciidoc/chapters/resultsets/resultsets.adoc
+48-30Lines changed: 48 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
[[resultsets]]
2
2
== Working with result sets
3
3
4
-
When a `SELECT` statement is executed, the results of the query are returned through the implementation of the `java.sql.ResultSet` interface.
4
+
When a `SELECT` statement is executed, the results of the query are returned through an implementation of the `java.sql.ResultSet` interface.
5
5
6
6
=== ResultSet properties
7
7
@@ -10,44 +10,62 @@ When a `SELECT` statement is executed, the results of the query are returned thr
10
10
11
11
The JDBC specification defines three types of result sets
12
12
13
-
* `TYPE_FORWARD_ONLY` -- the result set is not scrollable, the cursor can only move forward.
14
-
When the `TRANSACTION_READ_COMMITTED` isolation level is used, the result set will return all rows that are satisfying the search condition at the moment of fetch (which -- simplified -- will be every _fetch size_ calls to `ResultSet.next()`).
15
-
In other cases, the result set will return only rows that were visible at the moment of the transaction start.
13
+
`TYPE_FORWARD_ONLY`::
14
+
The result set is not scrollable, the cursor can only move forward.
15
+
+
16
+
For isolation level `TRANSACTION_READ_COMMITTED`, the result set will return all rows that satisfy the search condition at the moment of -- Firebird 4.0 and higher -- query execution, or -- Firebird 3.0 and earlier -- fetch (which -- simplified -- will be every _fetch size_ calls to `ResultSet.next()`).
17
+
For other isolation levels, the result set will return rows that were visible at query execution.
16
18
+
17
19
This is the default result set type.
18
-
* `TYPE_SCROLL_INSENSITIVE` -- the result set is scrollable, the cursor can move back and forth, can be positioned on the specified row.
19
-
Only rows satisfying the condition at the time of query execution are visible.
20
-
* `TYPE_SCROLL_SENSITIVE`, is not supported by Firebird and Jaybird.
21
-
Jaybird allows an application to ask for this type of result set, however in compliance with the JDBC specification, the type is "downgraded" to the `TYPE_SCROLL_INSENSITIVE` and a corresponding warning is added to the connection object.
22
20
23
-
Due to missing support for scrollable cursors in Firebird 4.0 and earlier, support for scrollable results set (`TYPE_SCROLL_INSENSITIVE` result set type) is implemented by fetching the complete result set to the client.
21
+
`TYPE_SCROLL_INSENSITIVE`::
22
+
The result set is scrollable.
23
+
+
24
+
The cursor can move back and forth, can be positioned on the specified row.
25
+
Only rows that satisfy the condition at the time of query execution are visible.
26
+
27
+
`TYPE_SCROLL_SENSITIVE`::
28
+
This type is not supported by Firebird and Jaybird.
29
+
+
30
+
Jaybird allows an application to ask for this type of result set, however in compliance with the JDBC specification, the type is "`downgraded`" to `TYPE_SCROLL_INSENSITIVE` and a corresponding warning is added to the connection object.
31
+
32
+
Due to missing support for scrollable cursors in Firebird 4.0 and earlier, support for scrollable results sets (`TYPE_SCROLL_INSENSITIVE`) is implemented by fetching the complete result set to the client.
24
33
Scrolling happens in memory on the client.
25
34
This can have adverse effect on the system memory usage and performance when the result set is large.
26
35
27
36
since:[Jaybird 5] +
28
37
since:[Firebird 5.0]
29
38
30
-
Starting with Firebird 5.0, server-side scrollable cursors are supported.
39
+
Starting with Firebird 5.0, server-side scrollable cursors are supported, but not enabled by default.
31
40
Jaybird 5 introduced support for scrollable non-holdable result set when the connection property `scrollableCursor` is set to value `SERVER`, and the connection is a pure Java connection (not native or embedded).
32
41
A future version may enable this behaviour by default.
33
42
34
43
[[resultsets-concurrency]]
35
44
==== ResultSet Concurrency
36
45
37
-
Result set concurrency specifies whether the result set object can be updated directly or a separate SQL request should be used to update the row.
46
+
Result set concurrency specifies if a row in the result set object can be updated directly through the result set.
38
47
Result sets that allow direct modification using the `ResultSet.updateXXX` methods are usually used in GUI applications which allow in-place editing of the underlying result set.
39
48
40
49
The result set concurrency is specified during statement creation and cannot be changed later.
41
50
JDBC defines two types of result set concurrency, which are both supported by Jaybird:
42
51
43
-
* `CONCUR_READ_ONLY` is available for all types of result sets.
44
-
It tells the driver that direct update of the result set is not possible and all `ResultSet.updateXXX` methods should throw an exception.
45
-
* `CONCUR_UPDATABLE` is supported only under certain conditions that are needed for the driver to correctly construct a DML request that will modify exactly one row.
52
+
`CONCUR_READ_ONLY`::
53
+
Read-only result set.
54
+
This type is always supported.
55
+
It tells the driver that direct update of the result set is not possible.
56
+
All `ResultSet.updateXXX` methods throw an exception.
57
+
58
+
`CONCUR_UPDATABLE`::
59
+
Updatable result set.
60
+
This is supported only under certain conditions that are needed for the driver to correctly construct a DML request that will modify exactly one row.
46
61
These conditions are:
47
-
** the SELECT statement references only one table;
48
-
** all columns that are not referenced by the SELECT statement allow `NULL` values, otherwise it won't be possible to insert new rows;
49
-
** the SELECT statement does not contain the `DISTINCT` predicate, aggregate functions, joined tables, or stored procedures;
50
-
** the SELECT statement references all columns of the tables primary key definition or the `RDB$DB_KEY` column.
62
+
+
63
+
--
64
+
* the `SELECT` statement references only one table;
65
+
* all columns that are not referenced by the `SELECT` statement allow `NULL` values, otherwise it won't be possible to insert new rows;
66
+
* the `SELECT` statement does not contain the `DISTINCT` predicate, aggregate functions, joined tables, or stored procedures;
67
+
* the `SELECT` statement references all columns of the tables primary key definition or the `RDB$DB_KEY` column.
68
+
--
51
69
52
70
[[resultsets-holdability]]
53
71
==== ResultSet Holdability
@@ -56,19 +74,19 @@ Result set holdability informs the driver whether result sets should be kept ope
56
74
`ResultSet.HOLD_CURSORS_OVER_COMMIT` tells the driver to keep the result set object open, while `ResultSet.CLOSE_CURSORS_AT_COMMIT` tells driver to close them on commit.
57
75
58
76
When an application calls `Connection.commit()`, the Firebird server closes all open result sets.
59
-
It is not possible to tell the server to keep a result set open over commit unless "commit retaining" mode is used.
77
+
It is not possible to tell the server to keep a result set open over commit unless "`commit retaining`" mode is used.
60
78
This mode is global for the complete connection and is not suitable for holdability control on a statement level.
61
-
Use of "commit retaining" mode als has an undesirable side effect for read-write transactions as it inhibits garbage collection.
62
-
Because of these reasons "commit retaining" is not used in Jaybird during normal execution.
63
-
Applications can commit the transaction keeping the result sets open by executing a "`COMMIT RETAIN`" SQL statement.
79
+
Use of "`commit retaining`" mode also has an undesirable side effect for read-write transactions as it inhibits garbage collection.
80
+
Because of these reasons "`commit retaining`" is not used in Jaybird during normal execution.
81
+
If really needed, applications can commit the transaction keeping the result sets open by executing a `COMMIT RETAIN` SQL statement.
64
82
65
83
To support holdable result sets, Jaybird will cache all rows locally. +
66
84
until:[Jaybird 6] In Jaybird 5 and earlier, for `TYPE_FORWARD_ONLY`, this is achieved by upgrading to `TYPE_SCROLL_INSENSITIVE`. See also <<resultsets-types>>. +
67
85
since:[Jaybird 6] Since Jaybird 6, the result set type is no longer upgraded to `TYPE_SCROLL_INSENSITIVE`, but all rows are still cached locally.
68
86
69
87
[NOTE]
70
88
====
71
-
When connecting to Firebird 5.0 with Jaybird 5 or higher and connection property `scrollableCursor=SERVER`, a holdable result set will not use server-side scrollable cursor, but instead emulate by caching.
89
+
When connecting to Firebird 5.0 with Jaybird 5 or higher and connection property `scrollableCursor=SERVER`, a holdable result set will not use a server-side scrollable cursor, but instead emulate by caching.
72
90
Server-side scrollable cursors do not support the holdable behaviour.
73
91
====
74
92
@@ -79,9 +97,9 @@ Server-side scrollable cursors do not support the holdable behaviour.
79
97
80
98
[NOTE]
81
99
====
82
-
until:[Jaybird 5.0.5] The implementation in Jaybird 5.0.4 and older does not allow calls to the `getResultSet()` method after using an `executeQuery` or the `getResultSet()` method of the `Statement` class.
100
+
until:[Jaybird 5.0.5] The implementation in Jaybird 5.0.4 and older does not allow calls to the `getResultSet()` method if the result set was already returned by `executeQuery` or a previous call to `getResultSet()`.
83
101
84
-
since:[Jaybird 5.0.5] Starting with Jaybird 5.0.5, calls to `getResultSet()` will return the current result set, even if the result set was returned before by an `executeQuery` or the `getResultSet()` method.
102
+
since:[Jaybird 5.0.5] Starting with Jaybird 5.0.5, calls to `getResultSet()` will return the current result set, even if the result set was already returned before by an `executeQuery` or the `getResultSet()` method.
Depending on the type of the result set, it is possible to move the cursor either forward only (link:#using-forward-only[next example]) or using absolute and relative positioning (link:#using-scrollable-updatable[second example below]).
129
+
Depending on the type of the result set, it is possible to move the cursor either forward only (link:#using-forward-only[next example]), or using absolute and relative positioning (link:#using-scrollable-updatable[second example below]).
112
130
113
131
Values of the result set are obtained by calling the corresponding getter method depending on the type of column.
114
132
For example, the `ResultSet.getInt(1)` method returns the value of the first column as an `int` value.
115
-
If the value of the column is not integer, Jaybird tries to convert it according to the conversions specified in <<datatypeconversion>>.
133
+
If the value of the column is not `INTEGER`, Jaybird tries to convert it according to the conversions specified in <<datatypeconversion>>.
116
134
If conversion is not possible, an exception is thrown.
117
135
118
136
There are two possibilities to obtain data from result set columns: by column label or by column position.
Scrollable cursors are especially useful when result of some query is displayed by the application which also allows the user to directly edit the data and post the changes to the database.
168
+
Updatable result sets are especially useful when the result of some query is displayed by the application which also allows the user to directly edit the data and post the changes to the database.
// TODO: Verify if above example works, shouldn't myColumn be included in the select?
229
+
// TODO: Verify if above example works, shouldn't myColumn be included in the select, and the column list in FOR UPDATE is ignored
212
230
213
231
==== Closing the result set
214
232
215
233
A result set is closed by calling the `ResultSet.close()` method.
216
-
This releases the associated server resources and makes the `ResultSet` object available for garbage collection.
234
+
This releases the associated server resources, and clears data held in the `ResultSet` object, making it available for garbage collection.
217
235
It is strongly recommended to explicitly close result sets in auto-commit mode or `ResultSet.TYPE_SCROLL_INSENSITIVE` result sets, because this releases memory used for the cached data.
0 commit comments