packages feed

Pathfinder 0.4.2 → 0.5

raw patch · 2 files changed

+27/−51 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Database.Pathfinder: compileFerry :: XmlString -> OutputFormat -> IO (Either ErrorString OutputString)
- Database.Pathfinder: compileFerryOpt :: XmlString -> OutputFormat -> Maybe OptArgs -> IO (Either ErrorString OutputString)
- Database.Pathfinder: type OptArgs = String
+ Database.Pathfinder: pathfinder :: XmlString -> OptString -> OutputFormat -> IO (Either ErrorString OutputString)
+ Database.Pathfinder: type OptString = String

Files

Pathfinder.cabal view
@@ -1,9 +1,9 @@ Name:                 Pathfinder-Version:              0.4.2+Version:              0.5 Synopsis:             Relational optimiser and code generator Description:   The library provides FFI bindings to the Pathfinder relational optimiser and-  code generator. Specifically, the provided functions allow for+  code generator. Specifically, the library allows for   .   * optimisation of table algebra (a variant of relational algebra) expressions   .
src/Database/Pathfinder.hsc view
@@ -2,13 +2,12 @@  module Database.Pathfinder     (-      compileFerry-    , compileFerryOpt+      pathfinder     , OutputFormat (..)     , XmlString     , ErrorString     , OutputString-    , OptArgs+    , OptString     ) where  import Foreign@@ -20,9 +19,6 @@  #include <pathfinder.h> ------------------------------------------------------------------------------------ Enum: OutputFormat- newtype COutputFormat = COutputFormat { unCOutputFormat :: CInt } #{enum COutputFormat, COutputFormat     , c_PFoutput_format_sql = PFoutput_format_sql@@ -43,56 +39,36 @@          OutputDot -> c_PFoutput_format_dot  ------------------------------------------------------------------------------------ FFI functions- type XmlString    = String type ErrorString  = String type OutputString = String-type OptArgs = String---foreign import ccall safe "PFcompile_ferry"-    c'PFcompile_ferry :: Ptr CString -> CString -> CString -> CInt -> IO CInt---- | Accept a logical query plan bundle in XML format and transform it into one--- of the output formats.-compileFerry :: XmlString                   -- ^ Input XML plan-             -> OutputFormat-             -> IO (Either ErrorString OutputString)-compileFerry xml output = do-    B.useAsCString (T.encodeUtf8 (T.pack xml)) $ \c'xml ->-      alloca $ \ptr -> alloca $ \c'err -> do--          -- run PFcompile_ferry-          ci <- c'PFcompile_ferry ptr c'err c'xml (outputFormatToCInt output)--          if ci == 0-             then Right `fmap` (peek ptr >>= B.packCString >>= (return . T.unpack . T.decodeUtf8))-             else Left  `fmap` (B.packCString c'err >>= (return . T.unpack . T.decodeUtf8))+type OptString    = String   foreign import ccall safe "PFcompile_ferry_opt"-    c'PFcompile_ferry_opt :: Ptr CString -> CString -> CString -> CInt -> CString -> IO CInt+    c_PFcompile_ferry_opt :: Ptr CString -> CString -> CString -> CInt -> CString -> IO CInt --- | Accept a logical query plan bundle in XML format, optimize it based on the--- argument 'OptArgs' or (if 'Nothing') the default optimization arguments in--- @PFopt_args@, and transform it into one of the output formats.-compileFerryOpt :: XmlString-                -> OutputFormat-                -> Maybe OptArgs                        -- ^ Optimization arguments (see pf option -o)-                -> IO (Either ErrorString OutputString)-compileFerryOpt xml output optimization = do-    B.useAsCString (T.encodeUtf8 (T.pack xml)) $ \c'xml ->-      alloca $ \ptr -> alloca $ \c'err -> do+-- | Relational optimiser and code generator+pathfinder :: XmlString     -- ^ A table algebra plan bundle in XML format+           -> OptString     -- ^ An optimisation string (empty string indicates default optimisations)+           -> OutputFormat  -- ^ Output format+           -> IO (Either ErrorString OutputString)+pathfinder xml optimisation output = do+    let bs = T.encodeUtf8 (T.pack xml)+    B.useAsCString bs $ \c_xml -> +      alloca            $ \c_ptr ->+        alloca            $ \c_err -> do+          c_opt <-  case optimisation of+                      [] -> return nullPtr+                      _  -> newCString optimisation -          -- Read optimization arguments, use nullPtr if nothing is given-          opt <- maybe (return nullPtr)-                       newCString-                       optimization+          ci <- c_PFcompile_ferry_opt c_ptr c_err c_xml (outputFormatToCInt output) c_opt+          free c_opt -          -- run PFcompile_ferry_opt-          ci <- c'PFcompile_ferry_opt ptr c'err c'xml (outputFormatToCInt output) opt           if ci == 0-             then Right `fmap` (peek ptr >>= B.packCString >>= (return . T.unpack . T.decodeUtf8))-             else Left  `fmap` (B.packCString c'err >>= (return . T.unpack . T.decodeUtf8))+             then do+               c_string <- peek c_ptr+               r <- fmap (T.unpack . T.decodeUtf8) (B.packCString c_string)+               free c_string+               return (Right r)+             else fmap (Left . T.unpack . T.decodeUtf8)  (B.packCString c_err)