Easy way to store metadata about SQLite Database

岁酱吖の 提交于 2019-12-07 00:45:24

问题


I was wondering if there is a simple way to store meta information about an sqlite-Database in that database.

I am specifically thinking about a version number that lets you easily find out which version of a database layout you are using (So my code could check if the database structure is compatible without querying SELECT sql FROM sqlite_master WHERE type='table'; and comparing the result with a predefined schematic). To clarify: I am not interested in the version number of the sqlite software, but something akin to pythons __version__ variable that can be defined seperately for each python file.

I know that I can probably just create a table named "meta" and save it there, but I was wondering if there was a better way to do that.

I also know that checking compatibility by only checking a version number has some problems, and I will still do other checks if necessary, but for now I am only interested in the version number I described.


回答1:


You might want to check out the user_version pragma.




回答2:


SQLite offers two slots to store an integer as metadata.

application_id

https://www.sqlite.org/pragma.html#pragma_application_id

Set an application_id to 900

PRAGMA application_id = 900;

Get the application_id

PRAGMA application_id;

user_version

https://www.sqlite.org/pragma.html#pragma_user_version

Set an user_version to 901

PRAGMA user_version = 901;

Get the user_version

PRAGMA user_version;


来源:https://stackoverflow.com/questions/9555479/easy-way-to-store-metadata-about-sqlite-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!