german special characters in select queries
andrewufrank opened this issue · 1 comments
i had a problem with the transmision of german characters (umlaut were ok, but sz not). the solution i found is to make the select query have a bytestring body and to decode the bytestring into a text.
i cannot attach the connection.hs file with the changes (i am not experience with git, using mostly svn). the change for the select query is
-- |Connect to remote 'EndPoint' and find all possible bindings for the
-- 'Variable's in the 'SelectQuery' action.
selectQuery :: Database.HSparql.Connection.EndPoint -> Query SelectQuery -> IO (Maybe [[BindingValue]])
selectQuery ep q = do
let uri = ep ++ "?" ++ urlEncodeVars [("query", createSelectQuery q)]
h1 = mkHeader HdrAccept "application/sparql-results+xml"
h2 = mkHeader HdrUserAgent "hsparql-client"
request = Request { rqURI = fromJust $ parseURI uri
, rqHeaders = [h1,h2]
, rqMethod = GET
, rqBody = (""::B.ByteString)
-- only string or bytestring has instances
-- possibly the other queries should be changed similarly
}
response <- simpleHTTP request >>= getResponseBody
-- af
-- putStrLn . unwords $ ["before structureContent bytestring", show response]
let response' = E.decodeUtf8 response
-- putStrLn . unwords $ ["before structureContent text", T.unpack response']
return $ structureContent response'
if this approach is ok, then it is probably a good idea to change the other query types similarly.
comments? better solution? (how to push?)
andrew (frank@geoinfo.tuwien.ac.at)
Indented code from above:
-- |Connect to remote 'EndPoint' and find all possible bindings for the
-- 'Variable's in the 'SelectQuery' action.
selectQuery :: Database.HSparql.Connection.EndPoint -> Query SelectQuery -> IO (Maybe [[BindingValue]])
selectQuery ep q = do
let uri = ep ++ "?" ++ urlEncodeVars [("query", createSelectQuery q)]
h1 = mkHeader HdrAccept "application/sparql-results+xml"
h2 = mkHeader HdrUserAgent "hsparql-client"
request = Request { rqURI = fromJust $ parseURI uri
, rqHeaders = [h1,h2]
, rqMethod = GET
, rqBody = (""::B.ByteString)
-- only string or bytestring has instances
-- possibly the other queries should be changed similarly
}
response <- simpleHTTP request >>= getResponseBody
-- af
-- putStrLn . unwords $ ["before structureContent bytestring", show response]
let response' = E.decodeUtf8 response
-- putStrLn . unwords $ ["before structureContent text", T.unpack response']
return $ structureContent response'