mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
sqlite3: handle int type in Connection.timeout parameter (#7237)
This commit is contained in:
1 parent
1a4eb19550
commit
a6b06c80fd
3 files changed
+7
-6
No files matched your search
Vendored
-1
@@ -1928,7 +1928,6 @@ class MultiprocessTests(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
unlink(TESTFN)
|
||||
|
||||
@unittest.expectedFailure # TODO: RUSTPYTHON multiprocess test fails
|
||||
def test_ctx_mgr_rollback_if_commit_failed(self):
|
||||
# bpo-27334: ctx manager does not rollback if commit fails
|
||||
SCRIPT = f"""if 1:
|
||||
|
||||
-1
@@ -31,7 +31,6 @@ from .util import memory_database
|
||||
from .util import MemoryDatabaseMixin
|
||||
|
||||
|
||||
@unittest.skip("TODO: RUSTPYTHON timeout parameter does not accept int type")
|
||||
class TransactionTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# We can disable the busy handlers, since we control
|
||||
|
||||
@@ -61,7 +61,7 @@ mod _sqlite3 {
|
||||
},
|
||||
convert::IntoObject,
|
||||
function::{
|
||||
ArgCallable, ArgIterable, FsPath, FuncArgs, OptionalArg, PyComparisonValue,
|
||||
ArgCallable, ArgIterable, Either, FsPath, FuncArgs, OptionalArg, PyComparisonValue,
|
||||
PySetterValue,
|
||||
},
|
||||
object::{Traverse, TraverseFn},
|
||||
@@ -333,8 +333,8 @@ mod _sqlite3 {
|
||||
struct ConnectArgs {
|
||||
#[pyarg(any)]
|
||||
database: FsPath,
|
||||
#[pyarg(any, default = 5.0)]
|
||||
timeout: f64,
|
||||
#[pyarg(any, default = Either::A(5.0))]
|
||||
timeout: Either<f64, i64>,
|
||||
#[pyarg(any, default = 0)]
|
||||
detect_types: c_int,
|
||||
#[pyarg(any, default = Some(vm.ctx.empty_str.to_owned()))]
|
||||
@@ -991,7 +991,10 @@ mod _sqlite3 {
|
||||
fn initialize_db(args: &ConnectArgs, vm: &VirtualMachine) -> PyResult<Sqlite> {
|
||||
let path = args.database.to_cstring(vm)?;
|
||||
let db = Sqlite::from(SqliteRaw::open(path.as_ptr(), args.uri, vm)?);
|
||||
let timeout = (args.timeout * 1000.0) as c_int;
|
||||
let timeout = (match args.timeout {
|
||||
Either::A(float) => float,
|
||||
Either::B(int) => int as f64,
|
||||
} * 1000.0) as c_int;
|
||||
db.busy_timeout(timeout);
|
||||
if let Some(isolation_level) = &args.isolation_level {
|
||||
begin_statement_ptr_from_isolation_level(isolation_level, vm)?;
|
||||
|
||||
Reference in new issue
Block a user