One benefit of specifying types when Android sqlite CREATE table

Source: Internet
Author: User
Tags sqlite create table

Use an example to explain the recent encounter with a problem.

In the android sqlite3 command line, execute CREATE TABLE T (a). The specific type of a is not specified here.

Then execute INSERT into T values (0).

If I use "select * from t where a = 0" in the sqlite3 command line, the query succeeds and fails if "select * from T where a= ' 0 '".

The reason is I'm calling Values.put ("a", 0), and 0 is an integer, so the database is considered a number. So the where uses ' 0 ', the database does not know what type the column should use, so it will not be converted into a number, so the query is not the thing.

If you create table T (a integer), specifying that the type of a is integer, the two statements will be successful.

Because the SQL parser knows the specific type of the column, even if you specify string ' 0 ' to come in, you can still automatically convert to the number 0 and then query.

When writing a program in Java, because sqlitedatabase.rawquery specifies that the SQL parameter must be of type string, if you do not specify a specific type when you create the table, the string does not automatically convert to a number, then the query fails.

One benefit of specifying types when Android sqlite CREATE table

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.