SLIDE 22 Lesson 13
The method tries to insert a row in a table The row’s column‐values are
Android’s INSERT Operation
SQL Databases
public long insert(String table, String nullColumnHack, ContentValues values)
table the table on which data is to be inserted nullColumnHack Empty and Null are different things. For instance, values could be defined but empty. If the row to be inserted is empty (as in our
The method tries to insert a row in a table. The row s column‐values are supplied in the map called values. If successful, the method returns the rowID given to the new record, otherwise ‐1 is sent back.
Parameters
next example) this column will explicitly be assigned a NULL value (which is OK for the insertion to proceed). values Similar to a bundle (name, value) containing the column values for the row that is to be inserted.
13 ‐43
ContentValues rowValues= new ContentValues(); rowValues.put("name", "ABC");
Android’s INSERT Operation
1
SQL Databases
p ( , ); rowValues.put("phone", "555‐1010"); long rowPosition = db.insert("tblAMIGO", null, rowValues); rowValues.put("name", "DEF"); rowValues.put("phone", "555‐2020"); rowPosition = db.insert("tblAMIGO", null, rowValues); rowValues.clear(); iti db i t("tbl GO" ll l )
2 3 4
rowPosition = db.insert("tblAMIGO", null, rowValues); rowPosition = db.insert("tblAMIGO", "name", rowValues);
5 6
13 ‐44