Android.Database.Sqlite.SQLiteDatabase.SetForeignKeyConstraintsEnabled Method
Sets whether foreign key constraints are enabled for the database.

Syntax

[Android.Runtime.Register("setForeignKeyConstraintsEnabled", "(Z)V", "GetSetForeignKeyConstraintsEnabled_ZHandler")]
public virtual void SetForeignKeyConstraintsEnabled (bool enable)

Parameters

enable
True to enable foreign key constraints, false to disable them.

Exceptions

TypeReason
Java.Lang.IllegalStateExceptionif the are transactions is in progress when this method is called.

Remarks

Sets whether foreign key constraints are enabled for the database.

By default, foreign key constraints are not enforced by the database. This method allows an application to enable foreign key constraints. It must be called each time the database is opened to ensure that foreign key constraints are enabled for the session.

A good time to call this method is right after calling SQLiteDatabase.OpenOrCreateDatabase(Java.IO.File, .ICursorFactory) or in the SQLiteOpenHelper.OnConfigure(SQLiteDatabase) callback.

When foreign key constraints are disabled, the database does not check whether changes to the database will violate foreign key constraints. Likewise, when foreign key constraints are disabled, the database will not execute cascade delete or update triggers. As a result, it is possible for the database state to become inconsistent. To perform a database integrity check, call SQLiteDatabase.IsDatabaseIntegrityOk.

This method must not be called while a transaction is in progress.

See also for more details about foreign key constraint support.

[Android Documentation]

Requirements

Namespace: Android.Database.Sqlite
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 16