KiCad: The case for Database driven design

You can use a JSON validator like https://codebeautify.org/jsonvalidator to check your kicad_dbl files.

It points out that in the version where you use a connection string, the string is not valid because you use backslashes without escaping them. If you include a path to a file (on Windows) in your connection string, you must use \\ instead of \ for it to be a valid string. Otherwise, it treats the \ as an escape character.

Thank you craftyjon. I started using the DSN connection so wouldnā€™t have to specify a path name for the driver. I just used the JSON validator to check my kicad_dbl file & it is valid.
I have my resistor & capacitor database libraries working perfectly.
When I include another library like diodes, Thru the library symbol chooser, I see the symbol but the footprint library says no footprints found.
I have imported all the diodes footprints & can see the footprints if I open the footprint library in the pcb chooser. I think it must be the kicad_dbl file. Iā€™ll keep on looking at it.

Iā€™ve been using Altium for a long time & I see alot of parallels in KiCad. Some things you are doing easier than Altium.
There are some Altium features I miss such as the way Altium copy/pastes a part relative to a point.
Iā€™ve been somewhat successful in mimicing out job functionality thru batch files & a custom Python/Tkinter program. Less prone to fabrication error.
Thanks for all you do,
nasa

There is a ā€œcopy with referenceā€ action that you can map to a hotkey if desired

The other thing to check is your database table ā€“ does the library nickname exactly match whatever your diodes library is called in your KiCad footprint library table?

Changing nicknames is an easy and convenient way to relocate a personal library in the library table.
This is detrimental to a data base or anything else?

The database links rows to symbol and footprint libraries by nickname. If you change the nickname, you must also update the database.

Note that when you are using a database library, the database table itself will show up with a different nickname in the library chooser. The ā€œsourceā€ library providing symbols can be hidden from the symbol chooser so that you donā€™t accidentally place ā€œplainā€ symbols that donā€™t come from the database.

1 Like

Thanks, Iā€™ll check today

Jon,
There was a mismatch between the kicad_dbl & the field name in my KiCad database for the footprint. I guess when you make the mistake, its harder to see it. It all works now!!!
Regards,
nasa

1 Like

@John_Pateman Iā€™m gonna try to test this out this weekend on a M1 MBP as well.

Could you provide a bit more detail how you got this working? Did you have to install sqliteodbc using the x86_64 version of homebrew or did you get it working some other way?

Few random hints to get this working!. It is useful to have the iODBC DataSource Administrator installed just to quickly check your configuration.

I installed the x86 version of the sqliteodbc ODBC driver with

arch -x86_64 brew install sqliteodbc

and the ARM version of sqlite with

brew install sqlite

The ODBC config files can be found at and can be edited by hand but I found the Data Source Administrator 64 helpful to confirm that I had a valid setup.

/Library/ODBC/odbc.ini and /Library/ODBC/odbcinst.ini are the files that control the ODBC setup.

If going by the hand rolled route, you will need to check that the /Library/ODBC/odbcinst.ini contains

[SQlite]
Driver = /usr/local/lib/libsqlite3odbc.dylib
Setup = /usr/local/lib/libsqlite3odbc.dylib

And the /Library/ODBC/odbc.ini contains something like the following snippet (not sure this is completely necessary - and the DEVART_SQLITE is a hangover from the DevArt ODBC drivers which I tried out (which work but are not cheap and not necessary)

[ODBC Data Sources]
myodbc        = MySQL ODBC 8.0 Unicode Driver
myodbca       = MySQL ODBC 8.0 ANSI Driver
DEVART_SQLITE = Devart ODBC Driver for SQLite
 
[ODBC]
TraceLibrary =
 
[myodbc]
Driver    = MySQL ODBC 8.0 Unicode Driver
SERVER    = localhost
NO_SCHEMA = 1

[myodbca]
Driver    = MySQL ODBC 8.0 ANSI Driver
SERVER    = lqocalhost
NO_SCHEMA = 1

Its helpful to have a schema viewer to adjust and import data from an external source eg a spreadsheet into your database. I found db-browser for sqlite easy to use.

brew install --cask db-browser-for-sqlite

Hope that helps to get you going.

Here is my database and .kicad_dbl files if you want to play. You will need to add it to your library table as database connection.

Let me know if this works for you!

database.sqlite (136 KB)
qa_dblib.kicad_dbl (3.8 KB)

2 Likes

THANK YOU! Iā€™m hoping to get some time to mess around with this over the weekend. Iā€™ll let you know if I run into any issues.

@John_Pateman thanks again, your tips were super helpful.

I put together a step-by-step guide for anybody else trying to get this working on a Mac with Apple Silicon:

Let me know if there is anything I got wrong/missed.

4 Likes

Just dropping in to say that now that we have universal builds up for macOS (for the nightlies) I have switched my M1 machine over to using arm64 odbc drivers and everything seems to work fine.

1 Like

@craftyjon which odbc driver are you using? was it installed from homebrew?

I just tried to use the ones installed via homebrew and I got an error like this:

The file exists on my machine:

āÆ ls -al /opt/homebrew/lib/libsqlite3odbc.dylib
lrwxr-xr-x  1 chris  admin  52 Dec 13 14:36 /opt/homebrew/lib/libsqlite3odbc.dylib -> ../Cellar/sqliteodbc/0.9998/lib/libsqlite3odbc.dylib

I am looking forward to seeing how this works in v7.

I get the same error as @cdwilson. Ive also tried a number of other ODBC drivers including the MS versions with a variety of similar errors.

For testing the DSN connection I tried this command in PowerShell:

This is not working for me as I get following error message:

 "ERROR [HY000] database is locked (5)"

+ $reader = $cmd.ExecuteReader()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : OdbcException

My system:

  • Windows 11 with KiCad Nightly
  • Windows Subsystem for Linux (Ubuntu 22.04) with SQLite3 installed

My steps so far:

  1. Installed ODBC driver for windows SQLite ODBC Driver (ch-werner.de)
  2. Installed SQLite3 on WSL 2 Ubuntu like user @cioma explained Adapted with the files from here qa/data/dblib Ā· master Ā· KiCad / KiCad Source Code / kicad Ā· GitLab
  3. Created an ODBC user dsn pointing to the database in the WSL 2 folder
  4. Configured the .kicad_dbl file with the dsn name
  5. Configured KiCad to point at this file

Now what I get in KiCad is this:
image

It recognizes the library, but it is shown empty.

I guess I have one or more of the following problems:

  1. Wrong permissions in WSL 2 for the database file? (-rwxr-xr-x 1 az az 139264 Dec 14 00:08 database.sqlite)
  2. ODBC driver is not working?
  3. SQLite is needed on Windows and not on WSL?

Has anybody looked into it with SQLite3 and WSL 2? Can anybody help? Thank you!

Ciao,
can you see the DB contents using the ā€˜DB browser for SQliteā€™?
i get something like this:

1 Like

Yes, there is data visible in there.

Said user was actually using Ubuntu for their desktop, not Windows.
The Windows SQLite ODBC driver contains the SQLite library already, you donā€™t need any extra packages and it can interact with sqlite files without anything else.

could you share the .kicad_dbl file with us?

1 Like