Database Operation Summary

Source: Internet
Author: User

Sqlitedatabase is about database operations that can be used for insert Delete update query and other operations. Unfortunately, the following are some shortcomings:

1. database creation is not supported

2. version updates are not supported.

So the sqliteopenhelper class appears, which is an abstract class and generally inherits from it.

Generally, three functions are required:

Constructor

Oncreate () is used during initialization and is generally used for table creation.

Onupdate () is used for upgrade. Generally, the existing table is deleted and then rebuilt.

Then, use the sqliteopenhelper class function: getwritabledatabase () or getreadabledatabase () to obtain the database instance.

Then perform query, insert, update, and delete operations.

MDB. insert (table_name, null, newvalues );

Newvalues is a collection similar to bundle and hashtable. It stores key-value pairs.

MDB. Delete (table_name, ID + "=" + id, null );

Return MDB. Delete (table_name, null, null );

Public personinfo [] queryonedata (long ID)

{

Cursor result = MDB. Query (table_name, new string [] {ID,
Personinfo_code, personinfo_displaypicture,
Personinfo_nickname, personinfo_birthday, personinfo_gender,
Personinfo_signature, personinfo_signaturedatetime,
Personinfo_password, personinfo_displaypicturebinary,
Personinfo_registertime, personinfo_updatetime },

ID + "=" + id, null, null );

Personinfo [] pinfo = converttopersoninfo (result );
If (result! = NULL &&! Result. isclosed ()){
Result. Close ();
Result = NULL;
}
Return pinfo;

}

 

Public long updateonedata (long ID, personinfo)

{

Contentvalues newvalues = new contentvalues ();

Newvalues. Put (personinfo_code, personinfo. getcode ());

Newvalues
. Put (personinfo_displaypicture, personinfo. getdisplaypicture ());

Newvalues. Put (personinfo_nickname, personinfo. getnickname ());

Newvalues. Put (personinfo_birthday, personinfo. getbirthday ());

Newvalues. Put (personinfo_gender, personinfo. getgender ());

Newvalues. Put (personinfo_signature, personinfo. getsignature ());

Newvalues. Put (personinfo_signaturedatetime, personinfo
. Getsignaturedatatime ());

Newvalues. Put (personinfo_password, personinfo. GetPassword ());

Newvalues. Put (personinfo_displaypicturebinary ,"");

Newvalues. Put (personinfo_registertime, personinfo. getregistertime ());

Newvalues. Put (personinfo_updatetime, personinfo. getupdatetime ());

Return MDB. Update (table_name, newvalues, ID + "=" + id, null );

}

 

Public long insert (personinfo)

{

Contentvalues newvalues = new contentvalues ();

Newvalues. Put (personinfo_code, personinfo. getcode ());

Newvalues
. Put (personinfo_displaypicture, personinfo. getdisplaypicture ());

Newvalues. Put (personinfo_nickname, personinfo. getnickname ());

Newvalues. Put (personinfo_birthday, personinfo. getbirthday ());

Newvalues. Put (personinfo_gender, personinfo. getgender ());

Newvalues. Put (personinfo_signature, personinfo. getsignature ());

Newvalues. Put (personinfo_signaturedatetime, personinfo
. Getsignaturedatatime ());

Newvalues. Put (personinfo_password, personinfo. GetPassword ());

Newvalues. Put (personinfo_displaypicturebinary ,"");

Newvalues. Put (personinfo_registertime, personinfo. getregistertime ());

Newvalues. Put (personinfo_updatetime, personinfo. getupdatetime ());

Return MDB. insert (table_name, null, newvalues );

}

Public long deleteonedata (long ID)

{

Return MDB. Delete (table_name, ID + "=" + id, null );

}

 

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.