fukamachi / caveman

Lightweight web application framework for Common Lisp.
http://8arrow.org/caveman/
776 stars 62 forks source link

Caveman V2 - sqlite3 file-db update/insert-into/delete have no effect #28

Closed fbox closed 10 years ago

fbox commented 10 years ago

Firstly, fukamachi-san (??) thanks for all the work you've done on this CL web framework.

Caveman V2 My updates failed in the sqlite database until I added a dbi:fetch around them.

Example: (I copied and modified your caveman2.db:update function) (defmacro bugfix-update (db table &body clauses) `(dbi:fetch (caveman2.db::execute-sxql ,db sxql:update ,table ,@clauses)))

I think the reason is that in sqlite3 one must call step-statement to cause execution of every statement, even if the statement returns no results.

In your driver dbd/sqlite3 execute-with-connection function it seems you only do binding but no execute. Hence the fetch call is needed.

In your postgres driver you do all the fetching in the execute-with-connection function and store the results in the query object for later.

You could do the same thing for sqlite.

I think to avoid storing so many results. How about just calling step-statement one time in execute and store just one result. Later fetches get that result for the first one and call step-statement for the others. That way all statements get executed properly and you don't have a huge list of results stored.

[Maybe this will work for the postgres driver too]

Sorry this is not a real patch but I think you may find a better solution than the dbi:fetch workaround I have made.

fukamachi commented 10 years ago

Thank you for reporting. Very helpful.

In your postgres driver you do all the fetching in the execute-with-connection function and store the results in the query object for later.

You could do the same thing for sqlite.

MySQL driver behaves as well unless :store nil is specified to dbi:prepare. It would be better if SQLite3 driver do the same too.

fukamachi commented 10 years ago

I think these commits resolve the bug.