Registered Member
|
Chalk me up as another user who has a large infrastructure around SQLite and just wants to be able to import those into Kexi. I took a different avenue to other folks (https://userbase.kde.org/Kexi/Tutorials/Importing_SQLite_database_into_Kexi), and my database is too big to convert via manual labor
Things of note in the following, along with the comments inline: * Ubuntu 16.10, with latest kexi in the ubuntu repos [2.9.11] * Requires sqlite 3.16.0+, since it uses pragma table-valued functions. * Reading Kexi's source, f_fields.f_options and f_constraints are hard to infer. I mostly care about reading from an existing fully-written database [rather than using kexi's GUI to add data], I quietly ignore most of it * Kexi doesn't use views to implement its "queries". The commented out section at the end does what I assume would be the right thing, but kexi doesn't like the syntax for a lot of the views in my database. If I just pretend that existing views are kexi "tables", the right thing happens. Being said, here you go. This script takes my existing sqlite databases, and ends with a file that kexi is able to load and look at.
Afterthoughts: * Kexi's schema: - lacks FKs and other structures that would enforce correctness - declares some columns as types that sqlite doesn't know about [CLOB] or doesn't care about [UNSIGNED] - Doesn't use sqlite's autoincrement * In the same vein, I can't seem to describe many of my constraints using kexi's lexicon [FKs, compound keys, CHECK constraints etc]. They're on the database and sqlite will enforce them. I'm quietly ignoring this. * My broad endgame for something like this would be to inject kexi "Reports" as befits my specific application Overall: * It's awesome that there's finally something approaching Access. * It clearly does a great job of solving a whole bunch of problems. * Thank-you for creating this. Cheers, Gary PS In case you're wondering: I have several models that drop SQLite databases as their output, that I then query to get model run results. Hence the databases would never be written to. I'm just trying to improve model usability by experimenting and finding good tools for users of my models to get output. |
Moderator
|
Thanks Gary, I see we can benefit from this analysis and check step by step what can be improved in Kexi schema and alike.
|
Moderator
|
Good observation, for my understanding: - The schema originates from the SQLite 2.8 times when FKs were ignored, IIRC. FKs would be a good addition, not breaking backward compatibility unless someone depends on lack of FK while using the sqlite file outside of Kexi. Kexi's client itself (originating, again to the old SQLite times) enforces the integrity internally and this won't be removed so we would be OK - we would stay compatible. - The use of UNSIGNED, as some other words in SQLite is a pure annotation. - Regarding CLOB, consider this an annotation, SQLite recognizes this; from https://www.sqlite.org/datatype3.html: "If the declared type of the column contains any of the strings "CHAR", "CLOB", or "TEXT" then that column has TEXT affinity. Notice that the type VARCHAR contains the string "CHAR" and is thus assigned TEXT affinity." - Kexi client uses the autoincrement feature by not setting the ID values. From https://www.sqlite.org/autoinc.html: "On an INSERT, if the ROWID or INTEGER PRIMARY KEY column is not explicitly given a value, then it will be filled automatically with an unused integer, usually one more than the largest ROWID currently in use. This is true regardless of whether or not the AUTOINCREMENT keyword is used." (so for SQLite AUTOINCREMENT would be redundant; if it's needed for some other db backends, it is added) |
Registered Member
|
Yeah, and FKs still require enabling every single time you open a database connection. Adding them adds convenience, and like you say, wouldn't actually break anything [PRAGMAs are documented as being ignored-but-accepted if unknown, which plays positively into this]. Honestly, SQLite 2 is something not worth considering, it's now *decades* out of date, and trying to support it leads to misery.
Sure! If it were me, I'd want to do one of two things [note that this is a SQLite-specific discussion]: a) If I actually cared that the values were unsigned, I'd add a CHECK constraint b) If I didn't actually care, I'd leave it off *shrug*
So, the broad [strategic] question for kexi would be [and this applies to most of my thoughts about this]: do you want to drink the SQLite kool-aid wholesale? If you do, you can take advantage of some vendor-specific stuff, and your code would be clearer by using the SQLite types. If you don't, or you want to leave it open to porting your code more easily to other databases, then it's totally fine as-is.
Ah, sorry. Upon further examination, I realise you're using that on kexi__{objects,blobs,parts} but not on kexi__{fields,db,objectdata,userdata}, because those don't actually have a pk column [they still have rowid, but that's hidden]. Which I'd note takes me back to a previous point; without a unique constraint on kexi__fields on {t_id,f_name}, you could easily end up in trouble; partially for correctness, and partially because addressing a specific row is hard [unless you're using the implicit rowid - implicit columns are something I'm not fond of, one of the few things I really don't take advantage of when drinking the sqlite kool-aid] Thanks for the responses! I wasn't really expecting this, I was just throwing up something that other folks may find helpful, if they start googling for kexi sqlite conversion stuff. I really appreciate what you've built, here. If I had more free time right now, I'd just implement the import properly directly in kexi Gary |
Registered Member
|
Hi gbriggs:
How do you use the script? Thanks. bdika |
Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]