MySQL(MariaDB)にInsertしたいがMySQLDateTimeに引数が渡せない
HaskellでMySQLにInsertを実行したいがエラーになります。
型があっていないようですが、どのように記述したらよいのかわかりません。
発生している問題・エラーメッセージ
apo@debian:~/doc/project/make/haskell/mysql-haskell/my-project$ stack build my-project-0.1.0.0: unregistering (local file changes: app/Main.hs) my-project> configure (lib + exe) Configuring my-project-0.1.0.0... my-project> build (lib + exe) Preprocessing library for my-project-0.1.0.0.. Building library for my-project-0.1.0.0.. Preprocessing executable 'my-project-exe' for my-project-0.1.0.0.. Building executable 'my-project-exe' for my-project-0.1.0.0.. [2 of 2] Compiling Main /home/apo/doc/project/make/haskell/mysql-haskell/my-project/app/Main.hs:24:86: error: parse error on input ‘2020’ | 24 | executeStmt conn stmt [MySQLText "chris", MySQLText "comment", MySQLDateTime '2020/06/05 09:00:00'] | ^^^^ -- While building package my-project-0.1.0.0 using: /home/apo/.stack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_2.0.1.0_ghc-8.2.2 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-2.0.1.0 build lib:my-project exe:my-project-exe --ghc-options " -fdiagnostics-color=always" Process exited with code: ExitFailure 1
該当のソースコード
Haskell
1{-# LANGUAGE OverloadedStrings #-} 2 3module Main where 4 5import Lib 6import Control.Exception 7import Database.MySQL.Base 8import qualified System.IO.Streams as Streams 9 10transactional :: MySQLConn -> IO a -> IO a 11transactional conn procedure = mask $ \restore -> do 12 execute_ conn "BEGIN" 13 a <- restore procedure `onException` (execute_ conn "ROLLBACK") 14 execute_ conn "COMMIT" 15 pure a 16 17main :: IO () 18main = do 19 someFunc 20 conn <- connect 21 defaultConnectInfo {ciUser = "root", ciPassword = "password", ciDatabase = "test"} 22 stmt <- prepareStmt conn "INSERT INTO memos (name, comment, time) VALUES (?, ?, ?)" 23 transactional conn $ do 24 executeStmt conn stmt [MySQLText "chris", MySQLText "comment", MySQLDateTime '2020/06/05 09:00:00']
試したこと
時刻の記載の仕方が悪いと思い、色々試してみましたがだめでした。
executeStmt conn stmt [MySQLText "chris", MySQLText "comment", MySQLDateTime '2020-06-05 09:00:00'] executeStmt conn stmt [MySQLText "chris", MySQLText "comment", MySQLDateTime '2020-06-05 09:00:00.000001'] executeStmt conn stmt [MySQLText "chris", MySQLText "comment", MySQLDateTime '2020/06/05 09:00:00'] executeStmt conn stmt [MySQLText "chris", MySQLText "comment", MySQLDateTime '06/05/2020 09:00:00'] executeStmt conn stmt [MySQLText "chris", MySQLText "comment", MySQLDateTime '06-05-2020 09:00:00']
補足情報(FW/ツールのバージョンなど)
OS:Debian10
DataBase:mysql Ver 15.1 Distrib 10.3.22-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
Stack:Version 2.3.1
Resolver:lts-11.22
テーブルの定義
MariaDB [test]> show columns from memos; +---------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+----------------+ | id | mediumint(9) | NO | PRI | NULL | auto_increment | | name | char(30) | YES | | NULL | | | comment | char(50) | YES | | NULL | | | time | datetime | YES | | NULL | | +---------+--------------+------+-----+---------+----------------+
全てのソースコード
https://github.com/ringo-apo/mysql-haskell
参考にしたサイト
https://qiita.com/lotz/items/1d9c7b4333fd4d29a150
よろしくお願いします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/06/05 02:58