Android Studio - Complete Android Apps Tutorial – SQLite Database - Day 17 - 8.12

preview_player
Показать описание
SQLite Database  Open source, lightweight relational database.  Stored in /data/data/package_name/databases  Private by default, only accessible by the application that created them.  To share a database across applications, use Content Providers.
3
 SQLite Database  SQLiteOpenHelper wraps up the creating, opening and upgrading of databases.  Extends SQLiteOpenHelper and override the  Constructor  onCreate  onUpgrade
4
 SQLite Database  With an instance of own subclass of SQLiteOpenHelper, call getReadableDatabase or getWritableDatabase to return a read-only or a writable SQLite database  Two approaches of using SQLite database to avoid IllegalStateException  Open it once and never close it  Right before we need to read or write to the database, open it and close it immediately after the operation is done – not possible if using SimpleCursorAdapter
5
 SQLiteOpenHelper constructor  1st parameter, the context, is usually the only parameter for the constructor for our subclass  2nd parameter is the name of the sqlite file  3rd parameter is an instance of CursorFactory, used for creating cursor objects, which usually is set to null  4th parameter is the version of the sqlite database, started from 1
6
7
 SQLiteOpenHelper onUpgrade  Will be called only when the sqlite file version number in the constructor is higher than the version number associated to the existing sqlite file created previously with an older version of the app  Simplest implementation of a schema change is to drop the existing table and create a new one
8
 Writing data to SQLite Database  ContentValues are used to insert new rows into database tables or update existing rows.  Each ContentValues object represents a single row.  The constructor of ContentValues takes an integer to set it's initial size
9
10
11
 Getting data from SQLite Database  Queries are returned as Cursor objects, which are pointers to a subset of the data.  Two ways to execute a query
12
13
Рекомендации по теме
welcome to shbcf.ru