takusen-oracle 0.9.3 → 0.9.4.1
raw patch · 5 files changed
+24/−168 lines, 5 filesdep ~basesetup-changed
Dependency ranges changed: base
Files
- Database/Oracle/Enumerator.hs +8/−7
- Database/Oracle/OCIConstants.hs +2/−0
- Database/Oracle/OCIFunctions.hs +1/−1
- Setup.hs +2/−147
- takusen-oracle.cabal +11/−13
Database/Oracle/Enumerator.hs view
@@ -149,7 +149,7 @@ -- These wrappers ensure that only DBExceptions are thrown, -- and never OCIExceptions. -data Session = Session +data Session = Session { envHandle :: EnvHandle , errorHandle :: ErrorHandle , connHandle :: ConnHandle @@ -266,7 +266,7 @@ startServerSession user pswd env err server -logoff :: ErrorHandle -> ConnHandle -> IO () +logoff :: ErrorHandle -> ConnHandle -> IO () logoff err conn = catchOCI (do session <- OCI.getHandleAttr err (castPtr conn) oci_HTYPE_SVCCTX oci_ATTR_SESSION server <- OCI.getHandleAttr err (castPtr conn) oci_HTYPE_SVCCTX oci_ATTR_SERVER @@ -311,7 +311,7 @@ -- there's no equivalent for ReadUncommitted. beginTrans :: Session -> IsolationLevel -> IO () -beginTrans session isolation = inSession session +beginTrans session isolation = inSession session (\_ err conn -> do case isolation of ReadUncommitted -> OCI.beginTrans err conn oci_TRANS_READWRITE @@ -464,7 +464,7 @@ executeCommand sess (CommandBind sqltext bas) = do let (PreparationA pa) = prepareStmt' 0 sqltext FreeWithQuery CommandType ps <- pa sess - bindRun sess ps bas (\(BoundStmt bs) -> do + bindRun sess ps bas (\(BoundStmt bs) -> do n <- getRowCount sess (stmtHandle bs) closeStmt (stmtSession ps) (stmtHandle ps) return n @@ -711,7 +711,7 @@ instance OracleBind a => OracleBind (Maybe a) where bindWithValue (Just v) a = bindWithValue v a - bindWithValue Nothing a = return () + bindWithValue Nothing a = a nullPtr bindWriteBuffer b (Just v) = bindWriteBuffer b v bindWriteBuffer b Nothing = return () bindDataSize (Just v) = bindDataSize v @@ -727,7 +727,7 @@ instance OracleBind String where -- FIXME should these be withUTF8String{Len} ? bindWithValue v a = withCString v (\p -> a (castPtr p)) - bindWriteBuffer b s = withCStringLen s (\(p,l) -> + bindWriteBuffer b s = withCStringLen s (\(p,l) -> copyBytes (castPtr b) p (1+l)) bindDataSize s = fromIntegral (length s) bindBufferSize _ = 32000 @@ -776,6 +776,7 @@ pok p (fn v) action (castPtr p) +clength :: Foldable m => m a -> Integer clength = fromIntegral . length toCInt :: Int -> CInt; toCInt = fromIntegral @@ -883,7 +884,7 @@ return (Query pstmt sess (Just pstmt)) -data ColumnBuffer = ColumnBuffer +data ColumnBuffer = ColumnBuffer { colBufBufferFPtr :: OCI.ColumnResultBuffer , colBufNullFPtr :: ForeignPtr CShort , colBufSizeFPtr :: ForeignPtr CUShort
Database/Oracle/OCIConstants.hs view
@@ -23,6 +23,8 @@ oci_DEFAULT :: CInt oci_DEFAULT = 0 +oci_THREADED :: CInt +oci_THREADED = 1 -- ** Handle types:
Database/Oracle/OCIFunctions.hs view
@@ -313,7 +313,7 @@ envCreate :: IO EnvHandle envCreate = alloca $ \ptr -> do - rc <- ociEnvCreate ptr oci_DEFAULT nullPtr nullFunPtr nullFunPtr nullFunPtr 0 nullPtr + rc <- ociEnvCreate ptr oci_THREADED nullPtr nullFunPtr nullFunPtr nullFunPtr 0 nullPtr testForErrorWithPtr rc "allocate initial end" ptr handleAlloc :: CInt -> OCIHandle -> IO OCIHandle
Setup.hs view
@@ -1,147 +1,2 @@-#!/usr/bin/env runhaskell - --- setup configure -fodbc -foracle -fpostgres -fsqlite - -import Prelude hiding (catch) -import Distribution.PackageDescription - ( PackageDescription(..), Library(..), BuildInfo(..), HookedBuildInfo - , emptyHookedBuildInfo, emptyBuildInfo - ) -import Distribution.PackageDescription.Parse ( writeHookedBuildInfo ) -import Distribution.Package (Dependency(..), PackageName(..)) -import Distribution.Simple.Setup ( ConfigFlags(..), BuildFlags(.. ), fromFlag) -import Distribution.Simple - ( defaultMainWithHooks, autoconfUserHooks, UserHooks(..), Args ) -import Distribution.Simple.Program (findProgramOnPath, simpleProgram, Program(..)) -import Distribution.Simple.LocalBuildInfo (LocalBuildInfo) -import Distribution.Simple.Utils (warn, info, rawSystemStdout) -import Distribution.Verbosity (Verbosity) - -import qualified System.Info (os) -import System.Directory (canonicalizePath, removeFile, doesDirectoryExist) -import System.Environment (getEnv) -import System.FilePath (combine, dropFileName, FilePath, pathSeparators, (</>)) -import Control.Monad(liftM) -import Control.Exception (SomeException, try, catch) -import Data.List (isInfixOf) -import Data.Maybe (fromJust) -import Data.Monoid (mconcat) - -{- -One install script to rule them all, and in the darkness build them... - -See this page for useful notes on tagging and releasing: - http://www.haskell.org/haskellwiki/How_to_write_a_Haskell_program - -To-dos for Takusen: - - Oracle resource leak: Ref Cursors (StmtHandles) not freed - - better result-set <-> iteratee validation. Check column types? - - use hsc2hs to create #define constants from header files, - rather than hard-code them. - - Blob support (and clob?). - - - Unwritten tests: - * incorrect fold function (doesn't match result-set) - --} - -emptyCatchHandler :: SomeException -> IO () -emptyCatchHandler _ = return () - -main = defaultMainWithHooks autoconfUserHooks - { preConf=preConf, postConf=postConf - , hookedPrograms = [sqlplusProgram] - } - where - preConf :: Args -> ConfigFlags -> IO HookedBuildInfo - preConf args flags = do - catch (removeFile "Takusen.buildinfo") emptyCatchHandler - return emptyHookedBuildInfo - postConf :: Args -> ConfigFlags -> PackageDescription -> LocalBuildInfo -> IO () - postConf args flags pkgdesc localbuildinfo = do - let verbose = fromFlag (configVerbosity flags) - let lbi = libBuildInfo (fromJust (library pkgdesc)) - let buildtools = buildTools lbi - oraBI <- configOracle verbose buildtools - let bi = mconcat [oraBI, lbi] - writeHookedBuildInfo "Takusen.buildinfo" (Just bi, []) - -sqlplusProgram = simpleProgram "sqlplus" - -isWindows = System.Info.os == "mingw32" || System.Info.os == "windows" - --- ghc-6.6.1 can't cope with a trailing slash or backslash on the end --- of the include dir path, so we strip it off. --- Not sure why this is; there might be something else causing it to fail --- which has gone unnoticed. -stripTrailingSep :: String -> String -stripTrailingSep p - = reverse - . (\s -> if [head s] `isInfixOf` pathSeparators then drop 1 s else s) - . reverse - $ p - -makeConfig path libDir includeDir = do - libDirs <- canonicalizePath (combine path libDir) - includeDirs <- canonicalizePath (combine path includeDir) - return - (emptyBuildInfo - { extraLibDirs = [stripTrailingSep libDirs], includeDirs = [stripTrailingSep includeDirs] }) - -nothingForSomeException :: SomeException -> IO (Maybe String) -nothingForSomeException _ = return Nothing - -maybeGetEnv :: String -> IO (Maybe String) -maybeGetEnv env = catch (liftM Just (getEnv env)) nothingForSomeException - --- Check that the program is in the buildtools. --- If it is, then run the action (which should return BuildInfo). --- If not, return emptyBuildInfo. --- Cabal populates the buildtools list depending on which flags --- have been passed to "setup configure". -guardProg :: Program -> [Dependency] -> IO BuildInfo -> IO BuildInfo -guardProg prog tools action = if prog `isElem` tools then action else return emptyBuildInfo - where - isElem program = any (match program) - match program (Dependency (PackageName tool) _) = programName program == tool - --- Run the first action to give a Maybe FilePath. --- If this is Nothing then emit a warning about library not found. --- Otherwise, run the second action over the FilePath. -guardPath :: IO (Maybe FilePath) -> String -> Verbosity -> (FilePath -> IO BuildInfo) -> IO BuildInfo -guardPath pathAction libName verbose resAction = do - putStrLn $ "Looking for "++libName++"..." - mb <- pathAction - case mb of - Nothing -> warn verbose ("No " ++libName++ " library found") >> return emptyBuildInfo - Just path -> info verbose ("Using " ++libName++ ": " ++ path) >> resAction path - --- From the Oracle 10g manual: --- --- Appendix D - Getting Started with OCI for Windows: --- Compiling OCI Applications for Windows: --- http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14250/ociadwin.htm#i634569 --- Header files are in: ORACLE_BASE\ORACLE_HOME\oci\include --- DLLs are in: ORACLE_BASE\ORACLE_HOME\bin --- --- For Unix full install: --- Appendix B - OCI Demonstration Programs: --- http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14250/ociabdem.htm#i459676 --- Header files are in: $ORACLE_HOME/rdbms/public --- Object files are in: $ORACLE_HOME/lib --- --- For Unix client only install: --- Header files are in: $ORACLE_HOME/oci/include --- Object files are in: $ORACLE_HOME - -configOracle verbose buildtools = - guardProg sqlplusProgram buildtools $ - guardPath (maybeGetEnv "ORACLE_HOME") "Oracle" verbose $ \path -> do - let fullInstallDirs = ("lib", "rdbms/public") - isFullInstall <- doesDirectoryExist (path </> snd fullInstallDirs) - let (libDir, incDir) - | isWindows = ("bin", "oci/include") - | isFullInstall = fullInstallDirs - | otherwise = ("", "sdk/include") - makeConfig path libDir incDir - +import Distribution.Simple+main = defaultMain
takusen-oracle.cabal view
@@ -1,5 +1,5 @@ Name: takusen-oracle -Version: 0.9.3 +Version: 0.9.4.1 License: BSD3 License-file: LICENSE Author: Alistair Bayley, Oleg Kiselyov, Pavel Ryzhov @@ -9,25 +9,25 @@ Homepage: https://github.com/paulrzcz/takusen-oracle.git Package-url: https://github.com/paulrzcz/takusen-oracle.git Category: Database -Build-type: Custom +Build-type: Simple Cabal-Version: >= 1.16 Synopsis: Database library with left-fold interface for Oracle. -Description: +Description: Takusen-Oracle is a Oracle access library. Like HSQL and HDBC, we support arbitrary SQL statements (currently strings, extensible to anything that can be converted to a string). - It is based on original Takusen library. It was just upgraded to support + It is based on original Takusen library. It was just upgraded to support Oracle 11gR2/12c instant client and GHC 7.4.2 and higher. -Extra-tmp-files: +Extra-tmp-files: Database/Oracle/OCIFunctions_stub.c Database/Oracle/OCIFunctions_stub.h source-repository this type: git location: https://github.com/paulrzcz/takusen-oracle.git - tag: 0.9.0 + tag: 0.9.4.1 Flag buildtests Description: Build test executables @@ -42,7 +42,7 @@ -- If we want to build test exe, then it needs Takusen installed. Build-Depends: takusen-oracle Main-Is: Main.hs - Other-modules: + Other-modules: Database.Enumerator , Database.InternalEnumerator , Database.Util @@ -71,7 +71,7 @@ If !flag(buildtests) Buildable: False Main-Is: Test/Main.hs - Other-modules: + Other-modules: Control.Exception.MonadIO , Test.MiniUnit , Test.MiniUnitTest @@ -91,18 +91,16 @@ Database.Oracle.Enumerator , Database.Oracle.OCIConstants , Database.Oracle.OCIFunctions - Build-Tools: sqlplus If os(windows) Extra-Libraries: oci Else Extra-Libraries: clntsh + Extra-Lib-Dirs: /Users/paul/instantclient - Build-Depends: base + Build-Depends: base >= 4.5 && < 5 , mtl , time , old-time Other-Extensions: CPP DeriveDataTypeable - Other-modules: + Other-modules: Database.InternalEnumerator - -- Modules in Other-modules are passed to Haddock with --hide=<module-name>. - Ghc-Prof-Options: -prof -auto-all