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

Commit d095251

Browse files
committed
forbid savepoints in legacy http
1 parent d511206 commit d095251

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

sqld/src/http/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ fn parse_queries(queries: Vec<QueryObject>) -> anyhow::Result<Vec<Query>> {
100100
out.push(query);
101101
}
102102

103+
// The state of a batch is unpredictable with savepoints, it's easier to just disable them in
104+
// legacy API
105+
if out.iter().any(|q| q.stmt.kind.is_savepoint() || q.stmt.kind.is_release()) {
106+
anyhow::bail!("savepoints not supported in legacy HTTP API, use hrana endpoint instead");
107+
}
108+
103109
match predict_final_state(State::Init, out.iter().map(|q| &q.stmt)) {
104110
State::Txn => anyhow::bail!("interactive transaction not allowed in HTTP queries"),
105111
State::Init => (),

sqld/src/query_analysis.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,22 @@ impl StmtKind {
164164
},
165165
}
166166
}
167+
168+
/// Returns `true` if the stmt kind is [`Savepoint`].
169+
///
170+
/// [`Savepoint`]: StmtKind::Savepoint
171+
#[must_use]
172+
pub fn is_savepoint(&self) -> bool {
173+
matches!(self, Self::Savepoint)
174+
}
175+
176+
/// Returns `true` if the stmt kind is [`Release`].
177+
///
178+
/// [`Release`]: StmtKind::Release
179+
#[must_use]
180+
pub fn is_release(&self) -> bool {
181+
matches!(self, Self::Release)
182+
}
167183
}
168184

169185
/// The state of a transaction for a series of statement
@@ -184,7 +200,8 @@ impl State {
184200
(State::Txn, StmtKind::TxnEnd) => State::Init,
185201
(state, StmtKind::Other | StmtKind::Write | StmtKind::Read) => state,
186202
(State::Invalid, _) => State::Invalid,
187-
(State::Init, StmtKind::TxnBegin | ) => State::Txn,
203+
(State::Init, StmtKind::TxnBegin) => State::Txn,
204+
_ => State::Invalid,
188205
};
189206
}
190207

@@ -273,7 +290,7 @@ impl Statement {
273290
pub fn is_read_only(&self) -> bool {
274291
matches!(
275292
self.kind,
276-
StmtKind::Read | StmtKind::TxnEnd | StmtKind::TxnBegin
293+
StmtKind::Read | StmtKind::TxnEnd | StmtKind::TxnBegin | StmtKind::Release | StmtKind::Savepoint
277294
)
278295
}
279296
}

0 commit comments

Comments
 (0)