ColumnInfo
public
abstract
@interface
ColumnInfo
implements
Annotation
androidx.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 |
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. |
String |
VALUE_UNSPECIFIED
A constant for |
Public methods | |
---|---|
int
|
collate()
The collation sequence for the column, which will be used when constructing the database. |
String
|
defaultValue()
The default value for this column. |
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
public static final int BINARY
Collation sequence for case-sensitive match.
See also:
Constant Value: 2 (0x00000002)
BLOB
public static final int BLOB
Column affinity constant for binary data.
See also:
Constant Value: 5 (0x00000005)
INHERIT_FIELD_NAME
public static final 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
public static final int INTEGER
Column affinity constant for integers or booleans.
See also:
Constant Value: 3 (0x00000003)
LOCALIZED
public static final int LOCALIZED
Collation sequence that uses system's current locale.
See also:
Constant Value: 5 (0x00000005)
NOCASE
public static final int NOCASE
Collation sequence for case-insensitive match.
See also:
Constant Value: 3 (0x00000003)
REAL
public static final int REAL
Column affinity constant for floats or doubles.
See also:
Constant Value: 4 (0x00000004)
RTRIM
public static final int RTRIM
Collation sequence for case-sensitive match except that trailing space characters are ignored.
See also:
Constant Value: 4 (0x00000004)
TEXT
public static final int TEXT
Column affinity constant for strings.
See also:
Constant Value: 2 (0x00000002)
UNDEFINED
public static final int UNDEFINED
Undefined type affinity. Will be resolved based on the type.
See also:
Constant Value: 1 (0x00000001)
UNICODE
public static final int UNICODE
Collation sequence that uses Unicode Collation Algorithm.
See also:
Constant Value: 6 (0x00000006)
UNSPECIFIED
public static final int UNSPECIFIED
Collation sequence is not specified. The match will behave like BINARY
.
See also:
Constant Value: 1 (0x00000001)
VALUE_UNSPECIFIED
public static final String VALUE_UNSPECIFIED
A constant for defaultValue()
that makes the column to have no default value.
Constant Value: "[value-unspecified]"
Public methods
collate
public 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 .
|
defaultValue
public String defaultValue ()
The default value for this column.
@ColumnInfo(defaultValue = "No name") public String name; @ColumnInfo(defaultValue = "0") public int flag;
Note that the default value you specify here will NOT be used if you simply
insert the Entity
with @Insert
. In that case, any value assigned in
Java/Kotlin will be used. Use @Query
with an INSERT
statement
and skip this column there in order to use this default value.
NULL, CURRENT_TIMESTAMP and other SQLite constant values are interpreted as such. If you want to use them as strings for some reason, surround them with single-quotes.
@ColumnInfo(defaultValue = "NULL") @Nullable public String description; @ColumnInfo(defaultValue = "'NULL'") @NonNull public String name;
You can also use constant expressions by surrounding them with parentheses.
@CoumnInfo(defaultValue = "('Created at' || CURRENT_TIMESTAMP)") public String notice;
Returns | |
---|---|
String |
The default value for this column. |
See also:
index
public 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
public 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
public 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 .
|
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.