user3127791
user3127791

Reputation: 101

Data Types used in SQLite

I'm confused what to declare as datatype in SQLite for the following: 1.email 2.phone number 3.password(Some articles I find that they use String instead of int for phone number and password , why is it so?)

Upvotes: 10

Views: 20542

Answers (3)

Matt Stevens
Matt Stevens

Reputation: 1124

Use String for all three.

String enables the use of the full character set, including lower case, upper case, numerals and special characters. Each of the examples you give (email, phone number and password) will use elements from the full character set. (email '@', phone '-' & '()' and passwords are more effective the larger the character set chosen from.)

Strings may also be parsed with Regular Expressions to validate them and achieve database wide conformity. For example you may choose a consistent format for phone numbers of '++64 4 12345678' and use RE's to achieve that state before saving it to the database. Equally you might use REs to strip all extra characters and save the phone number as an int.

Passwords using just int, have a character base of 10 characters, the full character set has (26+26+10+33)=95 characters. If your password is 8 characters long, that is 10^8 or 100,000,000 combinations (trivial to brute force) or 95^8 which a heck of a lot more (getting a lot more difficult to brute force).

Upvotes: 0

user2339071
user2339071

Reputation: 4310

There are fundamentally 5 types of datatypes in SQLite:

1.) NULL 2.) BLOB 3.) INTEGER 4.) REAL 5.) TEXT

You can read them up on the following page SQLite Datatypes.

As for your question :

1.) Since Email can contain alphanumeric and special characters, this field has to be declared as TEXT.

2.)For a phone number , you have to decide as to how to store the numbers. For e.g. one of the guys would want his phone number to be stored as

4567890

While some other guy would want the same number to be stored as

456-7890

In the first case , the datatype would be INTEGER while in the second case it would TEXT as the second case consists of special character.

3.) For password , use TEXT as it can have any character. Be sure to encrypt it though.

Hope it helps. :)

Upvotes: 9

Chintan Soni
Chintan Soni

Reputation: 25267

The reason behind using string is that, Sqlite was made much flexible and dynamic.

Check this link: http://www.sqlite.org/datatype3.html

First two paragraphs answers all of your questions.

Upvotes: 2

Related Questions