一些SQLite的方法为什么想到参数作为一个Object [],而另一些则需要一个String []? [英] Why do some SQLite methods expect arguments as an Object[] while others need a String[]?
问题描述
我很好奇的Android SQLite的API的设计一>。例如,我们有
I'm curious about the design of the Android SQLite API. For example, we have
public void execSQL(String sql, Object[] bindArgs)
对于不返回数据SQL后,我们也有
for SQLs that don't return data, and we also have
public Cursor rawQuery(String sql, String[] selectionArgs)
该做的返回数据的SQL。
for SQLs that do return data.
为什么参数预期的那样于前而在后一种情况下的String数组对象数组?据我所知,只接受字符串可能是有意义的,由于SQLite的的型亲和力。但是,如果是这样的话,为什么不坚持用字符串数组的参数呢?有一些是有道理的 execSQL
而不是 rawQuery
Why are the arguments expected as an Object array in the former and as a String array in the latter case? I understand that accepting only Strings might make sense due to SQLite's type affinity. However, if that is the case, why not consistently use String arrays for arguments? Is there some non-String argument that makes sense for execSQL
but not for rawQuery
?
推荐答案
有一个。例如,如果你想比较BLOB值。看看这个<一个href=\"http://stackoverflow.com/questions/9543595/how-to-delete-blob-element-from-a-table-in-sqlite-android/27465556#27465556\">example.
There is one. For example if you want to compare BLOB values. Have a look at this example.
存储为BLOB UUID
UUID stored as BLOB
db.execSQL("DELETE FROM "+USER_TABLE+" WHERE "+USER_UUID+"=?",
new Object [] { uuid.toByteArray }
据文档,字节[] ,字符串,长和Double在bindArgs支持。但是,不可以建议使用此方法执行SELECT / INSERT / UPDATE / DELETE语句。
According to documentation, byte[], String, Long and Double are supported in bindArgs. However, it is not recommended to use this method for executing SELECT/INSERT/UPDATE/DELETE statements.
我只是不知道为什么。
这篇关于一些SQLite的方法为什么想到参数作为一个Object [],而另一些则需要一个String []?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!