ColumnInfo
@Target(allowedTargets = [AnnotationTarget.FIELD, AnnotationTarget.FUNCTION])
@Retention(value = AnnotationRetention.BINARY)
public annotation ColumnInfo
Allows specific customization about the column associated with this property.
For example, you can specify a column name for the property or change the column's type affinity.
Summary
Nested types |
|---|
@IntDef(value = [1, 2, 3, 4, 5, 6]) |
@IntDef(value = [1, 2, 3, 4, 5])The SQLite column type constants that can be used in typeAffinity() |
Constants |
|
|---|---|
static final int |
BINARY = 2Collation sequence for case-sensitive match. |
static final int |
BLOB = 5Column affinity constant for binary data. |
static final @NonNull String |
Constant to let Room inherit the property name as the column name. |
static final int |
INTEGER = 3Column affinity constant for integers or booleans. |
static final int |
LOCALIZED = 5Collation sequence that uses system's current locale. |
static final int |
NOCASE = 3Collation sequence for case-insensitive match. |
static final int |
REAL = 4Column affinity constant for floats or doubles. |
static final int |
RTRIM = 4Collation sequence for case-sensitive match except that trailing space characters are ignored. |
static final int |
TEXT = 2Column affinity constant for strings. |
static final int |
UNDEFINED = 1Undefined type affinity. |
static final int |
UNICODE = 6Collation sequence that uses Unicode Collation Algorithm. |
static final int |
UNSPECIFIED = 1Collation sequence is not specified. |
static final @NonNull String |
A constant for defaultValue() that makes the column to have no default value. |
Public constructors |
|---|
ColumnInfo( |
Public methods |
|
|---|---|
final int |
The collation sequence for the column, which will be used when constructing the database. |
final @NonNull String |
The default value for this column. |
final boolean |
getIndex()Convenience method to index the property. |
final @NonNull String |
getName()Name of the column in the database. |
final int |
The type affinity for the column, which will be used when constructing the database. |
Constants
BINARY
public static final int BINARY = 2
Collation sequence for case-sensitive match.
| See also | |
|---|---|
collate |
() |
BLOB
public static final int BLOB = 5
Column affinity constant for binary data.
| See also | |
|---|---|
typeAffinity |
() |
INHERIT_FIELD_NAME
public static final @NonNull String INHERIT_FIELD_NAME
Constant to let Room inherit the property name as the column name. If used, Room will use the property name as the column name.
INTEGER
public static final int INTEGER = 3
Column affinity constant for integers or booleans.
| See also | |
|---|---|
typeAffinity |
() |
LOCALIZED
public static final int LOCALIZED = 5
Collation sequence that uses system's current locale.
| See also | |
|---|---|
collate |
() |
NOCASE
public static final int NOCASE = 3
Collation sequence for case-insensitive match.
| See also | |
|---|---|
collate |
() |
REAL
public static final int REAL = 4
Column affinity constant for floats or doubles.
| See also | |
|---|---|
typeAffinity |
() |
RTRIM
public static final int RTRIM = 4
Collation sequence for case-sensitive match except that trailing space characters are ignored.
| See also | |
|---|---|
collate |
() |
TEXT
public static final int TEXT = 2
Column affinity constant for strings.
| See also | |
|---|---|
typeAffinity |
() |
UNDEFINED
public static final int UNDEFINED = 1
Undefined type affinity. Will be resolved based on the type.
| See also | |
|---|---|
typeAffinity |
() |
UNICODE
public static final int UNICODE = 6
Collation sequence that uses Unicode Collation Algorithm.
| See also | |
|---|---|
collate |
() |
UNSPECIFIED
public static final int UNSPECIFIED = 1
Collation sequence is not specified. The match will behave like BINARY.
| See also | |
|---|---|
collate |
() |
VALUE_UNSPECIFIED
public static final @NonNull String VALUE_UNSPECIFIED
A constant for defaultValue() that makes the column to have no default value.
Public constructors
Public methods
getCollate
@ColumnInfo.Collate
public final int getCollate()
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.
getDefaultValue
public final @NonNull String getDefaultValue()
The default value for this column.
@ColumnInfo(defaultValue = "No name")
public name: String
@ColumnInfo(defaultValue = "0")
public flag: Int
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")
public description: String?
@ColumnInfo(defaultValue = "'NULL'")
public name: String
You can also use constant expressions by surrounding them with parentheses.
@ColumnInfo(defaultValue = "('Created at' || CURRENT_TIMESTAMP)")
public notice: String
| See also | |
|---|---|
VALUE_UNSPECIFIED |
getIndex
public final boolean getIndex()
Convenience method to index the property.
If you would like to create a composite index instead, see: Index.
| Returns | |
|---|---|
boolean |
True if this property should be indexed, false otherwise. Defaults to false. |
getName
public final @NonNull String getName()
Name of the column in the database. Defaults to the property name if not set.
getTypeAffinity
@ColumnInfo.SQLiteTypeAffinity
public final int getTypeAffinity()
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 property's type and available TypeConverters.
See SQLite types documentation for details.