重點來了
getWritableDatabase()
Database upgrade may take a long time, you should not call this method from the application main thread, including from
ContentProvider.onCreate()
.getReadableDatabase()
Like
getWritableDatabase()
, this method may take a long time to return, so you should not call it from the application main thread, including from ContentProvider.onCreate()
.說實在的,在對資料庫的抓取或異動還滿難用的....
public Cursor query (boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)
Since: API Level 1
Query the given URL, returning a
Cursor
over the result set.Parameters
distinct | 要不要 DISTINCT, TRUE/FALSE |
---|---|
table | 表格名稱 |
columns | new String[]{"column01","column02","column03"}; |
selection | "column01 = ? AND "column02 = ?"; |
selectionArgs | new String[]{"A","B","C"}; selection 與 selectionArgs 是配對的 |
groupBy | A filter declaring how to group rows, formatted as an SQL GROUP BY clause (excluding the GROUP BY itself). Passing null will cause the rows to not be grouped. |
having | A filter declare which row groups to include in the cursor, if row grouping is being used, formatted as an SQL HAVING clause (excluding the HAVING itself). Passing null will cause all row groups to be included, and is required when row grouping is not being used. |
orderBy | How to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort order, which may be unordered. |
limit | Limits the number of rows returned by the query, formatted as LIMIT clause. Passing null denotes no LIMIT clause. |
一般QUERY
SQLiteDatabase db = SQLiteOpenHelper.getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME, new String[] { "COLUMN01","COLUMN02" },
"cCarBocePartsIdn LIKE ?", new String[] { key+"%" }, null, null, null);