SQLiteDatabase.insert函数参数解释说明

public long insert (String table, String nullColumnHack, ContentValues values)
Added in  API level 1

Convenience method for inserting a row into the database.

Parameters
table the table to insert the row into
nullColumnHack optional; may be null. SQL doesn't allow inserting a completely empty row without naming at least one column name. If your provided values is empty, no column names are known and an empty row can't be inserted. If not set to null, the nullColumnHack parameter provides the name of nullable column name to explicitly insert a NULL into in the case where your values is empty.
values this map contains the initial column values for the row. The keys should be the column names and the values the column values
Returns

  • the row ID of the newly inserted row, or -1 if an error occurred
主要是解释中间那个参数nullColumnHack,这个参数是一个字段名。如果你想插入一条所有字段值都为NULL的记录,必须要指定一个字段名来作为该参数,来告诉数据库,将要插入的这条记录都为NULL值。如果不指定一个字段名为该参数,而是使用NUll的话,这样插入一条完全为NUll的记录,数据库将会报错。

通俗一点来讲,一般来说,数据不允许插入所有字段值都为NULL的记录,但是如果你指定一个字段为nullColumnHack的值,则数据库允许参加所有字段值都为NULL的记录。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值