I’m putting together a database library and I realized that the database column specified as "key"
in the database library config file (*.kicad_dbl
) is used as the name of the symbol in the GUI.
Originally I had a numeric identifier here, but since the value is used in the GUI, I decided I needed a more descriptive value for “key”.
What I came up with was the concatenation of manufacturer and manufacturer part number. So MFR=TI, MPN=1234, gui name is TI-1234.
This is possible in sqlite using generated columns.
So, I made this sqlite database:
gen-concat.db
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE everything (
symbol TEXT,
footprint TEXT,
value TEXT,
package TEXT,
mpn TEXT,
mfr TEXT,
guiname TEXT GENERATED ALWAYS AS ( mfr || '-' || mpn ) STORED,
UNIQUE ( mpn , mfr )
);
INSERT INTO everything VALUES('C_Small','C_1210_3225Metric','10 uF','1210','CGA6P1X7R1N106M250AC','TDK');
COMMIT;
generated column working as expected
$ sqlite3 gen-concat.db 'SELECT guiname FROM everything;'
TDK-CGA6P1X7R1N106M250AC
Then in *.kicad_dbl
set "key": "guiname"
.
I found no symbols in the library, though the library itself (“AAAAA - Everything”) is picked up1:
If I simply change "key"
from "guiname"
to "mpn"
(no longer referring to a generated column) in *.kicad_dbl
, the symbol appears in the library after closing kicad completely and reopening2:
So that’s the problem. It seems KiCad doesn’t recognize a generated column.
I though maybe the problem had to do with the value. Too long, or the dash in it, maybe?
Nope, I made another database where the generated column is exactly MPN, forget the concatenation.
gen-no-concat.db
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE everything (
symbol TEXT,
footprint TEXT,
value TEXT,
package TEXT,
mpn TEXT,
mfr TEXT,
guiname TEXT GENERATED ALWAYS AS ( mpn ) STORED,
UNIQUE ( mpn , mfr )
);
INSERT INTO everything VALUES('C_Small','C_1210_3225Metric','10 uF','1210','CGA6P1X7R1N106M250AC','TDK');
COMMIT;
diff
- "connection_string": "Driver=Sqlite3;Database=./gen-concat.db;"
+ "connection_string": "Driver=Sqlite3;Database=./gen-no-concat.db;"
- "key": "mpn",
+ "key": "guiname",
comparing guiname and mpn
$ sqlite3 gen-no-concat.db 'SELECT guiname, mpn FROM everything;'
CGA6P1X7R1N106M250AC|CGA6P1X7R1N106M250AC
Same issue3:
So, I’m wondering, is this a bug?
I’m on KiCad 9.0.0 Flatpak. Here’s a git repo with the full demo files, commits 1 2 3 corresponding to superscripts 1 2 3 in my post:
kicad-gen-col-demo.zip (25.9 KB)