

REAL numbers are the number with double floating points precision. INTEGER type affinity in SQLite can hold any assigned integer number (positive or negative) from 1 byte to maximum 8 bytes. It will be stored in an INTEGER storage class.Īll the following data types are assigned as an INTEGER type affinity: Mapping between SQLite data types and affinities Examples of Storing Data types in SQLite: Storing number with SQLite integer:Īny column of data type contains the “INT” word, it will be assigned an INTEGER type affinity. There is also a table on the same page showing some examples for the mapping between SQLite data types and their affinities determined by these rules: NUMERIC affinity is assigned for any other data type.REAL affinity is assigned if the type contains one of the following strings “ DOUB“, “ REAL, or “ FLOAT“.BLOB affinity is assigned if the column has no type specified or the data type is a BLOB.For example, the type VARCHAR will be assigned the TEXT affinity. TEXT affinity is assigned, if the column contains on its data type one of the following strings “ TEXT“, “ CHAR, or “ CLOB“.INTEGER affinity is assigned if the declared type contains the string “ INT“.Here’s how SQLite determines the affinity of the column from its declared data type: Here the lift of type affinities in SQLite: These types were introduced in SQLite to maximize the compatibility between SQLite and other database management system.Īny column declared in an SQLite database is assigned a type affinity depending on it declared data type. However, you still can store any type of data as you wish, these types are recommended not required. Type affinity is the recommended type of data stored in a column. The value is stored as byte array the same as the input value. BLOB – used to store large files, like images or text files.It also supports different encoding like UTF-8, UTF-16 BE, or UTF-26LE. REAL – this storage class is used to store the floating point values, and they are stored in an 8-bytes of storage.


The INTEGER values in SQLite are stored in either 1, 2, 3, 4, 6, or 8 bytes of storage depending on the value of the number.

The following are the storage classes available in SQLite: In SQLite there are different storage methods depending on the type of value, these different storage methods are called storage classes in SQLite. And then SQLite stores that value depending on its type. However, in dynamic types like in SQLite, the type of the column is determined by the value inserted. In static types, like in other database management systems, if you declared a column with a data type integer, you can only insert values of data type integer. There are no data types, you can store any type of data you like in any column. Examples of storing data types in SQLite.In SQLite, you can declare data types normally, but you still can store any value in any data type. Return values in the query results instead.Data types in SQLite are different compared to other database management system. SQLite doesn't support output parameters. Convert TimeSpan to days instead of textĬ("$expected", expected).SqliteType = SqliteType.Real ValueĪND julianday('now') - julianday(started) > $expected For the default mappings, see Data types. The following alternative type mappings can be used. Do this by setting the SqliteType property. Sometimes, you may want to use an alternative SQLite type. Truncate name to 30 charactersĬ("$name", name).Size = 30 Use the Size property to truncate TEXT and BLOB values. command.CommandText INTO user (name)Ĭ("$name", name) Parameters can be prefixed with either :, or $. In SQLite, parameters are typically allowed anywhere a literal is allowed in SQL statements. Instead of concatenating user input with SQL statements, use parameters to ensure input is only ever treated as a literal value and never executed. Parameters are used to protect against SQL injection attacks.
