Closed kalxd closed 2 years ago
You can use Data.Text.decodeUtf8'
.
You can use
Data.Text.decodeUtf8'
.
thanks for your reply.
decodeUtf8'
does not work either, it also prints:
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Hasql.Connection (acquire, release)
import Data.Text.Encoding (decodeUtf8')
main :: IO ()
main = do
conn <- acquire "postgresql://null@192.168.1.10:5431/sl"
case conn of
Right conn' -> release conn'
Left e -> print $ decodeUtf8' <$> e
--- prints:
--- Just (Right "\33268\21629\38169\35823: \25968\25454\24211 \"sl\" \19981\23384\22312\n")
psql
could print chinese characters correctly:
$ psql -U null -h 192.168.1.10 -p 5431 -d sl
psql: 错误: 致命错误: 数据库 "sl" 不存在
it also says database "sl" not existed, my $LANG
is zh_CN.UTF-8.
Now I have no idea how to solve it, could you give me some suggests?
also the query SQL, Haskell not prints very well.
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Main where
import Hasql.Connection (acquire, release)
import qualified Hasql.TH as TH
import Data.Text.Encoding (decodeUtf8')
import Hasql.Statement (Statement)
import Hasql.Session (run, statement)
import Data.Int (Int64)
import Data.Text (Text)
stmt :: Statement () (Int64, Text)
stmt = [TH.singletonStatement| select 1 :: int8, '美林' :: text |]
main :: IO ()
main = do
conn <- acquire "postgresql://null@192.168.1.10:5431"
case conn of
Right conn' -> do
result <- run (statement undefined stmt) conn'
release conn'
print result
Left e -> print $ decodeUtf8' <$> e
--- prints
--- Right (1,"\32654\26519")
How can I solve it? thanks a lot.
Use Data.Text.IO.putStrLn
instead of print
Use
Data.Text.IO.putStrLn
instead of
Great, it works, thanks a lot !!
Hi All. I am using the lastest version
hasql == 1.6.1.3
, and trying to connect to a postgresql server in the local netowork.where
unknowndb
is not exists. When running the code, it prints:so, is where a way to convert the
ByteString
to readableText
? thanks a lot.