[英]how to convert SqlByteString to String [HDBC]
I want do something on mysql with hdbc , I want know how can I convert SqlByteString to String? 我想用hdbc在mysql上做一些事情,我想知道如何将SqlByteString转换为String? when I try to use fromSql bytestrobj
, I got an error 当我尝试使用fromSql bytestrobj
,出现错误
<interactive>:20:1: error:
• Non type-variable argument
in the constraint: Data.Convertible.Base.Convertible SqlValue a
(Use FlexibleContexts to permit this)
• When checking the inferred type
it :: forall a. Data.Convertible.Base.Convertible SqlValue a => a
*InitPriceTable Database.HDBC Database.HDBC.Types> conn<-connectMySQL defaultMySQLConnectInfo {mysqlUser ="root",mysqlPassword ="root",mysqlDatabase ="linclon"}
fromSql
has the type signature fromSql
具有类型签名
fromSql :: Convertible SqlValue a => SqlValue -> a
If you just write fromSql bytestrobj
, Haskell cannot tell which type a
this expression has. 如果你只写fromSql bytestrobj
,哈斯克尔不能告诉哪种类型的a
这个表达。 In order to force a = ByteString
you can supply the type manually: 为了强制a = ByteString
您可以手动提供类型:
fromSql bytestrobj :: ByteString
Example ghci-session: ghci-session示例:
Prelude> :m +Database.HDBC Data.ByteString
Prelude Database.HDBC Data.ByteString> fromSql (toSql "Hello") :: ByteString
"Hello"
If the type can be inferred, then you can drop the type annotation: 如果可以推断类型,则可以删除类型注释:
Prelude Data.ByteString Database.HDBC> Data.ByteString.take 4 (fromSql (toSql "Hello"))
"Hell"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.