SQLite Create a table Be sure to declare the field type (small problem with ContentProvider query)

Source: Internet
Author: User

Use ContentProvider to inquire, sometimes not very spirit. Like the following code, the data exists in the database, but it can't be found. The reason may be that the field does not have a claim type:

As follows:

Private final static String sql_create_table_installed =
"CREATE TABLE if not exists" + table_installed + "("
+ "id not null,"
+ "Name text NOT NULL,"
+ "PRIMARY key (ID)"
+")";

There is no problem with this ID field. Using the following contentprovide to query will not find data ...

Contentresolver resolver = Context.getcontentresolver ();
Uri uri = Getcontenturi ();
cursor cursor = resolver.query (URI, Datacolumns.all, datacolumns.id
+ "=?", new string[] {integer.tostring (ID)},
Default_order);

Such a small problem is really no solution.

It can be found in the following ways. Directly with the parameter check.

cursor cursor = resolver.query (Getcontenturi (), Datacolumns.all,
datacolumns.id + "=" + ID, NULL, default_order);

So, write the code carefully, when creating the table, pay attention to the various field types. SQLite does not check the field type.

SQLite creates a table be sure to declare the field type (small problem with ContentProvider query)

Related Article

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.