Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit 55012f6

Browse files
committed
forbid savepoints in legacy http
1 parent b5850bb commit 55012f6

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

sqld/src/http/user/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ fn parse_queries(queries: Vec<QueryObject>) -> crate::Result<Vec<Query>> {
9797
out.push(query);
9898
}
9999

100+
// It's too complicated to predict the state of a transaction with savepoints in legacy http,
101+
// forbid them instead.
102+
if out.iter().any(|q| q.stmt.kind.is_release() || q.stmt.kind.is_release()) {
103+
anyhow::bail!("savepoints are not supported in HTTP API, use hrana protocol instead");
104+
}
105+
100106
match predict_final_state(State::Init, out.iter().map(|q| &q.stmt)) {
101107
State::Txn => {
102108
return Err(Error::QueryError(

sqld/src/query_analysis.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,22 @@ impl StmtKind {
171171
},
172172
}
173173
}
174+
175+
/// Returns `true` if the stmt kind is [`Savepoint`].
176+
///
177+
/// [`Savepoint`]: StmtKind::Savepoint
178+
#[must_use]
179+
pub fn is_savepoint(&self) -> bool {
180+
matches!(self, Self::Savepoint)
181+
}
182+
183+
/// Returns `true` if the stmt kind is [`Release`].
184+
///
185+
/// [`Release`]: StmtKind::Release
186+
#[must_use]
187+
pub fn is_release(&self) -> bool {
188+
matches!(self, Self::Release)
189+
}
174190
}
175191

176192
/// The state of a transaction for a series of statement
@@ -191,7 +207,8 @@ impl State {
191207
(State::Txn, StmtKind::TxnEnd) => State::Init,
192208
(state, StmtKind::Other | StmtKind::Write | StmtKind::Read) => state,
193209
(State::Invalid, _) => State::Invalid,
194-
(State::Init, StmtKind::TxnBegin | ) => State::Txn,
210+
(State::Init, StmtKind::TxnBegin) => State::Txn,
211+
_ => State::Invalid,
195212
};
196213
}
197214

@@ -280,7 +297,7 @@ impl Statement {
280297
pub fn is_read_only(&self) -> bool {
281298
matches!(
282299
self.kind,
283-
StmtKind::Read | StmtKind::TxnEnd | StmtKind::TxnBegin
300+
StmtKind::Read | StmtKind::TxnEnd | StmtKind::TxnBegin | StmtKind::Release | StmtKind::Savepoint
284301
)
285302
}
286303
}

0 commit comments

Comments
 (0)