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 );
}