Skip to content

Commit

Permalink
Change String to Text where it is logically appropriate.
Browse files Browse the repository at this point in the history
  • Loading branch information
IreneKnapp committed Aug 14, 2012
1 parent d74235a commit 7b4bc72
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
23 changes: 12 additions & 11 deletions Database/SQLite3.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ module Database.SQLite3 (

import qualified Data.ByteString as BS
import qualified Data.ByteString.Internal as BSI
import qualified Data.ByteString.UTF8 as UTF8
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import Data.Typeable
import Foreign
import Foreign.C
Expand Down Expand Up @@ -83,7 +84,7 @@ data ColumnType = IntegerColumn

data SQLData = SQLInteger Int64
| SQLFloat Double
| SQLText String
| SQLText T.Text
| SQLBlob BS.ByteString
| SQLNull
deriving (Eq, Show, Typeable)
Expand Down Expand Up @@ -167,7 +168,7 @@ errmsg :: Database -> IO String
errmsg (Database database) = do
message <- errmsgC database
byteString <- BS.packCString message
return $ UTF8.toString byteString
return $ T.unpack $ T.decodeUtf8 byteString

sqlError :: Maybe Database -> String -> Error -> IO a
sqlError maybeDatabase functionName error = do
Expand All @@ -184,7 +185,7 @@ foreign import ccall "sqlite3_open"
openC :: CString -> Ptr (Ptr ()) -> IO Int
openError :: String -> IO (Either Database Error)
openError path = do
BS.useAsCString (UTF8.fromString path)
BS.useAsCString (T.encodeUtf8 $ T.pack path)
(\path -> do
alloca (\database -> do
error <- openC path database
Expand Down Expand Up @@ -218,7 +219,7 @@ foreign import ccall "sqlite3_prepare_v2"
prepareC :: Ptr () -> CString -> Int -> Ptr (Ptr ()) -> Ptr (Ptr ()) -> IO Int
prepareError :: Database -> String -> IO (Either Statement Error)
prepareError (Database database) text = do
BS.useAsCString (UTF8.fromString text)
BS.useAsCString (T.encodeUtf8 $ T.pack text)
(\text -> do
alloca (\statement -> do
error <- prepareC database text (-1) statement nullPtr
Expand Down Expand Up @@ -301,7 +302,7 @@ foreign import ccall "sqlite3_bind_parameter_name"
bindParameterName :: Statement -> Int -> IO (Maybe String)
bindParameterName (Statement stmt) colNdx = do
mn <- bindParameterNameC stmt colNdx >>= maybeNullCString
return (mn >>= return . UTF8.toString)
return (mn >>= return . T.unpack . T.decodeUtf8)

foreign import ccall "sqlite3_bind_blob"
bindBlobC :: Ptr () -> Int -> Ptr () -> Int -> Ptr () -> IO Int
Expand Down Expand Up @@ -374,16 +375,16 @@ bindNull statement parameterIndex = do

foreign import ccall "sqlite3_bind_text"
bindTextC :: Ptr () -> Int -> CString -> Int -> Ptr () -> IO Int
bindTextError :: Statement -> Int -> String -> IO Error
bindTextError :: Statement -> Int -> T.Text -> IO Error
bindTextError (Statement statement) parameterIndex text = do
byteString <- return $ UTF8.fromString text
byteString <- return $ T.encodeUtf8 text
size <- return $ BS.length byteString
BS.useAsCString byteString
(\dataC -> do
error <- bindTextC statement parameterIndex dataC size
(intPtrToPtr (-1))
return $ decodeError error)
bindText :: Statement -> Int -> String -> IO ()
bindText :: Statement -> Int -> T.Text -> IO ()
bindText statement parameterIndex text = do
error <- bindTextError statement parameterIndex text
case error of
Expand Down Expand Up @@ -437,11 +438,11 @@ columnDouble (Statement statement) columnIndex = do

foreign import ccall "sqlite3_column_text"
columnTextC :: Ptr () -> Int -> IO CString
columnText :: Statement -> Int -> IO String
columnText :: Statement -> Int -> IO T.Text
columnText (Statement statement) columnIndex = do
text <- columnTextC statement columnIndex
byteString <- BS.packCString text
return $ UTF8.toString byteString
return $ T.decodeUtf8 byteString

foreign import ccall "sqlite3_column_count"
columnCountC :: Ptr () -> IO Int
Expand Down
8 changes: 6 additions & 2 deletions direct-sqlite.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: direct-sqlite
version: 1.1.0.1
version: 2.0
build-type: Simple
license: BSD3
license-file: LICENSE
Expand All @@ -19,6 +19,8 @@ description:
from the database. In particular, it supports strings encoded as UTF8, and BLOBs
represented as ByteStrings.

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.

Expand All @@ -32,7 +34,9 @@ Source-Repository head
Library
exposed-modules: Database.SQLite3
c-sources: sqlite3.c
build-depends: bytestring, base >= 4.1 && < 5, utf8-string >= 0.3.5
build-depends: base >= 4.1 && < 5,
bytestring >= 0.9.2.1 && < 1,
text >= 0.11.2.2 && < 1

This comment has been minimized.

Copy link
@snoyberg

snoyberg Oct 18, 2012

Is there a reason to require this version of text? The Haskell Platform out right now includes text-0.11.2.0, so having this minimum bound causes two copies of the libraries to be installed, causing build failures due to conflicting symbols. Would it be possible to change the minimum bound to, e.g., 0.11?

This comment has been minimized.

Copy link
@nurpax

nurpax Oct 18, 2012

Collaborator

Filed issue #18 for this.

This comment has been minimized.

Copy link
@snoyberg

snoyberg Oct 18, 2012

Thanks

default-language: Haskell2010


Expand Down

0 comments on commit 7b4bc72

Please sign in to comment.