尝试删除Haskell中的sqlite表时出错

时间:2019-02-16 15:38:43

标签: sqlite haskell sql-delete

尝试删除sqlite中的完整表格时遇到问题,有人可以帮我吗?

代码:

{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative
import Database.SQLite.Simple
import Database.SQLite.Simple.FromRow

data TestField = TestField Int String deriving (Show)

instance FromRow TestField where
fromRow = TestField <$> field <*> field

main :: IO()
main = do
conn <- open "db1.sqlite"
execute conn "DROP TABLE tabela"
close conn

返回错误:

delete.hs:14:3: error:
• Couldn't match expected type ‘IO a0’
              with actual type ‘q0 -> IO ()’
• Probable cause: ‘execute’ is applied to too few arguments
  In a stmt of a 'do' block: execute conn "DROP TABLE tabela"
  In the expression:
    do { conn <- open "db1.sqlite";
         execute conn "DROP TABLE tabela";
         close conn }
  In an equation for ‘main’:
      main
        = do { conn <- open "db1.sqlite";
               execute conn "DROP TABLE tabela";
               close conn }
      Failed, modules loaded: none.

1 个答案:

答案 0 :(得分:1)

execute需要查询参数。来自黑线船坞:

execute :: ToRow q => Connection -> Query -> q -> IO ()

尝试

execute conn "DROP TABLE tabela" ()