| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,6 +120,21 @@ def test_collation_register_twice(self): | |||
| 120 | 120 | self.assertEqual(result[0][0], 'b') | |
| 121 | 121 | self.assertEqual(result[1][0], 'a') | |
| 122 | 122 | ||
| 123 | + def test_collation_register_when_busy(self): | ||
| 124 | + # See https://github.com/python/cpython/issues/146090. | ||
| 125 | + con = self.con | ||
| 126 | + con.create_collation("mycoll", lambda x, y: (x > y) - (x < y)) | ||
| 127 | + con.execute("CREATE TABLE t(x TEXT)") | ||
| 128 | + con.execute("INSERT INTO t VALUES (?)", ("a",)) | ||
| 129 | + con.execute("INSERT INTO t VALUES (?)", ("b",)) | ||
| 130 | + con.commit() | ||
| 131 | + | ||
| 132 | + cursor = self.con.execute("SELECT x FROM t ORDER BY x COLLATE mycoll") | ||
| 133 | + next(cursor) | ||
| 134 | + # Replace the collation while the statement is active -> SQLITE_BUSY. | ||
| 135 | + with self.assertRaises(sqlite.OperationalError) as cm: | ||
| 136 | + self.con.create_collation("mycoll", lambda a, b: 0) | ||
| 137 | + | ||
| 123 | 138 | def test_deregister_collation(self): | |
| 124 | 139 | """ | |
| 125 | 140 | Register a collation, then deregister it. Make sure an error is raised if we try | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + :mod:`sqlite3`: properly raise :exc:`MemoryError` instead of :exc:`SystemError` | ||
| 2 | + when a context callback fails to be allocated. Patch by Bénédikt Tran. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + :mod:`sqlite3`: fix a crash when :meth:`sqlite3.Connection.create_collation` | ||
| 2 | + fails with `SQLITE_BUSY <https://sqlite.org/rescode.html#busy>`__. Patch by | ||
| 3 | + Bénédikt Tran. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1059,13 +1059,16 @@ static callback_context * | |||
| 1059 | 1059 | create_callback_context(PyTypeObject *cls, PyObject *callable) | |
| 1060 | 1060 | { | |
| 1061 | 1061 | callback_context *ctx = PyMem_Malloc(sizeof(callback_context)); | |
| 1062 | - if (ctx != NULL) { | ||
| 1063 | - PyObject *module = PyType_GetModule(cls); | ||
| 1064 | - ctx->refcount = 1; | ||
| 1065 | - ctx->callable = Py_NewRef(callable); | ||
| 1066 | - ctx->module = Py_NewRef(module); | ||
| 1067 | - ctx->state = pysqlite_get_state(module); | ||
| 1062 | + if (ctx == NULL) { | ||
| 1063 | + PyErr_NoMemory(); | ||
| 1064 | + return NULL; | ||
| 1068 | 1065 | } | |
| 1066 | + | ||
| 1067 | + PyObject *module = PyType_GetModule(cls); | ||
| 1068 | + ctx->refcount = 1; | ||
| 1069 | + ctx->callable = Py_NewRef(callable); | ||
| 1070 | + ctx->module = Py_NewRef(module); | ||
| 1071 | + ctx->state = pysqlite_get_state(module); | ||
| 1069 | 1072 | return ctx; | |
| 1070 | 1073 | } | |
| 1071 | 1074 | ||
@@ -2198,7 +2201,7 @@ pysqlite_connection_create_collation_impl(pysqlite_Connection *self, | |||
| 2198 | 2201 | * the context before returning. | |
| 2199 | 2202 | */ | |
| 2200 | 2203 | if (callable != Py_None) { | |
| 2201 | - free_callback_context(ctx); | ||
| 2204 | + decref_callback_context(ctx); | ||
| 2202 | 2205 | } | |
| 2203 | 2206 | set_error_from_db(self->state, self->db); | |
| 2204 | 2207 | return NULL; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments