Skip to content
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

Connect cached does not reconnect with sqlite #32

Open
lucashpandolfo opened this issue Jul 15, 2016 · 2 comments
Open

Connect cached does not reconnect with sqlite #32

lucashpandolfo opened this issue Jul 15, 2016 · 2 comments

Comments

@lucashpandolfo
Copy link

When using connect-cached, after a disconnect the next connect-cached returns the previous connection but because of the disconnect the handle slot is unbound.

CL-USER> (let ((conn (dbi:connect-cached :sqlite3 :database-name "/tmp/test.db")))
  (let* ((query (dbi:prepare conn "PRAGMA stats"))
         (result (dbi:execute query)))
    (loop for row = (dbi:fetch result)
       while row
       do (format t "~A~%" row)))
  (dbi:disconnect conn))

"(table sqlite_master index NIL width 65 height 200)"
=> #<SQLITE:SQLITE-HANDLE {1006E2ED43}>

CL-USER> (let ((conn (dbi:connect-cached :sqlite3 :database-name "/tmp/test.db")))
  (let* ((query (dbi:prepare conn "PRAGMA stats"))
         (result (dbi:execute query)))
    (loop for row = (dbi:fetch result)
       while row
       do (format t "~A~%" row)))
  (dbi:disconnect conn))
=> The slot SQLITE::HANDLE is unbound in the object

The connections remain cached and is not detected by connect-cached because ping only checks if the sqlite db file exists not if the connection is valid (ie: handle is bound).

Relevant code:

@rmhsilva
Copy link

@fukamachi, any idea when/if this will be fixed? Are you welcoming PRs?
Thanks!

@svetlyak40wt
Copy link
Contributor

@rmhsilva @lucashpandolfo seems you just don't have to call disconnect manually. Idea of the cached-connection is that your connection reused between queries. Pool is an abstraction which gives you one connection per thread, to make database queries threadsafe.

Cl-dbi will

cl-dbi/src/dbi.lisp

Lines 118 to 121 in 35b9d68

(unless (bt:thread-alive-p thread)
(maphash (lambda (args conn)
(declare (ignore args))
(disconnect conn))
call disconnect after the thread will exit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants