Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

german special characters in select queries #8

Open
andrewufrank opened this issue Feb 16, 2014 · 1 comment
Open

german special characters in select queries #8

andrewufrank opened this issue Feb 16, 2014 · 1 comment

Comments

@andrewufrank
Copy link

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)

@futpib
Copy link

futpib commented Nov 10, 2018

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants