41 Commits

Author SHA1 Message Date
Jiseok CHOI
ce79cd4853 sqlite3: fix Blob.__setitem__ value range validation (#7981)
* sqlite3: fix Blob.__setitem__ value range validation

Previously, assigning an out-of-range integer (negative or > 255) or an
integer too large for i64 (e.g. 2**65) to a Blob index raised OverflowError
instead of ValueError.

Mirror CPython's ass_subscript_index logic:
- Convert the value via to_i64(), treating any overflow as -1
- Validate the result is in [0, 255], raising ValueError("byte must be in range(0, 256)") otherwise
- Separate deletion error messages: "item deletion" for index, "slice deletion" for slice

* sqlite3: fix Blob.__setitem__ negative-step slice write

In the step != 1 branch of Blob.ass_subscript, the loop used
  i_in_temp += step as usize
where step is isize. For negative steps (e.g. step = -2),
  (-2isize) as usize = 18446744073709551614
causing an out-of-bounds panic whenever slice_len >= 2.

Fix: use SaturatedSliceIter (already used by the read path) to iterate
over the correct absolute blob indices, then map each index back to a
temp buffer offset via abs_idx - range_start.

Also fix a Clippy lint: replace
  val < 0 || val > 255
with the idiomatic
  !(0..=255).contains(&val)

Add a regression test in extra_tests/snippets/stdlib_sqlite.py that
exercises blob[9:0:-2] (negative step, slice_len=5).

* fix: guard blob negative-step snippet from CPython 3.11 bug

* style: add blank line after import sys in stdlib_sqlite snippet (ruff)

* Update extra_tests/snippets/stdlib_sqlite.py

---------

Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2026-05-27 16:40:05 +09:00
Jiseok CHOI
430eb5ffe4 Fix sqlite3 Cursor.fetchmany to not fetch rows when size=0 (#7425) 2026-03-14 15:49:55 +09:00
Jiseok CHOI
7b7c7a1b6e sqlite3: add Cursor.row_factory pygetset and fix Connection.cursor() propagation (#7278)
Add #[pygetset] getter/setter for Cursor.row_factory so that Python-level
attribute access reads/writes the Rust struct field instead of the
instance dict.

Fix Connection.cursor() to only propagate the connection's row_factory
to the cursor when the connection's row_factory is not None, matching
CPython behavior. Previously it unconditionally overwrote the cursor's
row_factory, discarding any factory set by a cursor subclass __init__.
2026-03-01 10:44:50 +09:00
Jiseok CHOI
81acb9b7c1 sqlite3: handle int type in Connection.timeout parameter (#7237) 2026-02-28 10:38:30 +09:00
Jiseok CHOI
c5472e2a4e sqlite3: reject negative fetchmany values (#7240) 2026-02-27 21:03:40 +09:00
Jiseok CHOI
f7fe9c53cb sqlite3: reject negative arraysize values (#7238) 2026-02-27 20:59:15 +09:00
Jiseok CHOI
00440b179a Update sqlite3 and the tests to CPython 3.14.2 (#6787)
* Update sqlite3, dbm.sqlite3 and tests to CPython 3.14.2

* Add skip decorators for failing sqlite3 tests

Skip tests that fail due to unimplemented features or behavior differences:
- _iterdump not implemented (test_dump.py)
- Unraisable exception handling not implemented (test_hooks.py, test_userfunctions.py)
- Keyword-only arguments not supported for various methods
- Autocommit behavior differences (test_transactions.py)
- TransactionTests skipped due to timeout parameter type issue
- Various error message differences (test_dbapi.py)
- SQLITE_DBCONFIG constants not implemented
- Row and Connection signature inspection issues

All tests now pass with 95 skipped out of 493 total tests.

* Change @unittest.skip to @unittest.expectedFailure per code review

- Convert @unittest.skip decorators to @unittest.expectedFailure for tests that fail without panic/hang
- Keep @unittest.skip only for TransactionTests class (setUp fails with timeout=0 int type)

* fixup
2026-01-19 02:45:47 +09:00
Jiseok CHOI
050db4725f sqlite3: fix Connection.cursor() factory argument handling (#6783)
Fix test_is_instance in CursorFactoryTests by properly handling the
factory argument in Connection.cursor() method. Now the factory can
be passed as both positional and keyword argument, and returns the
correct subclass type instead of always returning PyRef<Cursor>.

- Use FromArgs derive macro with CursorArgs struct for argument parsing
- Return PyObjectRef instead of PyRef<Cursor> to allow subclasses
- Use fast_issubclass to validate returned cursor is a Cursor subclass
- Properly differentiate between 'no argument' and 'None passed'
2026-01-18 23:37:47 +09:00
Terry Tianlin Luan
609dbb1439 Downgraded skips in tests (#6716)
* Downgraded skips in tests

* Fixed failing tests

* Fixed test_ftplib + test_socket + test_ssl + test_threaded_import failures

* Removed comments about which tests are run in which environment

* Addressed PR comments

* Annotated skips on failing tests

* Removed unneeded tests

* Removed unneeded sys import from test_ftplib

* Added annotation to test_ftplib

* Readded skipIf to test_cleanup_with_symlink_modes with a more general ENV_POLLUTING_TESTS_WINDOWS

* Addressed PR comments

* Made changes to minimize diff in PR

* Apply suggestion from @youknowone

---------

Co-authored-by: Jeong, YunWon <69878+youknowone@users.noreply.github.com>
2026-01-15 21:43:22 +09:00
Jeong, YunWon
527111bc98 PyWrapperDescrObject and rewrite toggle_slot (#6536)
* SlotFunc

* slotdef

* unify slots

* remove unsed slots
2025-12-28 11:44:36 +09:00
Jiseok CHOI
a14dd5921d fix(sqlite): Raise ProgrammingError when operating on a closed cursor (#6339) 2025-12-08 00:14:31 +09:00
Jiseok CHOI
a9469a20d5 Fix sqlite connection reinitialization (#6288)
* Fix sqlite connection reinitialization

* Align sqlite connection reinit with CPython

* Enable sqlite test_connection_bad_reinit

* Fix sqlite reinit flag without threading

* Use stronger memory ordering for initialized flag synchronization
2025-11-22 22:13:06 +09:00
Jiseok CHOI
567fb4dec0 fix(sqlite): raise ProgrammingError when operating on a blob with a closed connection, (#6286)
Fixed #6285
2025-11-22 20:42:24 +09:00
Jiseok CHOI
2faa05dcfb Fix sqlite Connection initialization check (#6199)
* Fix sqlite3 Connection initialization check

Add proper __init__ validation for sqlite3.Connection to ensure base class
__init__ is called before using connection methods. This fixes the
test_connection_constructor_call_check test case.

Changes:
- Modified Connection.py_new to detect subclassing
- For base Connection class, initialization happens immediately in py_new
- For subclassed Connection, db is initialized as None
- Added __init__ method that performs actual database initialization
- Updated _db_lock error message to match CPython: 'Base Connection.__init__ not called.'

This ensures CPython compatibility where attempting to use a Connection
subclass instance without calling the base __init__ raises ProgrammingError.

* use Initializer trait
2025-10-21 11:11:31 +09:00
Jiseok CHOI
25a464eeae Fix sqlite3 Cursor initialization check (#6198)
Add proper __init__ validation for sqlite3.Cursor to ensure base class
__init__ is called before using cursor methods. This fixes the
test_cursor_constructor_call_check test case.

Changes:
- Modified Cursor to initialize with inner=None in py_new
- Added explicit __init__ method that sets up CursorInner
- Updated close() method to check for uninitialized state
- Changed error message to match CPython: 'Base Cursor.__init__ not called.'

This ensures CPython compatibility where attempting to use a Cursor
instance without calling the base __init__ raises ProgrammingError.
2025-10-21 09:33:55 +09:00
Jiseok CHOI
a2b194a6f8 sqlite3: Support 'size' keyword argument in Cursor::fetchmany 2025-09-01 15:23:04 +09:00
Jiseok CHOI
e909e32f31 sqlite: Fix missing ProgrammingError for parameter mismatch (#6104) 2025-08-21 13:19:38 +09:00
Jiseok CHOI
a58d582001 Implement unsupported ops for sqlite3.Blob (#6066) 2025-08-05 17:53:06 +09:00
Jiseok CHOI
b2d6594bd9 Prevent direct instantiation of sqlite3.{Statement,Blob} 2025-08-01 13:39:45 +09:00
Jiseok CHOI
1e6da5f430 sqlite: Align Connection.__call__ error handling with CPython (#6042) 2025-07-30 14:05:17 +09:00
Jiseok CHOI
d8f1d188c3 stdlib(sqlite): Raise ProgrammingError in closed Blob context manager (#6041) 2025-07-27 21:47:05 +09:00
Jiseok CHOI
38ca076cb5 feat(stdlib/sqlite): Implement slice assignment for Blob (#6039) 2025-07-27 10:43:11 +09:00
Jiseok CHOI
fb9147736d stdlib(sqlite3): Raise ProgrammingError for missing named parameter (#6036) 2025-07-25 19:02:56 +09:00
Jiseok CHOI
bcf56279ec Raise UnicodeEncodeError for surrogates in sqlite.executescript (#6024) 2025-07-25 10:45:33 +09:00
Jiseok CHOI
57bdf35ee6 Enforce valid UTF-8 encoding for sqlite collation names (#6015)
* Make public `PyStr::ensure_valid_utf8`

* Enforce valid UTF-8 encoding for sqlite collation names
2025-07-21 23:42:47 +09:00
Jiseok CHOI
bbe98ddd86 Construct detailed message on text decode failure (#6014) 2025-07-21 22:33:09 +09:00
Jiseok CHOI
6f80ac0edd Align SQL comment parsing with CPython (#5996) 2025-07-20 10:51:42 +09:00
Jiseok CHOI
f8d03fd680 Correctly implement isolation_level setter to handle deletion (#5983) 2025-07-18 23:08:51 +09:00
Jiseok CHOI
5957f5d31a Fix off-by-one error in SQL length limit check (#5982) 2025-07-16 01:53:20 +09:00
Jiseok CHOI
f465af3a7c Reject SQL queries containing null characters (#5981) 2025-07-16 01:52:28 +09:00
Jiseok CHOI
6d2152cafe Correctly handle None for protocol in adapt(..) (#5979) 2025-07-16 01:49:53 +09:00
Jiseok CHOI
ed433837b3 Introduce PyUtf8Str and fix(sqlite): validate surrogates in SQL statements (#5969)
* fix(sqlite): validate surrogates in SQL statements

* Add `PyUtf8Str` wrapper for safe conversion
2025-07-15 00:54:42 +09:00
Jiseok CHOI
5ab64b7002 fix(sqlite): align adaptation protocol with CPython (#5964) 2025-07-14 14:22:52 +09:00
Jiseok CHOI
d42e8f0042 fix(sqlite): produce correct error for surrogate characters (#5962) 2025-07-14 14:21:36 +09:00
Jiseok CHOI
3a6a766a03 fix(sqlite): implement PARSE_COLNAMES column name parsing (#5923) 2025-07-10 00:18:40 +09:00
Jiseok CHOI
e6fdef43dc fix(sqlite): autocommit mode transaction handling to match CPython (#5918) 2025-07-09 20:13:26 +09:00
Jiseok CHOI
341341520e Fix SQLite large integer overflow error handling (#5916) 2025-07-09 17:14:45 +09:00
Ashwin Naren
b81ae9b954 More cspell fixes (#5670) 2025-04-11 09:37:20 +09:00
Noa
a86126419c Fix remaining tests 2025-03-25 19:05:12 -05:00
Lee Dogeon
1fa69ebcc9 sqlite: Throw TypeError when callable is not callable (#4923) 2023-04-22 07:10:44 +09:00
Steve Shi
765933136c Implement Sqlite3 Module (#4260)
* add supporting for PyAtomic<PyObject>

* create sqlite module

* add dependency sqlite3-sys

* add module constants

* import sqlite3 from cpython

* adjust lib

* add module structure

* impl Connection.cursor

* add module exceptions

* impl lstrip_sql

* impl statement new

* wip cursor.execute

* wip cursor

* wip error to exception

* add SqliteRaw and SqliteStatementRaw

* impl statement parameters binding

* wip cursor.execute

* add test_sqlite

* impl closeable connection

* impl closeable cursor

* impl cursor.executemany

* impl cursor.executescript

* impl cursor.fetch*

* impl connection.backup

* stage 1

* add support connection.backup with progress

* fix backup deadlock

* support changable isolation_level

* impl converter

* impl adapter

* impl text_factory and blob

* impl create_function

* impl create_function 2

* fix empty statement

* impl blob support

* impl create_aggregate

* impl create_aggregate 2

* refactor create_*

* impl enable_callback_traceback

* impl create_collation

* refactor create_* with CallbackData

* fix text and blob use SQLITE_TRANSIENT

* fix str to SQLITE_TEXT

* impl thread check

* impl Connection Factory

* impl busy timeout

* shift sqlite3-sys -> libsqlite3-sys

* refactor CallbackData

* impl create_window_function

* refactor callback functions

* add module attr converters

* fix nullable isolation_level

* add module attr adapters

* fix nullable adapt proto

* impl set_authorizer

* impl trace_callback

* impl set_progress_handler

* impl cancellable sqlite function*

* impl attributes for Connection

* fix some failed tests

* impl Row

* impl Blob methods

* impl Blob subscript & ass_subscript

* pass tests

* rebase

* no sqlite for wasm

* use ThreadId instead u64

* no libsqlite3-sys for wasm

* fix into_cstring for all platform

* fixup

* rebase

* fix windows into_bytes

* disable sqlite for android

* fixup
2023-01-07 22:03:24 +02:00