Permalink
Browse files

`fetch-all'

  • Loading branch information...
1 parent dd0ea86 commit 41e30a9d3235ddf79213687ef5e6f356a5a64273 @fukamachi committed May 1, 2012
Showing with 14 additions and 1 deletion.
  1. +1 −0 README.markdown
  2. +2 −0 src/dbi.lisp
  3. +7 −0 src/driver.lisp
  4. +4 −1 src/test.lisp
View
@@ -43,6 +43,7 @@ This library will be available on Quicklisp when ready to use.
* prepare [conn sql] => <dbi-query>
* execute [query & params] => something
* fetch [result] => a row data as plist
+* fetch-all [result] => a list of all row data
* do-sql [conn sql & params]
* list-all-drivers [] => (<dbi-driver> ..)
* find-driver [driver-name] => <dbi-driver>
View
@@ -15,6 +15,7 @@
:prepare
:execute
:fetch
+ :fetch-all
:do-sql
:begin-transaction
:commit
@@ -25,6 +26,7 @@
:prepare
:execute
:fetch
+ :fetch-all
:do-sql
:begin-transaction
:commit
View
@@ -97,6 +97,13 @@ This method may be overrided by subclasses."
(fetch-using-connection (query-connection query) query))
@export
+(defmethod fetch-all ((query <dbi-query>))
+ "Fetch all rest rows from `query`."
+ (loop for result = (fetch query)
+ while result
+ collect result))
+
+@export
(defmethod fetch-using-connection ((conn <dbi-connection>) (query <dbi-query>))
(error '<dbi-unimplemented-error>
:method-name 'fetch-using-connection))
View
@@ -19,7 +19,7 @@
@export
(defun run-driver-tests (driver-name &rest params)
(let ((*db* (apply #'connect driver-name params)))
- (plan 17)
+ (plan 18)
(run-test-all)))
(deftest |connect|
@@ -39,6 +39,9 @@
(setf query (prepare *db* "SELECT * FROM person"))
(is-type query '<dbi-query>)
(setf result (execute query))
+ (is (fetch-all result)
+ '((:|id| 1 :|name| "fukamachi") (:|id| 2 :|name| "matsuyama")))
+ (setf result (execute query))
(is-type result '<dbi-query>)
(let ((result (fetch result)))
(is-type result '(non-nil property-list))

0 comments on commit 41e30a9

Please sign in to comment.