Easy way to store SQLite database metadata

I was wondering if there is an easy way to store meta information about sqlite-Database in this database.

I specifically think about the version number, which allows you to easily find out which version of the database layout you are using (so my code could check the compatibility of the database structure without querying SELECT sql FROM sqlite_master WHERE type='table'; and comparing the result with a predefined schema) . To clarify: I'm not interested in the sqlite software version number, but something similar to the pythons __version__ variable, which can be defined separately for each python file.

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

I also know that checking for compatibility, only checking the version number, has some problems, and I will continue to do other checks if necessary, but for now I'm only interested in the version number that I described.

+6
source share
2 answers

You might want to check the user_version pragma .

+3
source

SQLite offers two slots for storing an integer as metadata.

application_id

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

Set application_id to 900

 PRAGMA application_id = 900; 

Get application_id

 PRAGMA application_id; 

user_version

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

Set user_version to 901

 PRAGMA user_version = 901; 

Get user_version

 PRAGMA user_version; 
+1
source

Source: https://habr.com/ru/post/909938/


All Articles