RowId in SQLITE3 and Android

I perform an insert operation on the database, and I want to know what the rowid to insert is.

This completes the task:

Uri uri = ContentResolver.insert(url,values); //Make insert
int rowid = Integer.parseInt(uri.getFragment()); //Get rowid

The Android document states that inserting returns “URL of the newly created row”. And the Uri method getFragment() should return everything after /#. So, is my understanding correct, getFragment() will therefore return my rowid?

To parse the URI and get the id after insertion, you should use ContentUris.parseId(uri).

I perform an insert operation on the database, and I want to know what rowid should be inserted.

This completes the task:

Uri uri = ContentResolver.insert(url,values); //Make insert
int rowid = Integer.parseInt(uri.getFragment()); //Get rowid

The Android document states that inserting returns “URL of the newly created row”. And the Uri method getFragment() should return everything after /#. So, is my understanding correct, getFragment() will therefore return my rowid?

To parse the URI and get the id after insertion, you should use ContentUris.parseId(uri).

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 889 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.