Mobile/Fennec/Android/CommonTips: Difference between revisions

Line 109: Line 109:


=== Add a new table to browser.db ===
=== Add a new table to browser.db ===
To follow along with code, see [https://bugzilla.mozilla.org/show_bug.cgi?id=1250707 Bug 1250707].
*Capture a current version of the database (before your changes!) with some browsing data from your device using the Copy Profile add-on. Put this in <tt>mobile/android/tests/browser/robocop/assets/browser_db_upgrade/v<#>.db</tt>. It is used to test your upgrade changes in <tt>testBrowserDatabaseHelperUpgrades</tt>
*Add your table name & schema as a new <tt>static</tt> class in <tt>BrowserContract</tt>
*Increment the <tt>DATABASE_VERSION</tt> in <tt>BrowserDatabaseHelper</tt> and update the related bug # comment
*Implement a create method to create your table
**Add a call to it in <tt>BrowserDatabaseHelper.onCreate</tt>
**Add a method to upgrade the database from the old version to the new version (which likely calls your create table method) and add it to <tt>BrowserDatabaseHelper.onUpgrade</tt>
*Register your new table with <tt>BrowserProvider</tt> by adding your table to the <tt>URI_MATCHER</tt> in the <tt>BrowserProvider</tt> constructor (pattern match the other values). Note the <tt>TABLE_*</tt> constant, the constants assigned to <tt>int</tt>s, and the <tt>*_PROJECTION_MAP</tt> constant.
*Add to the <tt>BrowserProvider.query</tt> method (pattern match!) by setting the projection map and table in the <tt>SQLiteQueryBuilder</tt> object.
*Add to the <tt>BrowserProvider.insertInTransaction</tt> method (pattern match!) by calling out to your own method to insert into the DB
*Test insert!
==== Explanation of classes ====
*<tt>BrowserContract</tt>
*<tt>BrowserDatabaseHelper</tt>


=== External how-to's ===
=== External how-to's ===
*[[Mobile/Fennec/Android/Updating search engine icons|Updating the search engine icons]]
*[[Mobile/Fennec/Android/Updating search engine icons|Updating the search engine icons]]
*[[Mobile/Fennec/Android/Updating_SDK_on_builders|Updating the Android SDK on the builders]]
*[[Mobile/Fennec/Android/Updating_SDK_on_builders|Updating the Android SDK on the builders]]
Confirmed users
975

edits