是否可以在Haskell Sqlite3触发器中具有IF条件?

时间:2013-12-30 20:23:44

标签: haskell if-statement triggers sqlite

是否可以以包含if条件的方式修改以下HDBC和Sqlite 3触发器?在满足条件时,只应执行UPDATE语句

calculateNoOfStocksTraded::String->Database.HDBC.Sqlite3.Connection->IO ()
calculateNoOfStocksTraded code conn=do                                                                               
                                    run conn " CREATE TRIGGER calcStocks \
                                               \ AFTER INSERT ON historicalData \
                                               \ FOR EACH ROW \
                                               \ BEGIN \
                                               \ UPDATE company \
                                               \ SET noOfStocks=(SELECT SUM(volume) FROM historicalData  WHERE companyCode= ? ); \
                                               \ END; " [toSql code]

                                    commit conn

1 个答案:

答案 0 :(得分:1)

你的逻辑应该是这样的:

someCondition :: Maybe String
someCondition = if undefined -- define your condition here
                then "SQL UPDATE QUERY 1"
                else "SQL UPDATE QUERY 2"

calculateNoOfStocksTraded::String-> Database.HDBC.Sqlite3.Connection->IO ()
calculateNoOfStocksTraded code conn = do run conn query [toSql code]
                                         commit conn
    where query = someCondition