Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #9 from ralph-moeritz/master

Fixes #8
  • Loading branch information...
commit 56f3400c108e0eb01e99f6c08e737d05b599b4b8 2 parents 8c29978 + 1aa50ef
@fukamachi authored
Showing with 28 additions and 21 deletions.
  1. +28 −21 README.markdown
View
49 README.markdown
@@ -2,27 +2,34 @@
## Usage
- (defvar *connection*
- (dbi:connect :mysql
- :database-name "test"
- :username "nobody"
- :password "1234"))
-
- (let ((query (dbi:prepare *connection*
- "SELECT * FROM somewhere WHERE flag = ? OR updated_at > ?"))
- (result (dbi:execute query 0 "2011-11-01")))
- (loop for row = (dbi:fetch result)
- while row
- ;; process "row".
- ))
-
- ;; Using dbi:with-connection macro.
- (dbi:with-connection (conn :sqlite3 :database-name "/home/fukamachi/test.db")
- (let* ((query (dbi:prepare conn "SELECT * FROM People"))
- (result (dbi:execute query)))
- (loop for row = (dbi:fetch result)
- while row
- do (format t "~A~%" row))))
+### Connecting and executing a query
+
+```common-lisp
+(defvar *connection*
+ (dbi:connect :mysql
+ :database-name "test"
+ :username "nobody"
+ :password "1234"))
+
+(let* ((query (dbi:prepare *connection*
+ "SELECT * FROM somewhere WHERE flag = ? OR updated_at > ?"))
+ (result (dbi:execute query 0 "2011-11-01")))
+ (loop for row = (dbi:fetch result)
+ while row
+ ;; process "row".
+ ))
+```
+
+### Using `dbi:with-connection` to ensure connections are closed
+
+```common-lisp
+(dbi:with-connection (conn :sqlite3 :database-name "/home/fukamachi/test.db")
+ (let* ((query (dbi:prepare conn "SELECT * FROM People"))
+ (result (dbi:execute query)))
+ (loop for row = (dbi:fetch result)
+ while row
+ do (format t "~A~%" row))))
+```
## Warning
Please sign in to comment.
Something went wrong with that request. Please try again.