Skip to content

Commit 4b79cf2

Browse files
committed
Document Jaybird 7 schema support
1 parent 3a92c39 commit 4b79cf2

File tree

5 files changed

+115
-3
lines changed

5 files changed

+115
-3
lines changed

src/docs/asciidoc/appendices/connectionproperties/connectionproperties.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ Character set for the connection using Java character set name.
9696
Similar to the previous property, but instead of Firebird-specific name accepts a Java character set name. +
9797
In general, only specify `charSet` _or_ `encoding`, not both.
9898

99+
a|`searchPath` +
100+
`search_path`, `isc_dpb_search_path`
101+
a|Schemas to search for unqualified objects ([.since]_Jaybird 7_, [.since]_Firebird 6.0_) +
102+
Comma-separated list of schema names.
103+
For a case-sensitive or otherwise non-regular schema name, the identifier *must* be quoted.
104+
See <<ref-schema-support-search-path>> for more information.
105+
99106
a|`sqlDialect` +
100107
`dialect`, `sql_dialect`, `isc_dpb_sql_dialect`
101108
a|SQL dialect, can be 1, 2 or 3. +

src/docs/asciidoc/chapters/services/services.adoc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -936,10 +936,25 @@ Possible values are (bit mask, can be combined):
936936
|getHeader{zwsp}Page()
937937
|Get information from the header page (e.g. page size, OIT, OAT and Next transaction values, etc.)
938938

939-
|getTable{zwsp}Statistics(String[])
940-
|Get statistic information for the specified tables.
939+
|getTable{zwsp}Statistics({zwsp}String[])
940+
a|Get statistic information for the listed tables.
941941

942-
This method allows to limit the reported statistical information to a single or couple of the tables, not for the whole database.
942+
The statistics will be limited to the listed tables.
943+
In Jaybird 6 and earlier, at least one table is required.
944+
945+
[.since]_Jaybird 7_ Method accepts varargs (`++String...++`).
946+
In Jaybird 7 and later, specifying no tables will list all tables.
947+
948+
|getTable{zwsp}Statistics({zwsp}Collection<String>)
949+
|[.since]_Jaybird 7_ Same as previous, but as a collection of table names.
950+
951+
|getTable{zwsp}Statistics({zwsp}Collection<String>, Collection<String>)
952+
a|[.since]_Jaybird 7_ Get statistic information for the listed tables in the listed schemas.
953+
Accepts a collection of schema names and a collection of table names.
954+
955+
The statistics will be limited to the listed schemas, and the listed tables.
956+
If both collections are empty, all tables in all schemas are reported.
957+
On Firebird 5.0 and older, the collections of schemas will be ignored.
943958

944959
|getDatabase{zwsp}Transaction{zwsp}Info()
945960
a|Get transaction information of a database
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
[#ref-schema-support]
2+
=== Schema support
3+
4+
[.since]_Jaybird 7_ +
5+
[.since]_Firebird 6.0_
6+
7+
Firebird 6.0 introduced schema support, and schemas are supported in Jaybird 7 and higher.
8+
9+
This sections describes aspects of schema support that we think are relevant, or deviate from JDBC defined behaviour.
10+
11+
[#ref-schema-support-search-path]
12+
==== Search path
13+
14+
In Firebird 6.0 and higher, the search path is a list of schemas that Firebird searches for objects that are not fully-qualified -- for example a select statement referencing a table without a schema name.
15+
16+
Jaybird has a connection property `searchPath` (aliases `search_path`, `isc_dpb_search_path`) to configure the initial search path of a connection.
17+
If the `SYSTEM` schema is not included, Firebird will automatically add it to the end of the search path.
18+
The configured value is also what is reverted to when executing `ALTER SESSION RESET`.
19+
20+
The value of this connection property is a comma-separated list of schema names.
21+
For a case-sensitive or otherwise non-regular schema name, the identifier *must* be quoted.
22+
23+
The `FirebirdConnection` interface defines the methods `setSearchPath(String)` and `setSearchPathList(List<String>)` to change the search path of the current connection.
24+
It also defines methods `String getSearchPath()` and `List<String> getSearchPathList()` to obtain the search path of the connection.
25+
26+
[#ref-schema-support-set-schema]
27+
==== Current schema and `Connection.setSchema/getSchema`
28+
29+
The first _valid_ (existing) schema on the search path is the _current schema_.
30+
The current schema is used to create objects if they are not fully-qualified.
31+
32+
JDBC defines the method `setSchema` to change the current schema, and `getSchema` to retrieve the current schema.
33+
34+
The implementation in Jaybird will do one of the following:
35+
36+
. Prepend the schema to the existing search path.
37+
+
38+
This is done if `setSchema` was not called before, or if Jaybird detected that the search path was changed in some other fashion.
39+
. Replace the first value of the current search path with a new value.
40+
+
41+
This is done if the current search path is unchanged since the previous call to `setSchema`, otherwise it's prepended.
42+
43+
The `setSchema` method will not check if the specified schema exists, nor throw an exception.
44+
In other words, the current schema -- and the value reported by `getSchema` -- might not change, or change to a different value in case 2 (replacing the first schema), if the specified schema does not exist.
45+
46+
If a schema on the search path that previously did not exist is created, the value reported by `getSchema` may change even if the search path was not changed.
47+
48+
[#ref-schema-support-statement]
49+
==== Non-standard statement behaviour
50+
51+
JDBC requires that a statement object, once created, does not change the current schema it uses.
52+
That is, changes made with `Connection.setSchema` should not apply to statements created before that call.
53+
Jaybird cannot fully meet this requirement as the search path is a connection-level property, and Firebird will use the search path as it is at prepare time.
54+
55+
- For `Statement`, Jaybird will prepare the statement text on execute, so the search path at that time is used and resolution can change between executes on the same `Statement` object.
56+
- For `PreparedStatement` (not `CallableStatement`), Jaybird will prepare the statement text at `Connection.prepareStatement` time, so it can guarantee the required behaviour.
57+
- For `CallableStatement`, Jaybird will attempt to identify the procedure at `Connection.prepareCall` time, and rewrite the statement text to use a fully-qualified reference.
58+
If it can identify the procedure, Jaybird will meet the required behaviour.
59+
+
60+
However, actual server-side statement preparation is delayed and will be repeated during the lifetime of the `CallableStatement`.
61+
So, if Jaybird was not able to identify the procedure during `prepareCall`, the actual schema and procedure resolution can change between executes.
62+
63+
[TIP]
64+
====
65+
If you need stable resolution where Jaybird doesn't guarantee it, you can fully qualify the objects (e.g. tables) in your statements:
66+
67+
[source,sql]
68+
----
69+
select
70+
MY_TABLE.*,
71+
MY_SCHEMA.MY_FUNCTION(MY_COLUMN),
72+
MY_SCHEMA.MY_PACKAGE.MY_FUNCTION(MY_COLUMN)
73+
from MY_SCHEMA.MY_TABLE
74+
----
75+
76+
[source]
77+
----
78+
{call MY_SCHEMA.MY_PROCEDURE(?, ?)}
79+
-- or
80+
{call MY_SCHEMA.MY_PACKAGE.MY_PROCEDURE(?, ?)}
81+
----
82+
====

src/docs/asciidoc/reference/reference.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ include::connection/reportsqlwarnings.adoc[]
3232

3333
include::connection/socketfactory.adoc[]
3434

35+
include::connection/schemasupport.adoc[]
36+
3537
[[ref-statement]]
3638
== Statement reference
3739

@@ -53,6 +55,8 @@ include::statement/allowtxstmts.adoc[]
5355

5456
include::statement/extendedmetadata.adoc[]
5557

58+
include::statement/schemasupport.adoc[]
59+
5660
// TODO: Document closeOnCompletion support?
5761

5862
////
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[#ref-stmt-schema-support]
2+
=== Schema support
3+
4+
See <<ref-schema-support-statement>>.

0 commit comments

Comments
 (0)