packages feed

direct-sqlite 2.3.12 → 2.3.13

raw patch · 6 files changed

+183/−55 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Database.SQLite3: bindNamed :: Statement -> [(Text, SQLData)] -> IO ()
+ Database.SQLite3.Bindings: c_sqlite3_bind_parameter_index :: Ptr CStatement -> CString -> IO CParamIndex
+ Database.SQLite3.Direct: bindParameterIndex :: Statement -> Utf8 -> IO (Maybe ParamIndex)

Files

Database/SQLite3.hs view
@@ -32,6 +32,7 @@     -- | <http://www.sqlite.org/c3ref/bind_blob.html>     bindSQLData,     bind,+    bindNamed,     bindInt,     bindInt64,     bindDouble,@@ -481,6 +482,30 @@         fail ("mismatched parameter count for bind.  Prepared statement "++               "needs "++ show nParams ++ ", " ++ show (length sqlData) ++" given")     zipWithM_ (bindSQLData statement) [1..] sqlData++-- | Convenience function for binding named values to all parameters.+-- This will 'fail' if the list has the wrong number of parameters or+-- if an unknown name is used.+--+-- Example:+-- >> stmt <- prepare conn "SELECT :foo + :bar"+-- >> bindNamed stmt [(":foo", SQLInteger 1), (":bar", SQLInteger 2)]+bindNamed :: Statement -> [(T.Text, SQLData)] -> IO ()+bindNamed statement params = do+    ParamIndex nParams <- bindParameterCount statement+    when (nParams /= length params) $+        fail ("mismatched parameter count for bind.  Prepared statement "+++              "needs "++ show nParams ++ ", " ++ show (length params) ++" given")+    mapM_ bindIdx params+    where+        bindIdx (name, val) = do+            idx <- Direct.bindParameterIndex statement $ toUtf8 name+            case idx of+                Just i ->+                    bindSQLData statement i val+                Nothing ->+                    fail ("unknown named parameter "++show name)+  -- | -- This will throw a 'DecodeError' if the datum contains invalid UTF-8.
Database/SQLite3/Bindings.hs view
@@ -30,6 +30,7 @@     -- * Parameter and column information     c_sqlite3_bind_parameter_count,     c_sqlite3_bind_parameter_name,+    c_sqlite3_bind_parameter_index,     c_sqlite3_column_count,     c_sqlite3_column_name, @@ -197,6 +198,10 @@ -- | <http://www.sqlite.org/c3ref/bind_parameter_name.html> foreign import ccall unsafe "sqlite3_bind_parameter_name"     c_sqlite3_bind_parameter_name :: Ptr CStatement -> CParamIndex -> IO CString++-- | <http://www.sqlite.org/c3ref/bind_parameter_index.html>+foreign import ccall unsafe "sqlite3_bind_parameter_index"+    c_sqlite3_bind_parameter_index :: Ptr CStatement -> CString -> IO CParamIndex  -- | <http://www.sqlite.org/c3ref/column_count.html> foreign import ccall unsafe "sqlite3_column_count"
Database/SQLite3/Direct.hs view
@@ -33,6 +33,7 @@     -- * Parameter and column information     bindParameterCount,     bindParameterName,+    bindParameterIndex,     columnCount,     columnName, @@ -405,6 +406,13 @@ bindParameterName (Statement stmt) idx =     c_sqlite3_bind_parameter_name stmt (toFFI idx) >>=         packUtf8 Nothing Just++-- | <http://www.sqlite.org/c3ref/bind_parameter_index.html>+bindParameterIndex :: Statement -> Utf8 -> IO (Maybe ParamIndex)+bindParameterIndex (Statement stmt) (Utf8 name) =+    BS.useAsCString name $ \name' -> do+        idx <- fromFFI <$> c_sqlite3_bind_parameter_index stmt name'+        return $ if idx == 0 then Nothing else Just idx  -- | <http://www.sqlite.org/c3ref/column_count.html> columnCount :: Statement -> IO ColumnCount
+ changelog view
@@ -0,0 +1,102 @@+v2.3.13+    * Add support for named parameters to queries.  Split this changelog into+      a separate file (preserving its history).++v2.3.12+	* Upgrade bundled SQLite3 to 3.8.4.1.++v2.3.11++	* Add support for URI filenames, and default to having them+	  on. Among other things, this enables using in-memory databases.++v2.3.10++	* Add support for compiling the bundled SQLite3 with URI filename+	  support. Specifying flags that would have affected the bundled+	  SQLite3 no longer causes build failure if the "systemlib" flag+	  is specified.++v2.3.9++	* Update bounds on the requirement on the "text" library.++v2.3.8++	* Upgrade bundled SQLite3 to 3.8.1.++v2.3.7++	* Fix a test failure related to 64-bit math on column indices.++v2.3.6++	* Re-apply the stat64 hack after upgrade to the bundled+SQLite3.  Oops!++v2.3.5++	* Add support to compile bundled SQLite3 with full-text+	  search.  Upgrade bundled SQLite3 to 3.7.17.++v2.3.4++	* Work around a linker error on some systems; add column-name+	  reporting.++v2.3.3.1++	* Upgrade bundled SQLite3 to 3.7.15.2.++v2.3.3++	* Add trace support, as a feature for debugging.++v2.3.2++	* Add execPrint, execWithCallback, and interruptibly functions.+	  Add bindings for sqlite3_last_insert_rowid and sqlite3_changes.+	  Change the Show instance of the Utf8 newtype to better match the+	  IsString instance.++v2.3.1++	* Upgrade the bundled SQLite3 to 3.7.15.  Add bindings for+	  sqlite3_interrupt.  Export Int rather than CInt.++v2.3++	* Mark some FFI calls "unsafe", for a substantial performance+	  benefit.++v2.2.1++	* Bump down text library version to match with the latest Haskell+	  Platform.++v2.2++	* Actually does what version 2.1 claimed to, since the author made+	  a mistake with git.++v2.1++	* Improves handling of invalid UTF-8 and changes error handling to+	  be more complete.  It also adds a build flag to build against the+	  system sqlite instead of the bundled one, optionally+	  (disabled by default).++v2.0++	* Uses Text for strings instead of String.++v1.1.0.1++	* Switches to the Faction packaging system and makes+	  no other changes.++v1.1++	* Adds the SQLite amalgamation file (version 3.7.5) to the+	  project, so that there are no external dependencies.+
direct-sqlite.cabal view
@@ -1,5 +1,5 @@ name: direct-sqlite-version: 2.3.12+version: 2.3.13 build-type: Simple license: BSD3 license-file: LICENSE@@ -18,64 +18,11 @@   bindings-sqlite3, it is slightly higher-level, in that it supports   marshalling of data values to and from the database.  In particular, it   supports strings encoded as UTF8, and BLOBs represented as ByteStrings.-  .-  Release history:-  .-  [Version 2.3.12] Upgrade bundled SQLite3 to 3.8.4.1.-  .-  [Version 2.3.11] Add support for URI filenames, and default to having them on. Among other things, this enables using in-memory databases.-  .-  [Version 2.3.10] Add support for compiling the bundled SQLite3 with URI filename support. Specifying flags that would have affected the bundled SQLite3 no longer causes build failure if the "systemlib" flag is specified.-  .-  [Version 2.3.9] Update bounds on the requirement on the "text" library.-  .-  [Version 2.3.8] Upgrade bundled SQLite3 to 3.8.1.-  .-  [Version 2.3.7] Fix a test failure related to 64-bit math on column indices.-  .-  [Version 2.3.6] Re-apply the stat64 hack after upgrade to the bundled-  SQLite3.  Oops!-  .-  [Version 2.3.5] Add support to compile bundled SQLite3 with full-text search.  Upgrade bundled SQLite3 to 3.7.17.-  .-  [Version 2.3.4] Work around a linker error on some systems; add-  column-name reporting.-  .-  [Version 2.3.3.1] Upgrade bundled SQLite3 to 3.7.15.2.-  .-  [Version 2.3.3] Add trace support, as a feature for debugging.-  .-  [Version 2.3.2] Add execPrint, execWithCallback, and interruptibly functions.-  Add bindings for sqlite3_last_insert_rowid and sqlite3_changes.  Change the-  Show instance of the Utf8 newtype to better match the IsString instance.-  .-  [Version 2.3.1] Upgrade the bundled SQLite3 to 3.7.15.  Add bindings for-  sqlite3_interrupt.  Export Int rather than CInt.-  .-  [Version 2.3] Mark some FFI calls "unsafe", for a substantial performance-  benefit.-  .-  [Version 2.2.1] Bump down text library version to match with the-  latest Haskell Platform.-  .-  [Version 2.2] actually does what version 2.1 claimed to, since the author-  made a mistake with git.-  .-  [Version 2.1] improves handling of invalid UTF-8 and changes error handling-  to be more complete.  It also adds a build flag to build against the system-  sqlite instead of the bundled one, optionally (disabled by default).-  .-  [Version 2.0] uses Text for strings instead of String.-  .-  [Version 1.1.0.1] switches to the Faction packaging system and makes no other-  changes.-  .-  [Version 1.1] adds the SQLite amalgamation file (version 3.7.5) to the-  project, so that there are no external dependencies.  extra-source-files:   cbits/sqlite3.c   cbits/sqlite3.h+  changelog  Source-Repository head   type: git
test/Main.hs view
@@ -44,6 +44,7 @@     , TestLabel "Params"        . testBindParamCounts     , TestLabel "Params"        . testBindParamName     , TestLabel "Params"        . testBindErrorValidation+    , TestLabel "Params"        . testNamedBindParams     , TestLabel "Columns"       . testColumns     , TestLabel "TypedColumns"  . testTypedColumns     , TestLabel "ColumnName"    . testColumnName@@ -302,6 +303,39 @@     -- Invalid use, one param in q string, 2 given     testException2 stmt = bind stmt [SQLInteger 1, SQLInteger 2] +testNamedBindParams :: TestEnv -> Test+testNamedBindParams TestEnv{..} = TestCase $ do+  withConn $ \conn -> do+    withStmt conn "SELECT :foo / :bar" $ \stmt -> do+      -- Test that we get something back for known names+      Just fooIdx <- Direct.bindParameterIndex stmt ":foo"+      Just barIdx <- Direct.bindParameterIndex stmt ":bar"+      -- Test that we get Nothing back for unknown names+      Nothing <- Direct.bindParameterIndex stmt "intentionally_undefined"+      Right () <- Direct.bindInt64 stmt fooIdx 4+      Right () <- Direct.bindInt64 stmt barIdx 2+      Row <- step stmt+      1 <- columnCount stmt+      [SQLInteger 2] <- columns stmt+      Done <- step stmt+      return ()+    withStmt conn "SELECT @n1+@n2" $ \stmt -> do+      -- Test that we get something back for known names+      Just _n1 <- Direct.bindParameterIndex stmt "@n1"+      Just _n2 <- Direct.bindParameterIndex stmt "@n2"+      -- Here's where things get confusing..  You can't mix different+      -- types of :/$/@ parameter conventions.+      Nothing <- Direct.bindParameterIndex stmt ":n1"+      Nothing <- Direct.bindParameterIndex stmt ":n2"+      return ()+    withStmt conn "SELECT :foo / :bar,:t" $ \stmt -> do+      bindNamed stmt [(":t", SQLText "txt"), (":foo", SQLInteger 6), (":bar", SQLInteger 2)]+      Row <- step stmt+      2 <- columnCount stmt+      [SQLInteger 3, SQLText "txt"] <- columns stmt+      Done <- step stmt+      return ()+ testColumns :: TestEnv -> Test testColumns TestEnv{..} = TestCase $ do   withConn $ \conn -> do@@ -477,6 +511,13 @@         expectError ErrorRange $ bindSQLData stmt i SQLNull       bind stmt []  -- This should succeed.  Don't whine that there aren't any                     -- parameters to bind!+      Row <- step stmt+      SQLInteger 1 <- column stmt 0+      return ()++    withStmt conn "SELECT :bar" $ \stmt -> do+      shouldFail $ bindNamed stmt [(":missing", SQLInteger 42)]+      bindNamed stmt [(":bar", SQLInteger 1)]       Row <- step stmt       SQLInteger 1 <- column stmt 0       return ()