使用导入HDBC-sqlite3,HDBC和文本。 在Main.hs中有此(部分)代码
insertClient :: IO ()
insertClient = do
newClient <- createClient
socket <- connectSqlite3 "cllist.db"
run socket "INSERT INTO client (cl_name,cl_form,cl_street,cl_no) VALUES (?,?,?,?)"
[ toSql ((newClient !! 0) :: String)
, toSql ((newClient !! 1) :: String)
, toSql ((newClient !! 2) :: String)
, toSql ((read (newClient !! 3)) :: Int)
]
-- let usingLens = newClient ^? element 2 -- returns maybe cannot explode like '!!'
commit socket
disconnect socket
putStrLn "Data successfully committed to database."
,并将此代码导入到名为“ HDBC-Prepper.hs”的导入中:
createClient :: IO [String]
createClient = do
putStr "Name: "; name <- getLine
putStr "Form: "; form <- getLine
putStr "Address: "; address <- getLine
putStr "Number: "; number <- getLine
return ([name,form, address, number])
当我在GHCi所有不错的工作文件中运行它时,当运行堆栈exec时,它将首先运行getLine
命令并附加putStr
。如果您知道何时输入,这不是什么大问题,但我对原因感到好奇。