packages feed

persistent-sqlite 1.1.3 → 1.1.3.1

raw patch · 3 files changed

+29/−20 lines, 3 files

Files

Database/Persist/Sqlite.hs view
@@ -77,9 +77,9 @@     stmt <- Sqlite.prepare conn sql     return Statement         { finalize = Sqlite.finalize stmt-        , reset = Sqlite.reset stmt+        , reset = Sqlite.reset conn stmt         , execute = execute' conn stmt-        , withStmt = withStmt' stmt+        , withStmt = withStmt' conn stmt         }  insertSql' :: DBName -> [DBName] -> DBName -> InsertSqlResult@@ -98,19 +98,20 @@         ]  execute' :: Sqlite.Connection -> Sqlite.Statement -> [PersistValue] -> IO Int64-execute' conn stmt vals = flip finally (liftIO $ Sqlite.reset stmt) $ do+execute' conn stmt vals = flip finally (liftIO $ Sqlite.reset conn stmt) $ do     Sqlite.bind stmt vals     Sqlite.Done <- Sqlite.step stmt     Sqlite.changes conn  withStmt'           :: MonadResource m-          => Sqlite.Statement+          => Sqlite.Connection+          -> Sqlite.Statement           -> [PersistValue]           -> Source m [PersistValue]-withStmt' stmt vals = bracketP+withStmt' conn stmt vals = bracketP     (Sqlite.bind stmt vals >> return stmt)-    Sqlite.reset+    (Sqlite.reset conn)     (const pull)   where     pull = do
Database/Sqlite.hs view
@@ -39,8 +39,10 @@ import Data.Text.Encoding (encodeUtf8, decodeUtf8With) import Data.Text.Encoding.Error (lenientDecode) import Data.Monoid (mappend, mconcat)+import Data.IORef (IORef, newIORef, readIORef, writeIORef) -newtype Connection = Connection (Ptr ())+data Connection = Connection !(IORef Bool) Connection'+newtype Connection' = Connection' (Ptr ()) newtype Statement = Statement (Ptr ())  data Error = ErrorOK@@ -126,7 +128,7 @@ foreign import ccall "sqlite3_errmsg"   errmsgC :: Ptr () -> IO CString errmsg :: Connection -> IO Text-errmsg (Connection database) = do+errmsg (Connection _ (Connection' database)) = do   message <- errmsgC database   byteString <- BS.packCString message   return $ decodeUtf8With lenientDecode byteString@@ -158,7 +160,8 @@                                case error of                                  ErrorOK -> do                                             database' <- peek database-                                            return $ Left $ Connection database'+                                            active <- newIORef True+                                            return $ Left $ Connection active $ Connection' database'                                  _ -> return $ Right error)) open :: Text -> IO Connection open path = do@@ -170,7 +173,8 @@ foreign import ccall "sqlite3_close"   closeC :: Ptr () -> IO Int closeError :: Connection -> IO Error-closeError (Connection database) = do+closeError (Connection iactive (Connection' database)) = do+  writeIORef iactive False   error <- closeC database   return $ decodeError error close :: Connection -> IO ()@@ -183,7 +187,7 @@ foreign import ccall "sqlite3_prepare_v2"   prepareC :: Ptr () -> CString -> Int -> Ptr (Ptr ()) -> Ptr (Ptr ()) -> IO Int prepareError :: Connection -> Text -> IO (Either Statement Error)-prepareError (Connection database) text' = do+prepareError (Connection _ (Connection' database)) text' = do   BS.useAsCString (encodeUtf8 text')                   (\text -> do                      alloca (\statement -> do@@ -221,12 +225,16 @@ resetError (Statement statement) = do   error <- resetC statement   return $ decodeError error-reset :: Statement -> IO ()-reset statement = do-  error <- resetError statement-  case error of-    ErrorOK -> return ()-    _ -> return () -- FIXME confirm this is correct sqlError Nothing "reset" error+reset :: Connection -> Statement -> IO ()+reset (Connection iactive _) statement = do+  active <- readIORef iactive+  if active+      then do+          error <- resetError statement+          case error of+            ErrorOK -> return ()+            _ -> return () -- FIXME confirm this is correct sqlError Nothing "reset" error+      else return ()  foreign import ccall "sqlite3_finalize"   finalizeC :: Ptr () -> IO Int@@ -421,7 +429,7 @@   mapM (\i -> column statement i) [0..count-1]  foreign import ccall "sqlite3_changes"-  changesC :: Connection -> IO Int+  changesC :: Connection' -> IO Int  changes :: Connection -> IO Int64-changes = fmap fromIntegral . changesC+changes (Connection _ c) = fmap fromIntegral $ changesC c
persistent-sqlite.cabal view
@@ -1,5 +1,5 @@ name:            persistent-sqlite-version:         1.1.3+version:         1.1.3.1 license:         MIT license-file:    LICENSE author:          Michael Snoyman <michael@snoyman.com>