我正在尝试获取一个简单的haskell程序来与MySQL数据库对话。该程序正确构建,但是当我运行该程序时,我从第一个查询中获得了大约一半的输出,然后得到了我难以解释的以下错误:
SqlError {seState = "[]", seNativeError = -2, seErrorMsg = "sqlFetch: []"}
该程序从MySQL数据库中的图像中获取带有标签的文本行,并将其解析为固定格式。
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
...
使用应用程序/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 ()
Main.hs当前仅用于测试示例URL输入的执行情况。
希望这足够详细。我也仍然非常“攀登Haskell山”,因此也随时可以对代码提出建议。