From 15477361ef76fda9aec7af72883950003b27ece1 Mon Sep 17 00:00:00 2001 From: "David M. Johnson" <875324+dmjio@users.noreply.github.com> Date: Sun, 26 Oct 2025 09:12:59 -0500 Subject: [PATCH] Revert "Close statements after use (#53)" This reverts commit ea120be0e7700a2e3e28d9f6968b25a4b758281e. --- src/Database/Oracle/Simple/Execute.hs | 10 ++-------- src/Database/Oracle/Simple/Internal.hs | 15 ++------------- src/Database/Oracle/Simple/Query.hs | 13 +++---------- 3 files changed, 7 insertions(+), 31 deletions(-) diff --git a/src/Database/Oracle/Simple/Execute.hs b/src/Database/Oracle/Simple/Execute.hs index 78b2ffd..fd784a2 100644 --- a/src/Database/Oracle/Simple/Execute.hs +++ b/src/Database/Oracle/Simple/Execute.hs @@ -16,7 +16,6 @@ import Database.Oracle.Simple.Internal Connection, DPIModeExec (DPI_MODE_EXEC_DEFAULT), dpiExecute, - closeStatement, getRowCount, prepareStmt, ) @@ -30,18 +29,14 @@ execute conn sql param = do stmt <- prepareStmt conn sql _ <- evalStateT (runRowWriter (toRow param) stmt) (Column 0) _ <- dpiExecute stmt DPI_MODE_EXEC_DEFAULT - rowCount <- getRowCount stmt - closeStatement stmt - pure rowCount + getRowCount stmt -- | A version of 'execute' that does not perform query substitution. execute_ :: Connection -> String -> IO Word64 execute_ conn sql = do stmt <- prepareStmt conn sql _ <- dpiExecute stmt DPI_MODE_EXEC_DEFAULT - rowCount <- getRowCount stmt - closeStatement stmt - pure rowCount + getRowCount stmt {- | Execute a multi-row INSERT, UPDATE or other SQL query that is not expected to return results. Returns the number of rows affected. If the list of parameters is empty, the function will simply @@ -57,5 +52,4 @@ executeMany conn sql params = do _ <- evalStateT (runRowWriter (toRow param) stmt) (Column 0) _ <- dpiExecute stmt DPI_MODE_EXEC_DEFAULT rowsAffected <- getRowCount stmt - closeStatement stmt pure (totalRowsAffected + rowsAffected) diff --git a/src/Database/Oracle/Simple/Internal.hs b/src/Database/Oracle/Simple/Internal.hs index 1404e63..44a7589 100644 --- a/src/Database/Oracle/Simple/Internal.hs +++ b/src/Database/Oracle/Simple/Internal.hs @@ -49,7 +49,6 @@ module Database.Oracle.Simple.Internal ping, fetch, close, - closeStatement, connect, withConnection, withConnCreateParams, @@ -1909,18 +1908,6 @@ foreign import ccall unsafe "dpiConn_getIsHealthy" Ptr CInt -> IO CInt -foreign import ccall "dpiStmt_close" - dpiStmt_close :: - DPIStmt -> - CString -> - CUInt -> - IO CInt - --- | Close the statement and make it unusable for further work immediately. -closeStatement :: DPIStmt -> IO () -closeStatement stmt = - throwOracleError =<< dpiStmt_close stmt nullPtr 0 - -- | A pointer to an integer defining whether the connection is healthy (1) or not (0), which will be populated upon successful completion of this function. isHealthy :: Connection -> IO Bool isHealthy (Connection fptr) = @@ -1935,3 +1922,5 @@ Structurally equivalent to 'Data.Functor.Identity.Identity'. newtype Only a = Only {fromOnly :: a} deriving stock (Eq, Ord, Read, Show, Generic) deriving newtype (Enum) + + diff --git a/src/Database/Oracle/Simple/Query.hs b/src/Database/Oracle/Simple/Query.hs index 177aa86..04f40d5 100644 --- a/src/Database/Oracle/Simple/Query.hs +++ b/src/Database/Oracle/Simple/Query.hs @@ -13,7 +13,6 @@ import Database.Oracle.Simple.Internal Connection, DPIModeExec (DPI_MODE_EXEC_DEFAULT), dpiExecute, - closeStatement, fetch, prepareStmt, ) @@ -30,9 +29,7 @@ query conn sql param = do found <- fetch stmt loop stmt found where - loop _ n | n < 1 = do - closeStatement stmt - pure [] + loop _ n | n < 1 = pure [] loop stmt _ = do tsVal <- getRow stmt found <- fetch stmt @@ -46,9 +43,7 @@ query_ conn sql = do found <- fetch stmt loop stmt found where - loop _ n | n < 1 = do - closeStatement stmt - pure [] + loop _ n | n < 1 = pure [] loop stmt _ = do tsVal <- getRow stmt found <- fetch stmt @@ -62,9 +57,7 @@ forEach_ conn sql cont = do found <- fetch stmt loop stmt found where - loop _ n | n < 1 = do - closeStatement stmt - pure () + loop _ n | n < 1 = pure () loop stmt _ = do tsVal <- getRow stmt cont tsVal