SQLiteDatabase数据库操作详解
source link: https://blog.csdn.net/dmk877/article/details/44876805
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
SQLiteDatabase数据库操作详解
insert的一种构造方法
public long insert (String table, String nullColumnHack, ContentValues values)
table
要插入数据的表的名称
values
ContentValues对象,类似一个map通过键值对的形式存储值。
nullColumnHack
当values参数为空或者里面没有内容的时候,insert是会失败的(底层数据库不允许插入一个空行),为了防止这种情况,要在这里指定一个列名,到时候如果发现将要插入的行为空行时,就会将你指定的这个列名的值设为null,然后再向数据库中插入。通过观察源码的insertWithOnConflict方法可以看到当ContentValues类型的数据initialValues为null或size<=0时,就会在sql语句中添加nullColumnHack的设置。
若不添加nullColumnHack则sql语句最终的结果将会类似insert into tableName()values(NULL);这是不允许的。
若添加上nullColumnHack则sql语句将会变成insert into tableName (nullColumnHack)values(null);这是可以的。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK