-
-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support STRICT tables #344
Comments
From that page:
|
I'm going to build my own |
This worked:
This gave me a file here:
That wheel only works when installed for Python 3.9 (it failed to install in a Python 3.10 virtual environment) - but >>> import pysqlite3
>>> pysqlite3.connect(":memory:").execute("select sqlite_version()").fetchall()
[('3.37.0',)] And if I install
|
There are a few places that the
I'll definitely implement the first one, and likely the second one too. I'm on the fence with regards to the third one. |
What should happen if you attempt to use An obvious error would be best... but how about silently ignoring it on older versions instead? That would match how we handle sqlite-utils/sqlite_utils/db.py Lines 372 to 380 in 1267037
sqlite-utils/tests/test_register_function.py Lines 34 to 37 in 93c7fd9
|
I'm leaning towards silently ignore if SQLite version doesn't support it. That means that the first time you attempt to use |
Is there a need for an introspection function for telling if a SQLite table is in strict mode or not? How would that work? |
From the STRICT docs:
So I think I need to read the |
Made myself a test strict table like so: >>> import pysqlite3
>>> conn = pysqlite3.connect("/tmp/strict-table.db")
>>> conn.execute("create table foo (id integer primary key, name text, weight real) strict")
<pysqlite3.dbapi2.Cursor object at 0x104317340>
>>> cursor = conn.cursor()
>>> with conn:
... cursor.execute("insert into foo (name, weight) values ('Lila', '2.31')")
<pysqlite3.dbapi2.Cursor object at 0x10331e1f0>
>>> conn.close() Uploaded that to: https://static.simonwillison.net/static/2021/strict-table.db |
Here's a function that detects if import secrets
import sqlite3
def supports_strict_tables(db = None):
if db is None:
db = sqlite3.connect(":memory:")
try:
table_name = 't{}'.format(secrets.token_hex(16))
with db:
db.execute("create table {} (name text) strict".format(table_name))
db.execute("drop table {}".format(table_name))
return True
except:
return False |
I'm going to add that as |
I haven't documented I need to remember to document it once I add documentation for the |
Need to figure out a good pattern for testing this in CI too - it will currently skip the new tests if it doesn't have SQLite 3.37 or higher. |
Make table.transform() preserve STRICT mode.
hello Simon, I've added more STRICT table support per #344 (comment) in changeset e4b9b58. |
* Add more STRICT table support per #344 (comment). * Make `table.transform()` preserve STRICT mode. * Fix mypy failures in PR #604 * Link to SQLITE strict page in a few places
New in SQLite 3.37.0, released a few days ago: https://www.sqlite.org/stricttables.html
The text was updated successfully, but these errors were encountered: