首页 > 解决方案 > 带有 HDBC 的 Haskell SQLError

问题描述

我想读取一个包含多行的文件并将它们保存在我的表中。一切都很好,但是当它到达我第一行的最后一个元素时,它会以 SqlError 停止。

readLines :: FilePath -> IO ()
readLines n = 
do s <- readFile n
   mapM_ (\x -> insertbdd x $ lines s !! 1) [3..9]

insertbdd :: Int -> String -> IO ()
insertbdd _ [] = putStrLn "k"   -- pattern matching that doesn't work
insertbdd ng xs =
    do conn <- connectSqlite3 "ngram.db"
       stmt <- handleSqlError $ prepare conn "insert into n3 (seq) values (?)"
       execute stmt $ take 1 $ (map toSql) $ ngrams ng xs
       commit conn
       insertbdd ng (tail xs)

ngrams :: Int -> [a] -> [[a]]
ngrams n l = take (length l - (n - 1)) . map (take n) . tails $ l

停止与此消息

*** Exception: SqlError {seState = "", seNativeError = -1, seErrorMsg     = "In HDBC execute, received [] but expected 1 args."}

我写了很多不匹配的模式。

知道为什么会这样吗?

标签: haskell

解决方案


推荐阅读