You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
admin BOOLEAN NOT NULL DEFAULT 0 CHECK (admin IN (0, 1)),
manager_id INTEGER,
created_at DATETIME,
FOREIGN KEY(manager_id) REFERENCES users(id)
)
According to 3.1. Determination Of Column Affinity the affinity of a column is based on the declared type. With the "parsing" following a set of five rules (see linked page).
So for the above table definition, the column affinity should be:
id -> rule 1: INTEGER ✅
email -> rule 2: TEXT ✅
age -> rule 1: INTEGER ✅
salary -> rule 4: REAL ✅
admin -> rule 5: NUMERIC ❌
manager_id -> rule 1: INTEGER ✅
created_at -> rule 5: NUMERIC ❌
but the affinity is incorrect for the following columns: admin and created_at (TEXT instead of NUMERIC).
E.g. take the example table definition from the
TestHelper
:SQLite.swift/Tests/SQLiteTests/TestHelpers.swift
Lines 22 to 31 in f1bee07
According to
3.1. Determination Of Column Affinity
the affinity of a column is based on the declared type. With the "parsing" following a set of five rules (see linked page).So for the above table definition, the column affinity should be:
id
-> rule 1:INTEGER
✅email
-> rule 2:TEXT
✅age
-> rule 1:INTEGER
✅salary
-> rule 4:REAL
✅admin
-> rule 5:NUMERIC
❌manager_id
-> rule 1:INTEGER
✅created_at
-> rule 5:NUMERIC
❌but the affinity is incorrect for the following columns:
admin
andcreated_at
(TEXT
instead ofNUMERIC
).See
SQLite.swift/Tests/SQLiteTests/Schema/SchemaReaderTests.swift
Lines 17 to 57 in f1bee07
A possible solution is to create the
Affinity
and implement the 5 rules, e.g. like here: stefansaasen@fabbe8cThere is one important thing to consider here, the default affinity for declared types that are not covered is now
NUMERIC
instead ofTEXT
. E.g. with the gotcha mentioned here: https://www.sqlite.org/datatype3.html#determination_of_column_affinityShould probably considered to be a breaking change.
P.S.: Happy to create a PR if the approach in the commit linked above is acceptable.
Build Information
14.3
and macOS Ventura13.4
The text was updated successfully, but these errors were encountered: