MAD

3. The store

StoreContent/analyitics is an ordinary SQLite database:

StoreContent/analyitics: SQLite 3.x database, last written using SQLite version 3043002,
  writer version 2, read version 2, file counter 52, database pages 126, cookie 0x6e,
  schema 4, largest root page 113, UTF-8, vacuum mode 1, version-valid-for 52

It holds the document definition: the query, its tables and joins, the report’s sections and elements, and the database schema snapshot. The Core Data model is MAD/MAD.xcdatamodel; its entities all carry the Rptq prefix (RptqDocument, RptqQuery, RptqDocumentElement, RptqDocumentSection, …).

Two properties of this store are load-bearing for portability:

  1. It is written in WAL mode. -wal and -shm are shipped inside the archive alongside the main database. A reader that extracts only analyitics and ignores the WAL will read a database up to one checkpoint stale. In the Music sample the WAL is 313 KB against a 516 KB main file – this is not a theoretical risk.
  2. It is a Core Data store, so its schema is Core Data’s, not ours. Reading it without Core Data means reading Core Data’s own tables. That is possible – it is SQLite, and the mapping is stable – but it is the part of this format that ties a reader to Core Data, and it is the reason the migration off Core Data matters here more than anywhere else.

3.1 The portable store (since the store migration)

Since the store migration (docs/project/MAD_STORE_MIGRATION.md), a document’s definition lives in a portable SQLite store of our own design. Its schema is described by the hand-maintained MADStoreSchema descriptors (MAD/Source/rptq/store/), generated by -createSchemaSQL, and cross-checked against the compiled model by MADStoreTests. The store records its schema version in PRAGMA user_version: version 1 is the schema as it shipped (absent or 0), version 2 adds RptqQuery.sqlSourceText – the user’s pasted SQL, kept verbatim (docs/project/MAD_SQL_ENTRY.md §8) – and MADStore applies the missing steps on open. The RptqQuery table’s fields:

Column Type Notes
identifier INTEGER the row key
cachedText TEXT  
override INTEGER  
overrideText TEXT  
sqlSourceText TEXT the last successfully applied pasted statement, verbatim; NULL otherwise
inDatabase_identifier INTEGER foreign key to RptqDatabase