tailieunhanh - Lập trình Androi part 35

Tuy nhiên, tùy chọn khác là sử dụng SQLiteQueryBuilder, trong đó cung cấp các tùy chọn truy vấn xây dựng phong phú hơn nhiều, đặc biệt cho các truy vấn liên quan đến những điều khó chịu như nhiều tiểu đoàn của kết quả truy vấn. | CHAPTER 22 Managing and Accessing Local Databases What Goes Around Comes Around As with INSERT UPDATE and DELETE you have two main options for retrieving data from a SQLite database using SELECT Use rawQuery to invoke a SELECT statement directly. Use query to build up a query from its component parts. Confounding matters further is the SQLiteQueryBuilder class and the issue of cursors and cursor factories. Let s take this one piece at a time. Raw Queries The simplest solution at least in terms of the API is rawQuery . Just call it with your SQL SELECT statement. The SELECT statement can include positional parameters the array of these forms your second parameter to rawQuery . So we wind up with this constantsCursor SELECT _ID title value FROM constants ORDER BY title null The return value is a Cursor which contains methods for iterating over results discussed in the Using Cursors section a little later in the chapter . If your queries are pretty much baked into your application this is a very straightforward way to use them. However it gets complicated if parts of the query are dynamic beyond what positional parameters can really handle. For example if the set of columns you need to retrieve is not known at compile time puttering around concatenating column names into a comma-delimited list can be annoying which is where query comes in. Regular Queries The query method takes the discrete pieces of a SELECT statement and builds the query from them. The pieces in the order they appear as parameters to query are as follows The name of the table to query against The list of columns to retrieve The WHERE clause optionally including positional parameters The list of values to substitute in for those positional parameters The GROUP BY clause if any The ORDER BY clause if any The HAVING clause if any CHAPTER 22 Managing and Accessing Local Databases These can be null when they are not needed except the table name of course String columns ID inventory String .

TÀI LIỆU MỚI ĐĂNG
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.