0

I'm trying to get a simple haskell program to talk to a MySQL database. The program builds properly, but when I run the program, I get about half of the output from the first query, and then the following error which I'm having difficulty interpreting:

SqlError {seState = "[]", seNativeError = -2, seErrorMsg = "sqlFetch: []"}

The program takes rows of labelled boxes of text from images out of a MySQL database and parses it into a fixed format.

query :: Option -> String -> IO SupplementalFacts
query op queryText = do
  conn <- connectODBC "DSN=imgparse"
  stmt <- prepare conn queryText
  execute stmt [] >> fetchRow stmt
  handle op stmt where
    unSQLString x = fromSql x :: String
    unSQLInteger x = fromSql x :: Integer
    unSQLRow (x:xs) = Ocr (unSQLString x) (locatize $ unSQLInteger <$> xs)
    handle option statement
      | option == Parsed = (fetchAllRows statement) >>= (\rows -> return $ parseTable $ unSQLRow <$> rows)


translit :: URL -> IO SupplementalFacts
translit u = query Parsed $ "SELECT description, x_1, y_1, x_3, y_3 FROM ocr_json_response where pic_url='" ++ u ++ "'"

parseTable :: [OcrRow] -> SupplementalFacts
...

with the app/Main.hs...

main :: IO ()
main = do
       translit url1 >>= (\x -> putStrLn $ show x)
       translit url2 >>= (\x -> putStrLn $ show x)
       translit url3 >>= (\x -> putStrLn $ show x)
       translit url4 >>= (\x -> putStrLn $ show x)
       return ()

The Main.hs is currently just set up for testing the execution of a sample url input.

Hopefully that's enough detail. I'm also still very much "climbing the haskell mountain", so feel free to make any suggestions on the code as well.

Ouyang Ze
  • 490
  • 4
  • 8
  • What happens when you use `fetchAllRows'` instead of `fetchAllRows`? – snak Jul 13 '19 at 06:50
  • That didn't work... I did end up getting this to work, by switching out the HDBC dependency to the mysql-haskell library. – Ouyang Ze Oct 28 '19 at 05:59

0 Answers0