Commit Graph

353 Commits

Author SHA1 Message Date
Erlend Egeberg Aasland c4a69a4ad0
bpo-45828: Use unraisable exceptions within sqlite3 callbacks (FH-29591) 2021-11-29 15:22:32 +00:00
Erlend Egeberg Aasland 0920b61a0c
bpo-45512: Use Argument Clinic to set sqlite3 isolation level (GH-29593) 2021-11-18 18:18:09 +09:00
Dong-hee Na e002bbc6cc
bpo-45512: Simplify manage isolation level (GH-29562) 2021-11-17 21:47:02 +09:00
Erlend Egeberg Aasland 9d6215a54c
bpo-45126: Harden `sqlite3` connection initialisation (GH-28227) 2021-11-16 15:53:35 +01:00
Erlend Egeberg Aasland 822c3dcce3
bpo-45512: Raise exception if sqlite3.Connection.__init__ is called with bad isolation level (#29561)
* bpo-45512: Raise sqlite3.Connection.__init__ is called with bad isolation level

* Also explicitly test allowed isolation levels

* Use subTest for better error messages if something goes wrong

* Update Lib/test/test_sqlite3/test_dbapi.py

Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>

Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
2021-11-15 21:55:38 +09:00
Erlend Egeberg Aasland b567b9d74b
bpo-45512: Simplify isolation_level handling in `sqlite3` (GH-29053) 2021-11-15 16:50:59 +09:00
Erlend Egeberg Aasland c1323d4b8c
bpo-45754: Use correct SQLite limit when checking statement length (GH-29489) 2021-11-10 18:46:11 +00:00
Christian Heimes e9594f6747
bpo-45731: Handle --enable-loadable-sqlite-extensions in configure (GH-29434) 2021-11-06 10:30:37 +01:00
Erlend Egeberg Aasland c273986711
bpo-45613: Set `sqlite3.threadsafety` dynamically (GH-29227)
Use the compile-time selected default SQLite threaded mode to set the
DB-API 2.0 attribute 'threadsafety'

Mappings:
  - SQLITE_THREADSAFE=0 => threadsafety=0
  - SQLITE_THREADSAFE=1 => threadsafety=3
  - SQLITE_THREADSAFE=2 => threadsafety=1
2021-11-03 21:01:37 +00:00
Erlend Egeberg Aasland 456e27ac0a
bpo-24139: Add support for SQLite extended result codes (GH-28076) 2021-11-02 23:49:38 +00:00
Erlend Egeberg Aasland 401272e6e6
bpo-42064: Adapt `sqlite3` to multi-phase init (PEP 489) (GH-29234) 2021-11-02 16:35:51 +01:00
Erlend Egeberg Aasland b6b38a8226
bpo-45243: Add support for setting/getting `sqlite3` connection limits (GH-28463) 2021-11-01 22:50:53 +00:00
Erlend Egeberg Aasland 39b4d5938c
bpo-45634: Don't combine error checks when adding `sqlite3` int constants (GH-29251) 2021-10-31 19:01:19 +09:00
Erlend Egeberg Aasland e2e62b3808
bpo-45581: Raise `MemoryError` in `sqlite3.connect` if SQLite signals memory error (GH-29171) 2021-10-29 22:21:58 +02:00
Erlend Egeberg Aasland 8f24b7dbcb
bpo-42064: Convert `sqlite3` global state to module state (GH-29073) 2021-10-27 13:12:21 +02:00
Erlend Egeberg Aasland 09c04e7f0d
bpo-42064: Add module backref to `sqlite3` callback context (GH-28242) 2021-10-19 15:44:45 +02:00
Erlend Egeberg Aasland cfb1df3b71
bpo-44991: Normalise function and collation callback naming (GH-28209) 2021-10-12 13:38:49 +02:00
Victor Stinner d943d19172
bpo-45439: Move _PyObject_CallNoArgs() to pycore_call.h (GH-28895)
* Move _PyObject_CallNoArgs() to pycore_call.h (internal C API).
* _ssl, _sqlite and _testcapi extensions now call the public
  PyObject_CallNoArgs() function, rather than _PyObject_CallNoArgs().
* _lsprof extension is now built with Py_BUILD_CORE_MODULE macro
  defined to get access to internal _PyObject_CallNoArgs().
2021-10-12 08:38:19 +02:00
Victor Stinner ce3489cfdb
bpo-45439: Rename _PyObject_CallNoArg() to _PyObject_CallNoArgs() (GH-28891)
Fix typo in the private _PyObject_CallNoArg() function name: rename
it to _PyObject_CallNoArgs() to be consistent with the public
function PyObject_CallNoArgs().
2021-10-12 00:42:23 +02:00
Erlend Egeberg Aasland 3f2c433da5
bpo-45041: Restore `sqlite3` executescript behaviour for `SELECT` queries (GH-28509)
* bpo-45041: Restore sqlite3 executescript behaviour for select queries

* Add regression test
2021-10-07 10:16:45 +01:00
Erlend Egeberg Aasland 7b88f63e1d
bpo-44958: Revert GH-27844 (GH-28574)
This reverts commit 050d103595, but keeps
the tests.
2021-09-26 22:24:19 +01:00
Erlend Egeberg Aasland 050d103595
bpo-44958: Only reset `sqlite3` statements when needed (GH-27844) 2021-09-21 12:20:34 +01:00
Erlend Egeberg Aasland a6779715c4
bpo-45041: Simplify `sqlite3.Cursor.executescript()` (GH-28020) 2021-09-19 23:52:36 +01:00
Erlend Egeberg Aasland 771a546713
bpo-45040: Simplify sqlite3 transaction control functions (GH-28019) 2021-09-19 23:51:36 +01:00
Erlend Egeberg Aasland c78d5ca380
bpo-45126: Fix ref. leak in `sqlite3.Connection.__init__` (GH-28231) 2021-09-12 21:27:42 +09:00
Serhiy Storchaka 92bf8691fb
bpo-43413: Fix handling keyword arguments in subclasses of some buitin classes (GH-26456)
* Constructors of subclasses of some buitin classes (e.g. tuple, list,
  frozenset) no longer accept arbitrary keyword arguments.
* Subclass of set can now define a __new__() method with additional
  keyword parameters without overriding also __init__().
2021-09-12 13:27:50 +03:00
Erlend Egeberg Aasland 979336de34
bpo-42064: Pass module state to trace, progress, and authorizer callbacks (GH-27940)
- add print-or-clear traceback helper
- add helpers to clear and visit saved contexts
- modify callbacks to use the new callback_context struct
2021-09-07 15:06:17 +02:00
Erlend Egeberg Aasland 0474d06008
bpo-44991: Normalise `sqlite3` callback naming (GH-28088)
- all callbacks are now named xxx_callback
- normalise callable naming in set_*() functions
- normalise context argument naming in callbacks

The sqlite code is being "touched" in bpo-42064 (and related issues);
this style change makes it easier to work with and review.
2021-09-07 13:43:44 +02:00
Erlend Egeberg Aasland 65c5756be9
Remove unused macros from Modules/_sqlite/microprotocols.h (GH-28171) 2021-09-05 12:59:30 +09:00
Petr Viktorin 01dea5f12b
bpo-42064: Offset arguments for PyObject_Vectorcall in the _sqlite module (GH-27931)
This allows e.g. methods to be called efficiently by providing
space for a "self" argument; see PY_VECTORCALL_ARGUMENTS_OFFSET docs.
2021-08-31 14:34:44 +02:00
Erlend Egeberg Aasland 001ef4600f
bpo-44991: Make GIL handling more explicit in `sqlite3` callbacks (GH-27934)
- acquire the GIL at the very start[1]
- release the GIL at the very end

[1] The trace callback performs a sanity check before acquiring the GIL

Automerge-Triggered-By: GH:encukou
2021-08-31 05:18:43 -07:00
Erlend Egeberg Aasland 86d8b46523
bpo-16379: expose SQLite error codes and error names in `sqlite3` (GH-27786) 2021-08-30 19:32:21 +01:00
Erlend Egeberg Aasland a3c11cebf1
bpo-27334: Fix reference leak introduced by GH-26202 (GH-27942) 2021-08-25 15:57:54 +02:00
Erlend Egeberg Aasland 7ecd3425d4
bpo-27334: roll back transaction if sqlite3 context manager fails to commit (GH-26202)
Co-authored-by: Luca Citi
Co-authored-by: Berker Peksag <berker.peksag@gmail.com>
2021-08-25 11:59:42 +01:00
Erlend Egeberg Aasland 3df0fc89bc
bpo-44976: Lazy creation of sqlite3 result rows (GH-27884) 2021-08-25 11:28:47 +01:00
Erlend Egeberg Aasland 9ed523159c
bpo-42064: Pass module state to `sqlite3` UDF callbacks (GH-27456)
- Establish common callback context struct
- Convert UDF callbacks to fetch module state from callback context
2021-08-24 05:24:09 -07:00
Erlend Egeberg Aasland 6dd1cdb0cf
Remove unused UNKNOWN macros from cursor.h and prepare_protocol.h (GH-27885) 2021-08-22 22:23:45 +09:00
Erlend Egeberg Aasland 878e726701
bpo-44965: Early exit for non-DML statements in sqlite3.Cursor.executemany() (GH-27865) 2021-08-21 19:58:58 +01:00
Erlend Egeberg Aasland 243b6c3b8f
bpo-44079: Strip superfluous statement cache from sqlite3.Connection (GH-25998) 2021-08-19 00:37:53 +01:00
Serhiy Storchaka 0eec6276fd
bpo-44859: Improve error handling in sqlite3 and and raise more accurate exceptions. (GH-27654)
* MemoryError is now raised instead of sqlite3.Warning when
  memory is not enough for encoding a statement to UTF-8
  in Connection.__call__() and Cursor.execute().
* UnicodEncodeError is now raised instead of sqlite3.Warning when
  the statement contains surrogate characters
  in Connection.__call__() and Cursor.execute().
* TypeError is now raised instead of ValueError for non-string
  script argument in Cursor.executescript().
* ValueError is now raised for script containing the null
  character instead of truncating it in Cursor.executescript().
* Correctly handle exceptions raised when getting boolean value
  of the result of the progress handler.
* Add many tests covering different corner cases.

Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
2021-08-08 08:49:44 +03:00
Serhiy Storchaka 7d747f26e6
bpo-44839: Raise more specific errors in sqlite3 (GH-27613)
MemoryError raised in user-defined functions will now preserve
its type. OverflowError will now be converted to DataError.
Previously both were converted to OperationalError.
2021-08-06 21:28:47 +03:00
Erlend Egeberg Aasland 8f010dc920
bpo-44822: Don't truncate `str`s with embedded NULL chars returned by `sqlite3` UDF callbacks (GH-27588) 2021-08-05 10:22:08 +03:00
Erlend Egeberg Aasland 2d34664051
bpo-31746: Fix broken call in GH-27431 (GH-27464) 2021-07-29 21:47:23 +01:00
Erlend Egeberg Aasland 7e311e496b
bpo-31746: Prevent segfaults when sqlite3.Connection is uninitialised (GH-27431) 2021-07-29 20:45:32 +01:00
Erlend Egeberg Aasland d542742128
bpo-42064: Optimise `sqlite3` state access, part 1 (GH-27273)
Prepare for module state:

- Add "get state by defining class" and "get state by module def" stubs
- Add AC defining class when needed
- Add state pointer to connection context
- Pass state as argument to utility functions

Automerge-Triggered-By: GH:encukou
2021-07-29 02:21:45 -07:00
Erlend Egeberg Aasland 5269c09145
bpo-44688: Remove ASCII limitation from `sqlite3` collation names (GH-27395) 2021-07-29 09:47:56 +02:00
Erlend Egeberg Aasland 890e22957d
bpo-42064: Migrate to `sqlite3_create_collation_v2` (GH-27156)
This implies that SQLite now takes care of destroying the callback
context (the PyObject callable it has been passed), so we can strip the
collation dict from the connection object.
2021-07-27 15:54:20 +02:00
Erlend Egeberg Aasland 4c0deb25ac
bpo-42064: Finalise establishing sqlite3 global state (GH-27155)
With this, all sqlite3 static globals have been moved to the global state.
There are a couple of global static strings left, but there should be no need for adding them to the state.

https://bugs.python.org/issue42064
2021-07-20 12:59:18 +02:00
Erlend Egeberg Aasland 5007a4f23c
bpo-44641: Use vectorcall in sqlite3 collation callback (GH-27158) 2021-07-15 16:49:14 +01:00
Erlend Egeberg Aasland 81b8c0a385
Fix docstring typo in sqlite3.Connection.executescript/sqlite3.Cursor.executescript (GH-27147)
Both `executescript` methods contain the same docstring typo:
_"Executes a multiple SQL statements at once."_ => _"Executes multiple SQL statements at once."_

Automerge-Triggered-By: GH:pablogsal
2021-07-14 14:54:37 -07:00