事务保存点

This commit is contained in:
LIm1tZz7 committed 2026-10-03 19:12:11 +08:00
1 parent 85008895dd
commit e2997627a7
10 files changed
+171 -6

No files matched your search

@@ -137,6 +137,9 @@ runStatementUncheckedM _ ShowDatabases = runStatementM ShowDatabases
runStatementUncheckedM _ BeginTransaction = pure (Left "BEGIN is executed by the session")
runStatementUncheckedM _ CommitTransaction = pure (Left "COMMIT is executed by the session")
runStatementUncheckedM _ RollbackTransaction = pure (Left "ROLLBACK is executed by the session")
runStatementUncheckedM _ Savepoint{} = pure (Left "SAVEPOINT is executed by the session")
runStatementUncheckedM _ RollbackToSavepoint{} = pure (Left "ROLLBACK TO is executed by the session")
runStatementUncheckedM _ ReleaseSavepoint{} = pure (Left "RELEASE is executed by the session")
-- | 只有需要读全表才能判断约束时才扫表
existingRows :: (MonadStorage m) => String -> Table -> m (Either String [Row])
@@ -437,6 +437,10 @@ checkResolvedWith db outer q = case q of
BeginTransaction -> Right ()
CommitTransaction -> Right ()
RollbackTransaction -> Right ()
-- | 保存点名字只是会话层的记号,不做列检查
Savepoint _ -> Right ()
RollbackToSavepoint _ -> Right ()
ReleaseSavepoint _ -> Right ()
where
tableCols' = map fst . tableCols
@@ -59,6 +59,12 @@ data Statement
| CommitTransaction
-- | 回滚事务
| RollbackTransaction
-- | 建保存点:SAVEPOINT 名字
| Savepoint String
-- | 回滚到保存点:ROLLBACK TO [SAVEPOINT] 名字
| RollbackToSavepoint String
-- | 释放保存点:RELEASE [SAVEPOINT] 名字
| ReleaseSavepoint String
deriving (Show, Eq)
-- | 连接类型:内连接与左外连接
@@ -619,7 +619,14 @@ transactionStatement =
try (BeginTransaction <$ (keyword "start" *> keyword "transaction"))
<|> (BeginTransaction <$ (keyword "begin" *> optional (keyword "transaction")))
<|> (CommitTransaction <$ (keyword "commit" *> optional (keyword "transaction")))
<|> try (RollbackToSavepoint <$> rollbackToName)
<|> (RollbackTransaction <$ (keyword "rollback" *> optional (keyword "transaction")))
<|> (Savepoint <$> (keyword "savepoint" *> identifier))
<|> (ReleaseSavepoint <$> (keyword "release" *> optional (keyword "savepoint") *> identifier))
where
-- | ROLLBACK TO [SAVEPOINT] 名字
rollbackToName =
keyword "rollback" *> keyword "to" *> optional (keyword "savepoint") *> identifier
-- | 解析总入口
parseStatement :: String -> Either String Statement