尝试删除 haskell 中的 sqlite table 时出错
Error while trying to delete a sqlite table in haskell
我在 sqlite 中尝试删除完整的 table 时遇到问题,有人可以帮我吗?
代码:
{-# 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.
execute
需要查询参数。来自黑线鳕:
execute :: ToRow q => Connection -> Query -> q -> IO ()
尝试
execute conn "DROP TABLE tabela" ()
我在 sqlite 中尝试删除完整的 table 时遇到问题,有人可以帮我吗?
代码:
{-# 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.
execute
需要查询参数。来自黑线鳕:
execute :: ToRow q => Connection -> Query -> q -> IO ()
尝试
execute conn "DROP TABLE tabela" ()