问题
I have a C++ application that stores data in a database (SQLite) through QxOrm.
It is clear that in the next versions, columns are gonna be added/removed/renamed, so I would like to set a version number to each database created, so that when someone tries to load a database it compares its version with the current version of the application and automatically add/remove/rename the columns to match the current schema.
I couldn't find in the QxOrm documentation something that would look like:
qx::QxSqlDatabase::getSingleton()->setVersion(2);
So first is it possible to do that kind of thing with SQLite? and if not should I just create a table that would hold the database version?
回答1:
A database version is perhaps not enough : you should store a version per persistent class (and maybe other informations per persistent class, like list of columns for example). When you register a persistent class into QxOrm context, you have to put a version number :
QX_REGISTER_HPP_XXX(myClass, myBaseClass, myClassVersion)
You can find some informations about creating a SQL schema into the FAQ of QxOrm library : http://www.qxorm.com/qxorm_en/faq.html#faq_230
Using introspection engine of QxOrm library, it's quite easy to do, more details about introspection engine here : http://www.qxorm.com/qxorm_en/faq.html#faq_190
You should create a table into your database to store a state for each persistents classes : you can store a version number per class, a list of columns, etc... Then it will be quite easy to compare 2 versions of persistent class to modify your SQL schema.
回答2:
Now, you have QxEntityEditor application to manage your database schema evolution. QxEntityEditor is a multi-platform and cross-database graphic editor for QxOrm library. A video presentation of QxEntityEditor features is available here : http://www.qxorm.com/qxorm_en/tutorial_4.html
来源:https://stackoverflow.com/questions/10035686/set-a-version-to-a-sqlite-database-file