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
The following error occurs using the schema reader (specifically columnDefinitions(table:)) for a particular table (see below for the tables/foreign key definition that triggers this):
SQLite/Query.swift:1216: Fatal error: 'try!' expression unexpectedly raised an error: Unexpected null value for column `"to"`
This is due to the fact that the foreignKeys function in the SchemaReader assumes that the to colum returned by running PRAGMA foreign_key_list("table name") contains a valid primary key column and is not null:
structFKey {
...
structsColMap { /* Mapping of columns in pFrom to columns in zTo */
....
char*zCol; /* Name of column in zTo. If NULL use PRIMARY KEY */
} aCol[1];
};
So it seems valid to omit the primary key column and SQLite will automatically use the primary key column of the referenced table. On the flip side that means, to can in fact be null. In this example, the referenced column would be artist. artistid (the primary key of the artist table).
Build Information
SQLite.swift version: 0.14.1 (also tested on master at 1b1eba0)
Xcode version: 14.3
macOS: 13.3.1
SQLite.swift is integrated via the SPM:
import PackageDescription
letpackage=Package(
name:"to-column-null",
dependencies:[.package(url:"https://github.com/stephencelis/SQLite.swift.git", from:"0.14.1")],
targets:[
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name:"to-column-null",
dependencies:[.product(name:"SQLite",package:"SQLite.swift")],
path:"Sources"),])
The text was updated successfully, but these errors were encountered:
The following error occurs using the schema reader (specifically
columnDefinitions(table:)
) for a particular table (see below for the tables/foreign key definition that triggers this):SQLite.swift/Sources/SQLite/Typed/Query.swift
Line 1216 in 7a2e3cd
This is due to the fact that the
foreignKeys
function in theSchemaReader
assumes that theto
colum returned by runningPRAGMA foreign_key_list("table name")
contains a valid primary key column and is not null:SQLite.swift/Sources/SQLite/Schema/SchemaReader.swift
Lines 94 to 107 in 7a2e3cd
The error occurs in line
100
:row[ForeignKeyListTable.toColumn]
.That is not necessarily true though.
How to reproduce
Minimal example (see below for the necessary
Package.swift
definition):The table definition is taken from the last example on https://www.sqlite.org/foreignkeys.html#fk_indexes (Section 3 "Required and Suggested Database Indexes").
The result of the
PRAGMA
query is the following table:Here the
to
column is empty.The SQLite source for the foreign key contains the following bits (see https://github.com/sqlite/sqlite/blob/master/src/sqliteInt.h#L2500):
So it seems valid to omit the primary key column and SQLite will automatically use the primary key column of the referenced table. On the flip side that means,
to
can in fact be null. In this example, the referenced column would beartist. artistid
(the primary key of theartist
table).Build Information
SQLite.swift version:
0.14.1
(also tested onmaster
at 1b1eba0)Xcode version:
14.3
macOS:
13.3.1
SQLite.swift is integrated via the SPM:
The text was updated successfully, but these errors were encountered: