Visitar URL original
bpo-45243: Add support for setting/getting `sqlite3` connection limits by erlend-aasland · Pull Request #28463 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Raise ProgrammingError if limit is out of bounds
  • Loading branch information
Erlend E. Aasland
Erlend E. Aasland committed Oct 7, 2021
commit e093a993244c8d41850b2cace576f61c17b9e882
6 changes: 6 additions & 0 deletions Lib/sqlite3/test/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ def test_connection_limits(self):
finally: # restore old limit
self.cx.setlimit(param, ret1)

def test_connection_set_bad_limit(self):
self.assertRaisesRegex(
sqlite.ProgrammingError, "'limit' is out of bounds",
self.cx.setlimit, 1111, 0
)


class UninitialisedConnectionTests(unittest.TestCase):
def setUp(self):
Expand Down
4 changes: 4 additions & 0 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1892,6 +1892,10 @@ setlimit_impl(pysqlite_Connection *self, int limit, int value)
}

int previous_value = sqlite3_limit(self->db, limit, value);
if (previous_value < 0) {
PyErr_SetString(self->ProgrammingError, "'limit' is out of bounds");
return NULL;
}
return PyLong_FromLong(previous_value);
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
}

Expand Down