Android Question SQLite and Data Types

tdocs2

Well-Known Member
Licensed User
Longtime User
Greetings.

This is info I found from previous questions I asked and trial and error. I hope is of help to some of the new users.

First, data types (from an A Graham post (I have it in a Word doc and cannot find the post):

B4X:
They are all standard Java data types. B4A doesn't support Decimal or Currency.

Byte : 1byte signed: -128 to 127
Char : 2bytes unsigned: 0 to 65535 : not all values are valid Unicode code points
Short : 2bytes signed: -32768 to 32767
Int : 4bytes signed: -2147483648 to 2147483647
Long : 8bytes signed: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (9.2...E+18)
Float : 4bytes +/- 3.4e +/- 38 (~7 digits)
Double : 8bytes +/- 1.7e +/- 308 (~15 digits)

Second: SQLite types:

INTEGER, TEXT, REAL, OR BLOB

Third, some nomenclature discrepancies.

Everyone knows that dates cannot fit in an integer. You need a double (Erel's quote).
In SQLite, a date goes into an Integer.

No currency type. Currency in SQLite Real, in B4A, Double.
Amendment: Best to keep Currency in SQLite as INTEGER - up to 8 bytes. B4A Long. Manage decimal points in coding.

Text and Integer are self explanatory. BLOB's are a true challenge but great for pics.
 
Last edited:

tdocs2

Well-Known Member
Licensed User
Longtime User
How do you manage date fields?

For example, to filter between two dates;
TO select only the records of one month;
etc..

I prefer to use TEXT for date fields (YYYY/MM/DD)

I love the YYYY/MM/DD or better YYYYMMDD format but you have to parse to convert to ticks to do computations... Also, there is the international aspect AHLocale...

Sorry, Luca, I did not set this up to receive emails, so I did not see your comment until now.

Best regards.

Sandy
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…