Skip to content

Most visited

Recently visited

navigation
added in version 1.0.0
belongs to Maven artifact android.arch.persistence.room:common:1.0.0

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 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 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

From interface java.lang.annotation.Annotation

Constants

BINARY

added in version 1.0.0
int BINARY

Collation sequence for case-sensitive match.

See also:

Constant Value: 2 (0x00000002)

BLOB

added in version 1.0.0
int BLOB

Column affinity constant for binary data.

See also:

Constant Value: 5 (0x00000005)

INHERIT_FIELD_NAME

added in version 1.0.0
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

added in version 1.0.0
int INTEGER

Column affinity constant for integers or booleans.

See also:

Constant Value: 3 (0x00000003)

NOCASE

added in version 1.0.0
int NOCASE

Collation sequence for case-insensitive match.

See also:

Constant Value: 3 (0x00000003)

REAL

added in version 1.0.0
int REAL

Column affinity constant for floats or doubles.

See also:

Constant Value: 4 (0x00000004)

RTRIM

added in version 1.0.0
int RTRIM

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

See also:

Constant Value: 4 (0x00000004)

TEXT

added in version 1.0.0
int TEXT

Column affinity constant for strings.

See also:

Constant Value: 2 (0x00000002)

UNDEFINED

added in version 1.0.0
int UNDEFINED

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

See also:

Constant Value: 1 (0x00000001)

UNSPECIFIED

added in version 1.0.0
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, or RTRIM.

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.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)