java nullColumnHack 是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32774507/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 20:45:14  来源:igfitidea点击:

What does nullColumnHack means?

javaandroidsqlite

提问by Ethyl Casin

According to the SQLiteDatabase API documentation:

根据 SQLiteDatabase API 文档:

  • insert(String table, String nullColumnHack, ContentValues values)

    Convenience method for inserting a row into the database.

  • 插入(字符串表,字符串 nullColumnHack,ContentValues 值)

    向数据库中插入行的便捷方法。

What does nullColumnHack means?

nullColumnHack 是什么意思?

Can you give me an example?

你能举个例子吗?

回答by Ted Yu

Sometimes you want to insert an empty row, in that case ContentValueshave no content value, and you should use nullColumnHack.

有时你想插入一个空行,在这种情况下ContentValues没有内容值,你应该使用 nullColumnHack。

For example, you want to insert an empty row into a table student(id, name), which idis auto generated and nameis null. You could invoke like this:

例如,您想在 table 中插入一个空行student(id, name),该行id是自动生成的并且name为 null。你可以这样调用:

ContentValues cv = new ContentValues();
db.insert("student", "name", cv);

回答by Buddy

Did you try looking at the docs?

您是否尝试查看文档

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.

nullColumnHack 可选;可能为空。SQL 不允许在未命名至少一个列名的情况下插入完全空的行。如果您提供的值为空,则没有列名是已知的,并且无法插入空行。如果未设置为 null,则 nullColumnHack 参数提供可空列名称的名称,以便在您的值为空的情况下显式插入 NULL。