Here is a list of the put methods supported by ContentValues:Įach put method takes a String key and a typed value as parameters. It contains multiple overloaded put methods that enforce type safety. String nullColumnHack: Specifies a column that will be set to null if the ContentValues argument contains no data.ĬontentValues values: Contains the data that will be inserted into the table.ĬontentValues is a maplike class that matches a value to a String key. This name needs to be the same as the name given to the table when it was created. String table: Gives the name of the table on which to perform the insert operation. The common three parameters for the insert methods are SQLiteDatabase.insertWithOnConflict() contains a fourth parameter which will be discussed soon. Notice that the parameter lists for all the variations of the insert methods contain (as the first three parameters) a String tableName, a String nullColumnHack, and ContentValues values. Long insertWithOnConflict(String table, String nullColumnHack, ContentValues values, int conflictAlgorithm) Long insertOrThrow(String table, String nullColumnHack, ContentValues values) Long insert(String table, String nullColumnHack, ContentValues values) In most cases, one of the following three methods is used to perform an insert operation: The SQLiteDatabase class contains multiple convenience methods that can be used to perform insert operations. The steps to create a database were covered in the previous chapter, so this discussion starts with inserting data into a database. This makes sense since a database is useful only after it contains data. In a typical database use case, inserting data into the database is the step that follows creating the database. This class contains methods for building SQL statements as well as convenience methods to make issuing SQL statements to the database easy. Working with SQL in Android involves calling methods on an SQLiteDatabase object. The Android SDK provides useful classes to assist in creating SQL statements, while also supporting the use of Java string processing to generate SQL statements. SQL can also be used to read, update, and delete information from a database in Android. In Chapter 2, “An Introduction to SQL,” we saw how SQL is used to both create and upgrade a database. Working with SQL is a vital part of working with databases in Android. The LoaderManager contains the API for initializing and resetting a loader that may be used by Android components. LoaderManager: Manages all loaders for an activity or fragment. In most cases, the keys map to the column names of the table, and the values are the data to enter into the table.ĬursorLoader: Part of the loader framework that handles cursor objects. An app can read the data from a cursor and display it to a user or perform business logic based on the data contained in the cursor.ĬontentValues: A key/value store that inserts data into a row of a table. It contains methods to perform standard database CRUD operations as well as control the SQLite database file used by an app.Ĭursor: Holds the result set from a query on a database. SQLiteDatabase: Represents a database in Android. Following are the classes introduced in this chapter and a summary of how they are used to work with databases in Android: Along with the classes to support create, read, update, and delete (CRUD) operations, the SDK contains classes to help generate the queries that read the database. The Android SDK contains many classes to support database operations. This chapter explains how that is done in Android by discussing which Android SDK classes can be used to manipulate a database as well as query a database. Of course, this is only the first step as a database is not very useful until it contains data and allows software to run queries against that data. The previous chapter introduced the SQLiteOpenHelper and SQLiteDatabase classes and discussed how to create databases.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |