与HDBC的Haskell SQLError

时间:2018-05-21 14:03:33

标签: haskell

我想读取包含许多行的文件,并希望将它们保存在我的表中。 一切都很好但是当它到达我的第一行的最后一个元素时,它会以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."}

我想了许多不匹配的模式。

知道为什么会这样吗?

0 个答案:

没有答案