KiCad: The case for Database driven design

Do you mean KiCad crashed for you? I tried this and couldn’t reproduce it – if you have nothing in the database it should just show up as an empty library.

Hi qu1ck,

Appreciate your feedback!

I have/ use Synology (one of the best related to the security update - I guess), but I assume most of NAS provides versions of mentioned packs (e.g PHP is offered in multiple version), but here you have a snapshot.

Thanks,
Best Regards,
Andrei

… or load everything as a Docker image? … to ensure multi platform compatibility?

You are right, I tried to replicate what I observed, but I couldn’t. I think at some point I had an incorrect .kicad_dbl file or something. Sorry for bothering you. I will update my previous post.

I have been tweaking my db and had issues with a goofed-up .kicad_dbl file. I recalled that @craftyjon had recommended pasting it into
https://codebeautify.org/jsonvalidator
which found an extra double quote that corrupted it. This resulted from me just doing a quick edit with a text editor – I should have edited it with vscode where I would have found it. Anyway, the kicad error is just a generic “.kicad_dbl file missing or…” message.
I am also on pop-os, but I use the sqlite db and sqlite-studio for maintaining it.

I just continued working on my migration and I was able to replicate the problem:

In my original database, I have a column named “Description” and its Datatype is set to TEXT. When trying to import any component non-empty description (which is basically any) KiCad will crash after pressing “Add a symbol” and trying to load the libraries.

I solved it changing the Datatype of this column to VARCHAR(xx). If someone can replicate it, I will take the time to write an issue in Gitlab.

Summary: the problems seems to be that KiCad is not able to load “TEXT” datatype columns.

Regards,
Enrique

3 Likes

Hey everyone,

It seems like my previous post received some positive feedback, so I’m assuming the bug I mentioned was replicated by others. I’ll be sure to file an issue report soon.

In the meantime, I came across another potential bug today:

I was working on splitting a VARCHAR column for “Operating Temperature” in my library, which contains strings like “-45ºC to 125ºC,” into two separate columns (min and max). Additionally, I wanted to convert other VARCHAR columns, such as “Power Rating” with values like “250 mW,” into a new “Power Rating [W]” column with a Float data type. This would help standardize units and allow for numerical data processing rather than working with strings.

However, I discovered that after converting “250 mW” to 0.25, KiCad reads the value as 0 due to rounding down. Similarly, 1.5 is rounded down to 1:

The code I’ve used in the .kicad_dbl file is as follows:

{
    "column": "Power Rating [W]",
    "name": "Power Rating [W]",
    "visible_on_add": false,
    "visible_in_chooser": false,
    "show_name": true
}

Currently, there’s no way to control the parsing of numbers. It would be fantastic if we could use formatting strings like “{2.0f} + mW” in the .kicad_dbl file.

I might update this post later, as I’m in a bit of a rush right now.

I would agree with @ nctnico CIS is a great reference. I walked into the same situation and designed by own (Python) based scripts and SQL DB system based on years working on the coordination of system integration with PLM, ERP, SCM, Warehousing, Engineers and quality sections (and a few years in EE and CAD).

I could not find any software solution in the market that structures the functions and workflows as how most large enterprises do. The current KiCad solution is great as I don’t want to go to other systems/applications to see if I have parts that need fit the schema/layout needs.

In many departments don’t like folks from other departments look into each other kitchen (systems) even though that would often help a lot. Most larger companies separate CAD ,PLM, ERP and SCM in different systems and the teams working with those system do not have access to other systems.

A CAD system integration should mainly interface with PDM data. Such PDM data can be located in a PDM, a PLM or ERP (it differs by company) or an aggregated database.

A request for a new symbol/footprint/model should flow through the PDM which in turn may have to go through a long cycle to check data in the PLM, ERP and SCM systems before approval. (For example, is the PN correct, is the part available, price, is the vendor approved, is there an alternative, are there form, fit, function and supply substitute parts, etc…etc…) In enterprise this is (partially) automated or just manual paperwork based. Individuals or in small companies with just a few folks don’t such an need bureaucratic workflow and can make decision much faster.

Basically, for automation, the CAD should only need to interface with the PDM (or ERP/PLM in case intermediate system do no exist). The search for, or to request, approval for a new symbol/footprint/model created in the PDM. The PDM takes it from there with other systems/departments.

So my suggestions /ideas would be as follows (YMMV). The assumption here is that there is one parts table (or SQL view) for all components.

  1. Take the search tool outside of the symbol management as a separate tool

  2. Remove the requirement of lib:symbol or ID field. I.O.W: just search on any keyword for any column. Define in the KiCad file which columns of the table should be used as the library : symbol/footprint name to insert it into the schema/layout.

  3. For part search: Change from ODBC to JSON HTTP API based request/response process. Define a schema for the API calls. It is nowadays easy to run a local server with python or npm. HTTP(S) will allow integration with any system (i.e retailers), for each one it just need a bridge that exchanges data from the 3rd party system to the KiCad API schema.

  4. For (local DB) new symbols/footprints/models: Create an export function for new symbol request (i.e a file the the PDM can pick up or an API call to the PDM) and create an import background job or function to pick up a file or get the status from the PDM once the PDM has approved/reject the request. Add a new fixed , mandatory field “status” in KiCad symbol/footprint/model that updates with the status returned from the PDM.

5.Show in the browser, the symbol/footprint parametric fields from the database

  1. Add search option to search for keywords for all the (schema) defined database fields.

Ultimately what I would like is to be able to do from KiCad instead of going trough other systems:

  1. Search for parts by keyword, value, manufacturer, part-number, rating, size, footprint, symbol, model , Part status i.e Internal approval/lifecycle status of the part itself (part-number) approved, obsolete, disqualified etc. (this can be direct to the PDM, PLM or ERP),
  2. PDM status: To know if the part (CAD) data (footprint/symbol/model) is approved (kept in the status field in KiCad)

The API bridge, would not be needed if the database (or view) implements the schema a defined by KiCad . This web API (i.e for at home a PHP SQL script or something that runs under an python or npm local server) could be a reference design provided by KiCAD. For 3rd parties DB’s or those who can’t generate the correct SQL view , they would need to implement their own HTTP API to their own database and transform the data into the JSON format as per the KiCad API. Te additional benefit is that the database could be located anywhere in the world as long as the API meets the API specification. The API could be REST based preferably.

@ 2norderEDO Thank you very much. I got the connection working with MariaBDB under Ubuntu 23.04. A few notes:

  1. sudo apt-get install odbc-mariadb (without the -s)

  2. apt install unixodbc (wasn’t needed)

  3. Kicad file:
    “source”: {
    “type”: “odbc”,
    “dsn”: “[dbname]”,
    “username”: “[dbuser]”,
    “password”: “[dbpass]”,
    “timeout_seconds”: 10,
    “connection_string”: “DRIVER=MariaDB Unicode;SERVER=localhost;USER=[dbuser];PASSWORD=[dbpass];DATABASE=[dbname];PORT=3306”

  4. .odbc.ini:
    [KiCad] # This assigns a local DNS to your IP and port, put whatever you like
    Description=[whatever]
    Driver=MariaDB Unicode
    SERVER=localhost
    USER=[dbuser]
    PASSWORD=[dbpass]
    DATABASE=[dbname]
    PORT=3306

5.use “SHOW GRANTS” in SQL for the server name (in my case “localhost”) make sure its the same servername as in .odbc.ini and the connection string. the “IP” did not work for me as the grants were not set for the IP address but for @localhost.

  1. Load the file kicad file (at point 3) in the manage symbol libraries

Hope this help anyone.

P:S I have lots of other data in my tables and I don’t use those fields in KiCAD bsymbol properties, but I would like to search for those fields and let them show up in the KiCaD symbol browser, is that possible ?

1 Like

Written up a quick draft API spec. This is not correct JSON, but just to get the idea.

kicad-api-draft.txt (2.5 KB)

It sounds like you have thought this out extensively, so I’d encourage you to add a “thumbs up” and copy this comment to the relevant gitlab issue where the developers are more likely to see it.

1 Like

Thanks a lot. Great to see my post was found so deep the chain :slight_smile: It wasn’t thought trough :smiley: after thinking more about it, there are so many things to consider before developing. I just read the Gitlab post and it seem others have the same thoughts and it’s very close what I documented above for the parts portion, even halfway developed the solution ! I agree the ODBC solution is nice but not perfect. I could write a high level functional draft blueprint for a solution but not sure where to post that. Gitlab ? Specially in the beginning, things may change quickly that requires to change the document.

Often a google doc link posted to gitlab is suggested as an easy way to share a draft spec and update/allow comments. Another option is starting a conversation on the developers email list, if you have something drafted already that you want more formalized comments on.

(Disclaimer, still not a developer, so take all of this with more than a few grains of salt)

I am working on a draft that cover most of the comments above. This takes some time to polish

about :

It will not be possible to implement alternate symbols until V8 at earliest (alternate footprints are somewhat easier)

I wish that KiCad could provide an option to add multiple “configurations” for a symbol, For example a MCU symbol can be reused but the GPIO’s and other pins may be used in different ways (I/O/Bi/NC/passive etc…)

Something of the sort already exists: you can have alternate pin names within a symbol. If you open Symbol Editor and double click on a pin (or press E with a pin selected) you can hit the drop down arrow for Alternate Pin Definitions and add as many as you like.

When the symbol is placed in schematic, you can hit E with a symbol selected to open Symbol Properties and edit the “Alternate Pin Assignments” in the tab next to General. It isn’t obvious, but the Alternate Assignment column has a bunch of drop down menus that need to be selected from.

Edit: See Alternate pin assignment - #6 by roboya for nice screenshots

I followed the instructions by @2norderEDO and @debug (thanks for you posts!) but it still won’t work for me. KiCAD shows my library, but it’s empty. Any ideas, where I am missing the last piece?

library.kicad_dbl:

{
    "meta": 
    {
        "version": 0
    },
    "name": "My Database Library",
    "description": "A database of components",
    "source": 
    {
        "type": "odbc",
        "dsn": "",
        "username": "",
        "password": "",
        "timeout_seconds": 2,
        "connection_string": "DRIVER=SQLite3;DSN=KiCAD;UID=binner;PWD=binner;SERVER=10.0.1.157;DATABASE=binner"
    },
    "libraries": 
    [
        {
            "name": "ICs",
            "table": "ICs",
            "key": "PartNumber",
            "symbols": "SymbolName",
            "footprints": "FootprintName",
            "fields": [
                {
                    "column": "PartNumber",
                    "name": "Value",
                    "visible_on_add": true,
                    "visible_in_chooser": true,
                    "show_name": true
                },
                {
                    "column": "ManufacturerPartNumber",
                    "name": "PartNr",
                    "visible_on_add": false,
                    "visible_in_chooser": true
                },
                {
                    "column": "Manufacturer",
                    "name": "Manufac",
                    "visible_on_add": false,
                    "visible_in_chooser": true
                },
                {
                    "column": "DatasheetUrl",
                    "name": "Datasheet",
                    "visible_on_add": false,
                    "visible_in_chooser": true
                }
            ],
            "properties": 
            {
                "description": "Description",
                "keywords": "Keywords"
            }
        }
    ]
}

Data base:


    Server: Localhost via UNIX socket
    Server type: MariaDB
    Server connection: SSL is not being used Documentation
    Server version: 10.11.3-MariaDB-1 - Debian 12
    Protocol version: 10
    User: root@localhost
    Server charset: UTF-8 Unicode (utf8mb4)

And my table looks like this:

| PartId |  ...  | PartNumber |  ...  | ManufacturerPartNumber |  ... -| FootprintName | SymbolName   |
X--------X- ... -X------------X- ... -X------------------------X- ... -X---------------X--------------X
| 1      |  ...  | LM358      |  ...  | LM358SNG               |  ... -| LALALALALA    | LALALA       |
| 2      |  ...  | NE5532     |  ...  | NE5532DR               |  ... -| 0_epak:SO-8   | 0_EPAK:OPAMP |
X--------X- ... -X------------X- ... -X------------------------X- ... -X---------------X--------------X

ODBC log exists, so there is some kind of communication, can’t decipher it, though.
odbc.log (9.2 KB)

So as far as I understand it, my library should not be empty. Any ideas? :smiley:

Thx!

OK, my bad, the SQLite3 driver cannot communicate properly with a MariaDB. And since the MariaDB driver crashes KiCAD in my case I installed the MySQL ODBC driver driver and now it’s working. Nice.

Perusing back through this thread - its kinda surprising the life it took on. So glad that people got behind this and that KiCad continues to move forward.

Well you started all this – and Jon finished it :slight_smile:

There must be some record set on length of a new member first-post.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.