Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Max length of Android Sqlite String?

In reference to this question:

How SQLite on Android handles long strings?

It says that default SQLite stores at 1 billion. This is the same as the actual site.

However, as the person states, it could be less. I was wondering if their is a way to check/what is this value?

Thanks!

like image 795
Justin Warner Avatar asked Apr 19 '13 04:04

Justin Warner


People also ask

What is the maximum size of SQLite database in Android?

Maximum Database Size 140 tb but it will depends on your device disk size.

How big is too big for SQLite?

An unlikely requirement for an engine popular on Android and iOS. SQLite, which claims to be "used more than all other database engines combined", has been updated to version 3.33. 0 with the maximum size increased to 281TB, around twice the previous capacity of 140TB.

What is the maximum size of SQLite varchar?

(9) What is the maximum size of a VARCHAR in SQLite? SQLite does not enforce the length of a VARCHAR. You can declare a VARCHAR(10) and SQLite will be happy to store a 500-million character string there. And it will keep all 500-million characters intact.

Does SQLite support long?

SQLite does not support built-in date and time storage classes. However, you can use the TEXT, INT, or REAL to store date and time values.


2 Answers

Maximum length of a string or BLOB

The maximum number of bytes in a string or BLOB in SQLite is defined by the preprocessor macro SQLITE_MAX_LENGTH. The default value of this macro is 1 billion (1 thousand million or 1,000,000,000). You can raise or lower this value at compile-time using a command-line option like this:

-DSQLITE_MAX_LENGTH=123456789 

The current implementation will only support a string or BLOB length up to 231-1 or 2147483647. And some built-in functions such as hex() might fail well before that point. In security-sensitive applications it is best not to try to increase the maximum string and blob length. In fact, you might do well to lower the maximum string and blob length to something more in the range of a few million if that is possible.

During part of SQLite's INSERT and SELECT processing, the complete content of each row in the database is encoded as a single BLOB. So the SQLITE_MAX_LENGTH parameter also determines the maximum number of bytes in a row.

From http://www.sqlite.org/limits.html.

like image 99
Triode Avatar answered Sep 19 '22 16:09

Triode


The is no way to read SQLite limits in Android at runtime. (SQLite has a function for this in its C API, but Android does not expose this.)

In any case, I do not know of any Android vendor that has reduced any of SQLite's limits. (Usually, they increase some limit or enable some option when they need it in their own apps or when they try to optimize, but they never bother to change something otherwise.)

like image 40
CL. Avatar answered Sep 19 '22 16:09

CL.