mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-03 08:24:19 +01:00
ext/python: Partially implements commit()
It was based on https://docs.python.org/3/library/sqlite3.html but some more work is needed specially in LEGACY_TRANSACTION_CONTROL and isolation levels. See: https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.autocommit
This commit is contained in:
@@ -215,6 +215,13 @@ fn stmt_is_ddl(sql: &str) -> bool {
|
||||
sql.starts_with("CREATE") || sql.starts_with("ALTER") || sql.starts_with("DROP")
|
||||
}
|
||||
|
||||
#[pyclass(unsendable)]
|
||||
#[derive(Clone)]
|
||||
pub struct Connection {
|
||||
conn: Rc<limbo_core::Connection>,
|
||||
io: Arc<dyn limbo_core::IO>,
|
||||
}
|
||||
|
||||
#[pymethods]
|
||||
impl Connection {
|
||||
pub fn cursor(&self) -> Result<Cursor> {
|
||||
@@ -232,9 +239,16 @@ impl Connection {
|
||||
}
|
||||
|
||||
pub fn commit(&self) -> PyResult<()> {
|
||||
Err(PyErr::new::<NotSupportedError, _>(
|
||||
"Transactions are not supported in this version",
|
||||
))
|
||||
if !self.conn.get_auto_commit() {
|
||||
self.conn.execute("COMMIT").map_err(|e| {
|
||||
PyErr::new::<OperationalError, _>(format!("Failed to commit: {:?}", e))
|
||||
})?;
|
||||
|
||||
self.conn.execute("BEGIN").map_err(|e| {
|
||||
PyErr::new::<OperationalError, _>(format!("Failed to commit: {:?}", e))
|
||||
})?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn rollback(&self) -> PyResult<()> {
|
||||
|
||||
Reference in New Issue
Block a user