KiCad: The case for Database driven design

That’s really really wonderful! KiCAD rules!

Are there anything in your mind to polish this feather? Could I help a little bit on this function?

I am not sure quite what you mean by this, but if you have requests or find bugs, please report them on GitLab

I will have to check out that issue with the browser later. I recommend in general to use the symbol chooser, not the browser. Is there some reason you use the browser in particular?

Not really, I’ve just found the issue.

Anybody used MariaDB? Can it be used with KiCad. If so, is anyone willing to tell us how. I know NOTHING about databases in general. So maybe setting up KiCad with MariaDB would be an excuse to learn. Thanks.

Any database that has a ODBC driver can be used with KiCad. Depending on database, you often to have to install it separately. Exceptions are like on Windows, the MSSQL driver is part of Windows.

MariaDB has one you need to install here:

Yes, doing just that :slight_smile:
You have to provide (and fill) some new columns to add KiCAD parts and KiCAD footprints and you’re done,
you can use the DB with both. MAGIC!

Doe anyone know and open-source ODBC driver for text files (e.g. CSV)?

In latest distributions UnixODBC doesn’t compile ODBC text driver (libodbctxt.so) anymore (link)

You could try SQLite if you want something portable. Though you need to use a SQLite tool later to edit the database outside kicad.

Thanks, SQLite is my next best option if I wouldn’t find an ODBC driver for text (CSV) files.

Well, I managed to set up an SQLite database, if anyone interested I’ll describe the process step-by-step.

As this is not an officially released feature I should probably refrain from opening issues on Gitlab but I’ll add them here for now.

In *.kicad_dbl file format it would be useful to have the following features:

“visible_on_add” parameter values:
“true” - make field visible when symbol is placed and put it to the origin of the symbol (implemented)
“false” - make field invisible when symbol is placed and put it to the origin of the symbol (implemented)
“placeholder” - make field visible when symbol is placed and put it where the placeholder in the symbol is placed (not implemented)

Additional parameter for “fields”:
“add_if_empty” = {true|false} - defines if a field shall be added to the placed symbol if it’s empty in the database

2 Likes

Well, I managed to set up an SQLite database, if anyone interested I’ll describe the process step-by-step.

Yes please!
Thanks

2 Likes

Hello all. I have been working with a company that uses Altium. There wasn’t a database when I started. The designers had their own symbols & footprints so all schematics looked somewhat different & not all footprints were good. We made an Excel sheet with all the parts, then Altium made the database. All is good. We are looking into using KiCad & I have.

  1. imported an Altium board (looks good)
  2. made resistor & capacitor symbol & footprint libraries from the Altium parts. I can see then in the
    Kicad chooser
  3. I made the KiCad database for the parts using . I have the database made from the Altium Excel file
    with DB Browser (SQLite). I also made the .kicad_dbl file. Thanks to Claudio.Lorini for the example
    files & craftyjohn.
  4. I installed SQLite ODBC Driver 64 bit. I told KiCad (nightly build) to connect to the .kicad_dbl file thru
    the symbol preferences screen. But I get the following error:
    Symbol Library ‘name_db’ failed to load. Could not connect to database library: could not connect
    to database.
    I’m pretty sure I don’t have the ODBC Datasource Admisistrator page setup correctly.
    Any help would be greatly appreciated. I’m pretty close to getting this working

So here is what I did to set up an SQLite ODBC database in KiCad.

It was done on Ubuntu 22.04 with latest KiCad v6.99 nightly build.

  1. Install UnixODBC, SQLite command-line tool, SQLite ODBC driver, SQLite Database Browser (optional):
sudo apt-get install unixodbc sqlite3 libsqliteodbc sqlitebrowser
  1. Check if SQLite ODBC driver was added to the odbcinst.ini file:
cat /etc/odbcinst.ini

You should see a section like this:

[SQLite3]
Description=SQLite3 ODBC Driver
Driver=libsqlite3odbc.so
Setup=libsqlite3odbc.so
UsageCount=1
  1. I don’t use data sources but you could set them up if you like:
    System data sources are held in /etc/odbc.ini
    User data sources are held in ~/.odbc.ini

  2. Create your SQLite component database.
    I use this Google spreadsheet as a source: link
    I save the second sheet (named “kicad”) as a CSV file.
    And then I recreate SQLite database from that CSV file:

rm /media/cioma/my/project/kicad/library/kicad.sqlite
sqlite3 --csv /media/cioma/my/project/kicad/library/kicad.sqlite '.import /media/cioma/my/project/kicad/library/kicad.csv component'

As you can see I keep all the components in a single database table named “component” but you might have several table if you wish.

  1. Create *.kicad_dbl file:
{
    "meta": {
        "version": 0
    },
    "name": "KiCad Database Library",
    "description": "KiCad components database",
    "source": {
        "type": "odbc",
        "dsn": "",
        "username": "",
        "password": "",
        "timeout_seconds": 10,
        "connection_string": ";DATABASE=file:///media/cioma/my/project/kicad/library/kicad.sqlite;DRIVER=SQLite3;"
    },
    "libraries": [
        {
            "name": "component",
            "table": "component",
            "key": "Identifier",
            "symbols": "Symbol",
            "footprints": "Footprint",
            "fields": [
                {
                    "column": "Part",
                    "name": "Part",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Category",
                    "name": "Category",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Manufacturer",
                    "name": "Manufacturer",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Manufacturer Partnumber",
                    "name": "Manufacturer Partnumber",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Type",
                    "name": "Type",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Package",
                    "name": "Package",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Description",
                    "name": "Description",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Address",
                    "name": "Address",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Capacitance",
                    "name": "Capacitance",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Color",
                    "name": "Color",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Current",
                    "name": "Current",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Dielectric",
                    "name": "Dielectric",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Frequency",
                    "name": "Frequency",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Impedance",
                    "name": "Impedance",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Inductance",
                    "name": "Inductance",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Output",
                    "name": "Output",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Rate",
                    "name": "Rate",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Resistance",
                    "name": "Resistance",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Resolution",
                    "name": "Resolution",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Sequence",
                    "name": "Sequence",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Size",
                    "name": "Size",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Temperature",
                    "name": "Temperature",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Temperature Coefficient",
                    "name": "Temperature Coefficient",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Time",
                    "name": "Time",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Tolerance",
                    "name": "Tolerance",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                },
                {
                    "column": "Voltage",
                    "name": "Voltage",
                    "visible_on_add": false,
                    "visible_in_chooser": true,
                    "show_name": false
                }
            ]
        }
    ]
}

What’s important here is the database connection string:

";DATABASE=file:///media/cioma/my/project/kicad/library/kicad.sqlite;DRIVER=SQLite3;"
  1. Add this component database (*.kicad_dbl file) to KiCad symbol libraries table.

  2. And now you should be able to add symbols from this library to you schematic.

2 Likes

Thank you for your response. My source is:
“source”: {
“type”: “odbc”,
“dsn”: “SQLite3 Datasource”,
“username”: “”,
“password”: “”,
“timeout_seconds”: 2,
“connection_string”: “Driver={SQLite3 ODBC Driver};Database=C:Users\nasad\Documents\KiCad\DB_Files/EPC_Db.sqlite”

I think the problem is my connection string
the dsn is the name in my ODBC Data Source Administration (64-bit) window. I tried removing the dsn & just tried “dsn”: “”, but same error.
I can’t seem to find a way to test the the connection from the ODBC Data Source Administration (64-bit) window.

I see you use multiple /// after file:, i haven’t tried this yet.

After I add this *.kicad_dbl file to the KiCad symbol libraries table & press ok is when I get the error.
Also that, the .kicad_dbl file disappears from the folder. Not sure why this happens. I thought maybe McAffee protection is doing something, thinking this is a virus or something. IDK

Anyway, thank you for your response!!!

Well, I’m under Linux but I suspect you connection string is incorrect, try this (just copy paste):

";DATABASE=C:Users\nasad\Documents\KiCad\DB_Files\EPC_Db.sqlite;DRIVER=SQLite3;"

Thank you cioma. I just tried it & still doesn’t work.
Its driving me crazy. I feel I’m pretty close.
Thanks again

This is correct according to url syntax. The file:// is the scheme and the following / is the root of the Linux filesystem. On Windows it might continue as C: in a drive letter based path.

Also if you mix / and \ in Windows paths check that the software allows it.

This syntax is also how you would get a web browser to open a local file.

And make sure there is a semicolon as the first symbol of the connection string as you’re not using data sources

Thank you all for your comments. I still can’t get this working. it seems most if you use Linux, Ubuntu. Just wondering if anyone has gotten the database to work with windows?
From windows ODBC source admin:
ODBC_Data
So, there is the DSN name using the SQLite 3 driver I see under the Drivers tab.

According to @craftyjohn:
There are two ways you can set up an ODBC connection:

  1. Set up a DSN (data source name) on your system, which has all the right parameters for the driver. Then you can tell KiCad to just connect to this DSN. This is what Claudio has done.
  2. Specify a connection string, which lets you include a choice of driver and all required parameters in the KiCad config file.

my .kicad_dbl file is:
“name”: “EPC Database”,
“description”: “EPC parts library”,
“source”: {
“type”: “odbc”,
“dsn”: “{SQLite3DSN}”,
“username”: “”,
“password”: “”,
“timeout_seconds”: 2
“connection_string”: “Driver={SQLite3 ODBC Driver};Database=C:Users\nasad\Documents\KiCad\DB_Files\EPC_Db.sqlite”
},

So if using method 1, just using the DSN, I can eliminate all the lines after “dsn”: “{SQLite3DSN}”,
I tried with & without the curly braces, but no luck.

If I use method 2, I can eliminate the “dsn”: “{SQLite3DSN}”, line. & just use the connection string with or without the curley braces, different combinations of the driver name, no luck.

While its not in my DNA, I’m giving up, I feel its not working under windows. Hopefully I’m wrong.
Regards to all
Nasa

BTW, here is the documentation for setting up Database Libraries in KiCad: Schematic Editor | master | English | Documentation | KiCad