Booleans in a db

From Boolean array to SQLite - Databases - Xojo Programming Forum

Which is the best way to save an array() of booleans to SQLite?

In a db that is properly normalized this REALLY might end up as a table all by itself related to another table
without knowing more about the domain its hard to make really great suggestions but a kv pair table related back to the original on an ID
create table kv_pairs ( id integer primary key, id_fk integer, key text, value integer )
this has the advantage that more pairs are just more data and inserted as more rows

and it can be extended simply to support default values AND other data types as well like

     ```
         create table kv_pairs ( id integer primary key,
                                           id_fk integer,
                                           key text,
                                           datatype text,
                                           value text )
     ```

then the DATATYPE column can be used as part of read / write to convert TO/FROM whatever datatypes you need to support

In general IF you have a class that has “an array of …” then that means you have a table for the class and a related 1:N table for that “array of …” whatever that is (could be an array of related classes, booleans, strings, whatever )

Agree. Although I would always be hesitant to use a generic key-value table for all sort of things together. Since tables are cheap in databases I personally would always go with dedicated tables.

Indeed I’d usually use a dedicated table as well

The key value style works well when you dont know ahead of time how many rows per related table you might need

Like maybe for storing all the property values for objects :slight_smile: