Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

ColumnInfo

public abstract @interface ColumnInfo
implements Annotation

android.arch.persistence.room.ColumnInfo


Allows specific customization about the column associated with this field.

For example, you can specify a column name for the field or change the column's type affinity.

Summary

Nested classes

@interface ColumnInfo.Collate

 

@interface ColumnInfo.SQLiteTypeAffinity

The SQLite column type constants that can be used in typeAffinity()  

Constants

int BINARY

Collation sequence for case-sensitive match.

int BLOB

Column affinity constant for binary data.

String INHERIT_FIELD_NAME

Constant to let Room inherit the field name as the column name.

int INTEGER

Column affinity constant for integers or booleans.

int LOCALIZED

Collation sequence that uses system's current locale.

int NOCASE

Collation sequence for case-insensitive match.

int REAL

Column affinity constant for floats or doubles.

int RTRIM

Collation sequence for case-sensitive match except that trailing space characters are ignored.

int TEXT

Column affinity constant for strings.

int UNDEFINED

Undefined type affinity.

int UNICODE

Collation sequence that uses Unicode Collation Algorithm.

int UNSPECIFIED

Collation sequence is not specified.

Public methods

int collate()

The collation sequence for the column, which will be used when constructing the database.

boolean index()

Convenience method to index the field.

String name()

Name of the column in the database.

int typeAffinity()

The type affinity for the column, which will be used when constructing the database.

Inherited methods

Constants

BINARY

int BINARY

Collation sequence for case-sensitive match.

See also:

Constant Value: 2 (0x00000002)

BLOB

int BLOB

Column affinity constant for binary data.

See also:

Constant Value: 5 (0x00000005)

INHERIT_FIELD_NAME

String INHERIT_FIELD_NAME

Constant to let Room inherit the field name as the column name. If used, Room will use the field name as the column name.

Constant Value: "[field-name]"

INTEGER

int INTEGER

Column affinity constant for integers or booleans.

See also:

Constant Value: 3 (0x00000003)

LOCALIZED

int LOCALIZED

Collation sequence that uses system's current locale.

See also:

Constant Value: 5 (0x00000005)

NOCASE

int NOCASE

Collation sequence for case-insensitive match.

See also:

Constant Value: 3 (0x00000003)

REAL

int REAL

Column affinity constant for floats or doubles.

See also:

Constant Value: 4 (0x00000004)

RTRIM

int RTRIM

Collation sequence for case-sensitive match except that trailing space characters are ignored.

See also:

Constant Value: 4 (0x00000004)

TEXT

int TEXT

Column affinity constant for strings.

See also:

Constant Value: 2 (0x00000002)

UNDEFINED

int UNDEFINED

Undefined type affinity. Will be resolved based on the type.

See also:

Constant Value: 1 (0x00000001)

UNICODE

int UNICODE

Collation sequence that uses Unicode Collation Algorithm.

See also:

Constant Value: 6 (0x00000006)

UNSPECIFIED

int UNSPECIFIED

Collation sequence is not specified. The match will behave like BINARY.

See also:

Constant Value: 1 (0x00000001)

Public methods

collate

int collate ()

The collation sequence for the column, which will be used when constructing the database.

The default value is UNSPECIFIED. In that case, Room does not add any collation sequence to the column, and SQLite treats it like BINARY.

Returns
int The collation sequence of the column. This is either UNSPECIFIED, BINARY, NOCASE, RTRIM, LOCALIZED or UNICODE.

index

boolean index ()

Convenience method to index the field.

If you would like to create a composite index instead, see: Index.

Returns
boolean True if this field should be indexed, false otherwise. Defaults to false.

name

String name ()

Name of the column in the database. Defaults to the field name if not set.

Returns
String Name of the column in the database.

typeAffinity

int typeAffinity ()

The type affinity for the column, which will be used when constructing the database.

If it is not specified, the value defaults to UNDEFINED and Room resolves it based on the field's type and available TypeConverters.

See SQLite types documentation for details.

Returns
int The type affinity of the column. This is either UNDEFINED, TEXT, INTEGER, REAL, or BLOB.