More
Upgrading
What an application written for an earlier XOD 2.x must change or check before it moves to a later version.
This page is a checklist for moving an application to a later XOD version. Start at the section for the version you have and work up. Each item links to the page that explains it. Back up the database folder before the first open with the new version, and close every context of the old version first.
Upgrading from 2.1.0 to 2.2.0
The file format is compatible: 2.2.0 opens 2.1.0 databases directly (scanning every page once at the first open to check for duplicate row codes), and 2.1.0 reads databases written with stored map comparers under its default comparers. What an application written for 2.1.0 must check before it moves to 2.2.0.
Code that no longer builds cleanly
[Inherited],LazyLoadFilterandReservedPropertyTypeare obsolete (warning CS0618, an error in a build that treats warnings as errors). They did nothing (see Attributes and XodContext API).
What can now throw
- A map property XOD can’t construct or whose keys or values aren’t scalars (
Dictionary<string, object>, a map of a class, interface orUri, or a map type with no parameterless constructor, entries constructor or known factory) is refused when its class is first used. A 2.0.x row written for anIDictionary<K, V>property throwsDatabaseFileExceptionnaming the row and property (SQL readsNULLwith warningXQ014) (see Supported types). - An
objectproperty holding a collection, string, number, date,Guidor struct (without[GenericTypeProperty]naming the full type), or aList<object>holding a collection, string, number or struct, is refused when written and in a query by example. - An undefined
StorageFormatthrowsArgumentOutOfRangeExceptionin a context,XodMigratorandxod convert(see DatabaseOptions). - A missing page file named by a table, or an index entry whose row isn’t on its page, throws
DatabaseFileExceptioninstead of skipping rows silently (see Storage). - Inserting a parent with a child another parent lists throws
ReservedChildException(see Relationships). - Inside a
BeforeActionorAfterActionhandler,Flush,ClearCache/ClearCachesandGetStatisticsthrowInvalidOperationExceptionin buffered mode or a transaction, andCommit/RollbackthrowTransactionExceptionin every mode (see Events). - Reading a map whose stored culture is unavailable on the reading machine (including
globalization-invariant mode) throws
DatabaseFileExceptionnaming the culture.
Behaviour to check
- A derived class inherits XOD attributes from
virtualbase properties it overrides ([PrimaryKey],[UniqueKey],[Property],[NotMapped], relations). Check derived classes that relied on base attributes being ignored on overrides (see Modelling data). - A
Guid? Idgets a newGuidwhen inserted null (autonumber by convention). Existing rows keep their stored key (see Primary keys). - In
DurabilityMode.Buffered,InsertRange,DeleteandDeleteWherewait forFlush(), as every other buffered write does, and every failed write in buffered mode or a transaction leaves nothing of itself (see Transactions and durability). - Self-referencing and mutually-referencing
[ForeignKey]relations followCascade = UpdateandCascade = Delete(see Relationships). - String-keyed built-in maps store and restore their
StringComparer, and sorted string maps without a stored comparer read back in ordinal order rather than the reading machine’s culture order (see Supported types). - The first open of an existing database reads every page once to check for duplicate row codes, recodes any it finds (rebuilding indexes if needed), and records that check in the database file.
Upgrading from 2.0.3 to 2.1.0
The file format is the same. What an application written for 2.0.3 must check before it moves to 2.1.0.
What can now throw
- A key part at its type’s default. A row whose key isn’t an autonumber is refused with
MissingPrimaryKeyValueExceptionwhen a key part is0,false, an enum’s first member, an emptyGuid, or an empty or null string. So is an update by such a key, and an update or delete by an example that sets some key parts and not others. A row 2.0.3 stored that way can’t be updated or deleted by its key: remove it withDeleteWhere(see Models). - A type XOD can’t store or read back. A class with a property of
Int128,Half,BigInteger,nint, a tuple or a struct of your own, or a collection aList<T>can’t be assigned to (class Notes : List<Note>,HashSet<T>,ArrayList), is refused withXodExceptionwhen it is first used. Mark the property[NotMapped]or change its type. 2.0.3 stored these and read them back empty or at their default. - A write inside a read on the same thread, such as in a query’s predicate or while its results are
enumerated, throws
XodException, for every table. Make the write after the read (see Writing). - Inside a trigger,
BeginTransactionthrowsTransactionException, and setting, changing or removing the password throwsInvalidOperationException.
Behaviour to check
- A transaction belongs to the code that began it. Other threads’ reads and writes wait for it to end,
up to
TransactionTimeoutMs, and no longer see or join its writes. Keep transactions short, and begin one where its work is done (see Transactions). - Writes are made one at a time, for every table.
InsertRange,DeleteWhereandDropAllare each one write. Outside a transaction, with the default durability, one refused item leaves none of it done.DeleteWherereturns the number of rows it deleted.- A parent’s update writes its
[Children]and the relations declaredCascade = CascadeOptions.Update, and no others. A plain list or reference of objects with a key only links them. Declare[Property(Cascade = CascadeOptions.Update)]on it, or update those objects yourself (see Relationships). - Deleting a row deletes its children and its plain lists of objects without a key, with their triggers.
An
objectproperty deletes the row of a keyed type it holds only withCascade = Delete. Clearing aCascade = Deletereference in an update deletes its row. - A child without a key is written again at each update of its parent: its old row is deleted and a new one inserted, with their triggers. Give it a key to have it updated in place.
- The obsolete
CryptoHelper.EncryptPropertyandDecryptProperty, given a passphrase, take about 25 ms a call. A[Crypto(AES256)]property is encrypted by the database itself. - A password-protected database written by 2.0.x reads each file a little slower, once per context, until the file is written again.
Upgrading from 2.0.2 to 2.0.3
What an application written for 2.0.2 must check before it moves to 2.0.3.
One context per database
- A database is open in one context at a time. Keep one
XodContextper database for the life of the application (a singleton, not one per request or per scope) and dispose it. A second open, in the same process or another, waitsLockRetryTimeoutMs, then throwsDatabaseLockedException. A context never disposed keeps the database until the garbage collector finalizes it (see Processes). LockDatabaseno longer changes anything. Code that sets it still compiles.- The command-line tool (
xod stats,xod queryand the others) is refused while an application has the database open (see Command-line tool).
Before the first open
- XOD 2.0.2 and 2.0.3 keep each other out. 2.0.2 holds the lock files shared and 2.0.3 alone, so whichever opens second is refused with
DatabaseLockedException. XOD 2.0.0 and 2.0.1 take no lock unlessLockDatabaseis set: don’t run them beside 2.0.3. - Leave the lock files alone.
xod.lockandapp.xod.locksit beside the database file and are never deleted, as in 2.0.2. A folder where they can’t be created or opened is opened for reading only, and nothing keeps a writer out beside such a reader (see Read-only folders). - Where the file system gives no lock (an NFS client, for example), every open is refused, since nothing
would keep a second context out. On Linux or macOS, setting
DOTNET_SYSTEM_IO_DISABLEFILELOCKING=1opens it, taken as saying nothing else opens the database. - A context that can only read the folder, with the lock files there, holds the database too. A reader run by another user keeps the application’s open out until it closes.
- A transaction no longer sets files aside. A
.xdelfile 2.0.2 left at a crash is put back by the next open (see What’s in the folder).
Code that no longer builds cleanly
XmlExtensions.ElementMatchis obsolete (warning CS0618, an error in a build that treats warnings as errors): XOD no longer matches rows by it (see XodContext API).
What can now throw
- A second context’s open throws
DatabaseLockedException, as above. Secure,ChangePasswordandLoosethrowXodExceptionover a.xdelfile or a password change’s own files a crash left, as they do over a journal (see Adding, changing and removing the password).
Behaviour to check
- Matching by example compares text exactly and numbers by value, with or without an index:
Queryby example,UpdateandDelete, and, withEnableIndexing = false, the primary-key and unique checks. Without an index, 2.0.2 compares text ignoring case, so code that relied on “alice” finding “Alice” gets nothing. Match the case, or query with a lambda (see Query many and Indexes). - Referenced objects are built afresh by every query: two queries give two instances of one customer. Code that compared them by reference, or relied on an unsaved change to one showing in the next query, needs changing (see Loading relationships).
- A rollback writes nothing back, and a transaction’s deletes take effect at its commit (see Transactions).
- The
AES256key is made when a database gets a secret: at its creation with a password orPropertyEncryptionKey, or bySecure,ChangePasswordorLoose(see A key of the database’s own). - A database from XOD 1.x: an encrypted one opens with its password, and 1.x digests verify and are kept by an update (see Moving from XOD 1.x).
Upgrading from 2.0.0 or 2.0.1 to 2.0.2
What an application written for 2.0.0 or 2.0.1 must change or check before it moves to 2.0.2. Read Moving back to 2.0.0 or 2.0.1 before you rely on going back.
Code that no longer builds cleanly
IdentitySeedandIdentityIncrementareobject, where 2.0.1 hasdynamic. Code that reads them as a number (int seed = attribute.IdentitySeed;) needs a cast. They can now be set (see The Property attribute in full).- A subclass of
[Property]that setsIdentitySeedorIdentityIncrementin its constructor (2.0.1’s only way to set them) still numbers a number property as before. On aGuidautonumber, 2.0.1 ignores them; 2.0.2 refuses the type withAutonumberSeedExceptionwhen it is first used, even for a value of- Don’t put such a subclass on a
Guid(see The Property attribute in full).
- Don’t put such a subclass on a
- Obsolete members give warning CS0618, an error in a build that treats warnings as errors:
XodSecurityServiceandIXodSecurityService: useSecure,ChangePasswordandLooseon the context (see Passwords and encryption);CryptoHelper.EncryptPropertyandDecryptProperty, which use 2.0.1’s form of anAES256value:[Crypto(CryptoMethod.AES256)]encrypts and decrypts the property itself (see Encrypting a property);DatabaseOptions.EnableCompression, which never had an effect: useStorageFormat.Binary(see DatabaseOptions).
Property encryption
AES256without a database password. XOD 2.0.2 won’t encrypt with the key built into the library. A database with no password and noDatabaseOptions.PropertyEncryptionKeyrefuses every insert or update that stores anAES256value withSecurityException; reads still work, the values 2.0.1 wrote included. SetPropertyEncryptionKey(or a password) before the upgrade goes live (see A key of the database’s own).- Values 2.0.1 encrypted aren’t converted until their row is next written (see A key of the database’s own).
[Crypto]on a type that isn’tstring, or on a property that is indexed, a unique key or a primary key, is refused when the type is first used, withCryptoDataTypeExceptionorIndexDataTypeException. 2.0.1 ignores[Crypto]on other types and stores the plain value. Change the model first (see Attributes).[Crypto]on a value stored as an attribute (ValuePosition.Attribute) is now applied, where 2.0.1 stores the value as written (see Attributes).- Changing or removing the password is refused with
SecurityExceptionwhen the database holdsAES256values 2.0.1 wrote under it and the change would leave them unreadable (see Adding, changing and removing the password).
Locks, processes and password changes
LockDatabasekeeps out every other context, withLockDatabaseor without: an open while aLockDatabasecontext or process has the database getsDatabaseLockedException,xod statsincluded. 2.0.1 keeps out only contexts that also setLockDatabase(see Processes andxod stats).- A password change needs the database to itself.
Secure,ChangePasswordandLooseare refused withXodExceptionwhile another context or process has the database open, and withTransactionExceptioninside a transaction. While a change runs, an open elsewhere getsDatabaseLockedException(see Adding, changing and removing the password). - Contexts opened at once on a new database. The open that creates it holds the folder alone until its
database file is written; another open meanwhile waits up to
LockRetryTimeoutMs, then getsDatabaseLockedException. 2.0.1 lets both go on. Open the first context before the others, or setLockRetryTimeoutMs(see One database per folder). - Dispose every context. One left to the garbage collector holds the lock file, and keeps out
LockDatabaseopens and password changes until it is finalized (see Processes). - Leave the new files alone. The database’s lock file now stays after the close, and so does the
folder’s,
xod.lock; the folder can also hold.xidxdirty,.xdel,.xpwlogand.xpwnewfiles. Don’t delete them while the database is open (see What’s in the folder). - A folder XOD can’t write opens for reading only when the lock file can’t be opened or created; with
LockDatabase, the open throwsUnauthorizedAccessException(see Read-only folders).
Files, folders and conversion
- One database per folder. Opening a folder that holds more than one database file, or a path naming a
new database file beside an existing one, is refused with
XodException(see One database per folder). - The migrator needs an empty target.
XodMigrator.ConvertDatabaseandxod convertrefuse a target folder that holds anything, and a source that a context or process has open (see Converting between formats). - The format comes from the database. Without
StorageFormatset, a context writes a database in the format its database file records, where 2.0.1 writes the one the extension or the options pick (XML for options that don’t set it). So a.xoddatabase converted to JSON or binary in place is now written in JSON or binary, and a.xodjor.xodbdatabase opened with options that don’t set a format is written in the format it records, not in XML (see Choosing a format). - A new database in a folder named
.jsonor.binis XML. SetStorageFormatto create it in JSON or binary. A database 2.0.1 created that way keeps its format (see Choosing a format). - Table files gain a
<Schema>element at the next write to each table, so a database folder kept in version control shows each.xtabfile changed once (see What’s in the folder). - Indexes are rebuilt from the pages the first time each is needed, so the first queries after the upgrade take longer (see Moving back to 2.0.0 or 2.0.1).
Behaviour to check
- Writes from inside a read that need a lock the read holds back throw
XodException, where 2.0.1 throwsLockRecursionException. Code that catches the latter needs changing (see Writes from many threads). - Values read back as written: an empty string comes back as
"", and anullasnull, where 2.0.1 can returnnullor what a new instance holds (see Values read back as written). - Maps and lists read back as written: a dictionary’s
nullvalue comes back asnull, where 2.0.1 gives""; a list or array keeps itsnullitems, which 2.0.1 drops; and an empty dictionary comes back empty, where 2.0.1 givesnull(see Values read back as written). - Autonumbers aren’t handed out again after a delete and a reopen, and an update that leaves an autonumber at 0 keeps the row’s number (see Primary keys and Update).
- A failed write behaves differently: a statement that fails removes the rows it created, a handler
that throws makes the write fail, and a failed write is kept: an
Insertis taken back, so it can be retried, but anInsertRange,UpdateorDeletethat threw is still made by the next flush (see Writes outside a transaction and Durability). xodoutput sent to a file or a pipe is UTF-8, where 2.0.1 writes it in the console’s code page. A script that reads it in another encoding needs changing (see Command-line tool).
Moving back to 2.0.0 or 2.0.1
Plan for these before a database written by 2.0.2 or later goes back to 2.0.0 or 2.0.1:
- A page with a control character in any value is one 2.0.1 can’t read at all: every read of that page
fails with
DatabaseFileException. - An
AES256value 2.0.2 wrote reads in 2.0.1 as its stored text, and if 2.0.1 saves the row, the value is lost. - Don’t run both at once. 2.0.1 takes no lock without
LockDatabase, and deletes the lock file at the close with it (see Processes). - Empty and
nullvalues 2.0.2 wrote read back differently in 2.0.1, and 2.0.1 rebuilds the indexes 2.0.2 wrote the first time it needs them. - A row that holds a list of a nullable type (
List<int?>), or an empty map of a type other thanDictionary<K, V>, can’t be read by 2.0.1.