android - How to get the cause of an insert() error using ContentProvider? -


i have code inserts row db, using custom contentprovider:

uri contenturi = uri.withappendedpath(dataprovider.content_uri, usertable.table_name); uri resulturi = getcontext().getcontentresolver().insert(contenturi, contentvalues); boolean success = (long.parselong(resulturi.getlastpathsegment()) != -1); 

the insert() method defined in contentprovider follows:

public class dataprovider extends contentprovider {  // ...      @override     public uri insert(uri uri, contentvalues initialvalues) {         string table = gettablename(uri);         sqlitedatabase database = dbhelper.getwritabledatabase();         long value = database.insert(table, null, initialvalues);         return uri.withappendedpath(content_uri, string.valueof(value));     }  } 

i've noticed that, sometimes, insertion fails returning row id equals -1 (as can see in third line of first code, success should become false). problem can't understand reason because logcat doesn't print exception related sqllite. why contentprovider not inform me cause of errors?

to exception, use insertorthrow instead.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -