android - beginTransaction(), endTransaction(), and setTransactionSuccessful(). What exactly do they do? -


i have provide synchronization when inserting, querying, updating , deleting items database. far understand begintransaction() , begintransactionnonexclusive() methods need.

besides sqlite documentation describes exclusive, immediate, , deferred quite well.

transactions can deferred, immediate, or exclusive. deferred means no locks acquired on database until database first accessed.

if transaction immediate, reserved locks acquired on databases begin command executed, without waiting database used. after begin immediate, no other database connection able write database or begin immediate or begin exclusive. other processes can continue read database, however.

an exclusive transaction causes exclusive locks acquired on databases. after begin exclusive, no other database connection except read_uncommitted connections able read database , no other connection without exception able write database until transaction complete.

it seems provide protection unwanted insertions , queries while thread working database. i'm not sure guarantees synchronization.

there insert method of contentprovider.

@override public uri insert(uri baseuri, contentvalues values) {     try {         mdatabase = mhelper.getwritabledatabase();         mdatabase.begintransaction(); // exclusive         switch (surimatcher.match(baseuri)) {         case uricodes.countries:         case uricodes.continents:         case uricodes.orgs:             string table = baseuri.getlastpathsegment();             long rowid = mdatabase.insert(table, null, values);             uri uri = uri.withappendedpath(baseuri, long.tostring(rowid));             mdatabase.settransactionsuccessful();             return uri;          default:             mdatabase.endtransaction();             throw new illegalargumentexception(unsupported_uri + space + baseuri);         }     } {         mdatabase.endtransaction();     } } 

i haven't had problems without begintransaction(), endtransaction(), , settransactionsuccessful() before. need add them?

off course android! if working reliable data manipulation important use following supported methods.

begintransaction(); settransactionsuccessful(); endtransaction();  

for further see this…in android highly important use transactions when working databases.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -