Skip to content

Documentation for fetch-lazy and prepared-statement #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ A JDBC library for Clojure.
## Documentation ##

- **Documentation:** http://funcool.github.io/clojure.jdbc/latest/

- **API Docs** https://funcool.github.io/clojure.jdbc/latest/api/index.html
5 changes: 1 addition & 4 deletions doc/content.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ Andrey Antukh, <[email protected]>
:idprefix:
:!numbered:

== link:api/index.html[API reference documentation]

== Introduction

_clojure.jdbc_ is a library for low level, jdbc-based database access.


link:api/index.html[Api reference documentation.]


=== Install

The simplest way to use _clojure.jdbc_ in a clojure project, is by including it in the dependency
Expand Down
26 changes: 22 additions & 4 deletions src/jdbc/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,16 @@

(defn prepared-statement
"Given a string or parametrized sql in sqlvec format
return an instance of prepared statement."
return an instance of prepared statement.
`options` is an optional map with these keys (all optional):
- :result-type - A keyword indicating the java.sql.ResultSet type. Any of :forward-only, :scroll-insensitive, :scroll-sensitive.
- :result-concurrency - A keyword indicating the concurrency mode of the java.sql.ResultSet object. Either :read-only or :updatable.
- :fetch-size - An integer indicating the number of rows to fetch at once.
- :max-rows - An integer indicating the maximumal number of rows that may be fetched.
- :holdability - A keyword indicating whether cursors should be held or closed on commit. Either :hold or :close.
- :returning - Either true or :all, to indicate that the generated keys for new rows should be returned, or a sequence of keywords indicating the names of rows to return.

More information about these options can be found in the [javadoc](https://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html)."
([conn sqlvec] (prepared-statement conn sqlvec {}))
([conn sqlvec options]
(let [conn (proto/connection conn)]
Expand Down Expand Up @@ -146,11 +155,20 @@

This function returns a cursor instead of result.
You should explicitly close the cursor at the end of
iteration for release resources."
iteration for release resources.

`options` is an optional map with these keys (all optional):
- :result-type - A keyword indicating the java.sql.ResultSet type. Any of :forward-only, :scroll-insensitive, :scroll-sensitive.
- :result-concurrency - A keyword indicating the concurrency mode of the java.sql.ResultSet object. Either :read-only or :updatable.
- :fetch-size - An integer indicating the number of rows to fetch at once.
- :max-rows - An integer indicating the maximumal number of rows that may be fetched.
- :holdability - A keyword indicating whether cursors should be held or closed on commit. Either :hold or :close.

More information about these options can be found in the [javadoc](https://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html)."
([conn q] (fetch-lazy conn q {}))
([conn q opts]
([conn q options]
(let [^Connection conn (proto/connection conn)
^PreparedStatement stmt (proto/prepared-statement q conn opts)]
^PreparedStatement stmt (proto/prepared-statement q conn options)]
(types/->cursor stmt))))

(def ^{:doc "Deprecated alias for backward compatibility."
Expand Down
8 changes: 4 additions & 4 deletions src/jdbc/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@
(defn- prepared-statement*
"Given connection and query, return a prepared statement."
([^Connection conn sqlvec] (prepared-statement* conn sqlvec {}))
([^Connection conn sqlvec {:keys [result-type result-concurency fetch-size
([^Connection conn sqlvec {:keys [result-type result-concurrency fetch-size
max-rows holdability returning]
:or {result-type :forward-only
result-concurency :read-only}
result-concurrency :read-only}
:as options}]
(let [sqlvec (if (string? sqlvec) [sqlvec] sqlvec)
^String sql (first sqlvec)
Expand All @@ -211,12 +211,12 @@
holdability
(.prepareStatement conn sql
(result-type constants/resultset-options)
(result-concurency constants/resultset-options)
(result-concurrency constants/resultset-options)
(holdability constants/resultset-options))
:else
(.prepareStatement conn sql
(result-type constants/resultset-options)
(result-concurency constants/resultset-options)))]
(result-concurrency constants/resultset-options)))]

;; Set fetch-size and max-rows if provided by user
(when fetch-size (.setFetchSize stmt fetch-size))
Expand Down