How to choose a magic number for SQLite's PRAGMA application_id

0

So there's PRAGMA application_id meant to identify a SQLite database that is used as the file format of a program as this specific file format. The docs say one should choose a unique signed 32 bit integer for this and link https://www.sqlite.org/src/artifact?ci=trunk&filename=magic.txt as a list of registered types. But in this file, there are only a few entries.

So I have two questions:

  1. Is it meaningful and common to actually run this pragma when using SQLite as the file format for a program?

  2. If so, how should that number be chosen? Simply a random number? Or somehow derived from the program's name, homepage or whatever?

Edit:

In addition to the MikeT's answer, I want to add that using this feature, a file can be identified by the file (1) using a magic definition, also including the user_version. For e. g. 123 like so:

0 string SQLite\ format\ 3
>68 belong =int(0x0000007b) Program 123 file (using SQLite)
>>60 belong x \b, Version %d

which actually might be a nice use-case, as one can simply distinguish the file from a "plain" SQLite datase in this way.

sqlite
asked on Stack Overflow Nov 15, 2019 by Tobias Leupold • edited Nov 18, 2019 by Tobias Leupold

1 Answer

0

Is it meaningful and common to actually run this pragma when using SQLite as the file format for a program?

It is a rarely used feature and would only be meaningful to a specific application which would handle it in it's own way. It's basically a variable that can be set/changed to indicate to the specific application.

Say for example the application wanted to handle encrypted/non encrypted data the value could be set to indicate an encrypted database (or be a value to indicate one of a set of different encryption methods) or a non-encrypted, thus you could have a single easily and efficiently obtained value to determine which type.

  • Of course other methods could be used e.g. if the user_version isn't otherwise utilised that could be used.

If so, how should that number be chosen? Simply a random number? Or somehow derived from the program's name, homepage or whatever?

The number, if used, should probably be set simply as it would need to be interpreted into a meaningful value. A random value would probably not be of any use.

In short it's a 4 byte field in the header that can be used as desired, similar to the user version field. However, it has the advantage that is less likely to alreadey be used, as an example if using the Android SDK/API's then the user_version is utilised for versioning and should not be used (or used with great care).

answered on Stack Overflow Nov 15, 2019 by MikeT

User contributions licensed under CC BY-SA 3.0