git.iko.soy/typeable/postgresql-simple
on master help sign in
привет мир (Add testcase for unicode queries)

I noticed that the IsString instance for Identifier and Query look suspect from an efficiency standpoint. I briefly considered using newtype deriving instead, but then remembered that this would probably break anybody using unicode inside queries. While this wouldn't affect me personally, postgresql-simple does have a number of international users and contributors. So I added this to the test suite, in case I do decide to try to tweak the IsString instance at some point.

commit534799b476cabb6651f27bd65bd9c14cfc5474de authorLeon P Smith <leon@melding-monads.com> dateMon 17 Mar 2014, 07:15 (13 years ago) parente1253f2
1 file changed+13
test/Main.hs+13
test/Main.hs+13
@@ -3,6 +3,7 @@
33{-# LANGUAGE ScopedTypeVariables #-}
44import Common
55import Database.PostgreSQL.Simple.FromField (FromField)
6+import Database.PostgreSQL.Simple.Types(Query(..))
67import Database.PostgreSQL.Simple.HStore
78import qualified Database.PostgreSQL.Simple.Transaction as ST
89import Control.Applicative
@@ -13,8 +14,10 @@ import Data.IORef
1314import Data.Typeable
1415import qualified Data.ByteString as B
1516import Data.Map (Map)
17+import Data.List (sort)
1618import qualified Data.Map as Map
1719import Data.Text(Text)
20+import qualified Data.Text.Encoding as T
1821import System.Exit (exitFailure)
1922import System.IO
2023import qualified Data.Vector as V
@@ -36,6 +39,7 @@ tests =
3639 , TestLabel "HStore" . testHStore
3740 , TestLabel "JSON" . testJSON
3841 , TestLabel "Savepoint" . testSavepoint
42+ , TestLabel "Unicode" . testUnicode
3943 ]
4044
4145testBytea :: TestEnv -> Test
@@ -243,6 +247,15 @@ testSavepoint TestEnv{..} = TestCase $ do
243247
244248 return ()
245249
250+testUnicode :: TestEnv -> Test
251+testUnicode TestEnv{..} = TestCase $ do
252+ let q = Query . T.encodeUtf8
253+ let messages = map Only ["привет","мир"] :: [Only Text]
254+ execute_ conn (q "CREATE TEMPORARY TABLE ру́сский (сообщение TEXT)")
255+ executeMany conn "INSERT INTO ру́сский (сообщение) VALUES (?)" messages
256+ messages' <- query_ conn "SELECT сообщение FROM ру́сский"
257+ sort messages @?= sort messages'
258+
246259data TestException
247260 = TestException
248261 deriving (Eq, Show, Typeable)