简体   繁体   English

为什么execSQL接受Object []和原始查询字符串[]

[英]Why execSQL accepts Object[] and raw Query String[]

I would like to have an option to call 'rawQuery' with a list of Integers passed into it, but it looks I can't: all 'rawQuery' methods require array of Strings... 我想有一个选项来调用'rawQuery',并传递一个整数列表,但看起来我做不到:所有'rawQuery'方法都需要字符串数组...

Why? 为什么? I can call 'toString' for each passed int object, but I don't see any logic here. 我可以为每个传递的int对象调用'toString',但是在这里看不到任何逻辑。 Why Google don't provide rawQuery that accept list of Objects? 为什么Google不提供接受对象列表的rawQuery?

Are there any limitation or constrains for that? 是否有任何限制或约束?

Probably I miss something? 可能我想念什么吗?

Thank you. 谢谢。

Probably because rawQuery isn't the prefered method of querying. 可能是因为rawQuery不是首选的查询方法。 And since sqlite columns basically don't have types, they probably don't want to assume calling toString on whatever it is you're passing. 而且由于sqlite列基本上没有类型,所以它们可能不想假设对要传递的内容调用toString。

SQLite supports the concept of "type affinity" on columns. SQLite支持列上的“类型相似性”概念。 The type affinity of a column is the recommended type for data stored in that column. 列的类型相似性是存储在该列中的数据的推荐类型。 The important idea here is that the type is recommended, not required. 这里的重要思想是建议类型,而不是必需类型。 Any column can still store any type of data. 任何列仍可以存储任何类型的数据。 It is just that some columns, given the choice, will prefer to use one storage class over another. 只是有些列(如果有选择)将更喜欢使用一种存储类而不是另一种。 The preferred storage class for a column is called its "affinity". 列的首选存储类称为其“关联性”。

Is there a reason you want to use rawQuery instead of execSQL ? 您是否有理由要使用rawQuery而不是execSQL

No complex objects are accepted in the list of parameters, as stated on the documentation for the parameter bindArgs : 如参数bindArgs的文档中所述,参数列表中不接受任何复杂对象:

Parameters 参量

sql the SQL statement to be executed. sql要执行的SQL语句。 Multiple statements separated by semicolons are not supported. 不支持用分号分隔的多个语句。

bindArgs only byte[], String, Long and Double are supported in bindArgs. bindArgs只支持byte [],String,Long和Double的bindArgs。

http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#execSQL(java.lang.String, java.lang.Object[]) . http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#execSQL(java.lang.String,java.lang.Object [])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 StringBuilder构造函数接受StringBuilder对象 - 为什么? - StringBuilder constructor accepts a StringBuilder object - why? 使用接受字符串参数的构造函数实例化一个类对象? - Instantiate a class object with constructor that accepts a string parameter? 从SQLiteDatabase.execSQL获取生成的查询 - Get Generated Query From SQLiteDatabase.execSQL 使用自定义查询和rawQuery或execSQL更新不起作用 - update using custom query and rawQuery or execSQL not working SQLiteDatabase的execSQL(String sql)函数的说明 - Explanation of execSQL (String sql) function of SQLiteDatabase 泛型迭代器<e>当集合的原始类型 object 传递给接受通用参数的方法时,行为不同</e> - Generic Iterator<E> behaves differently when a Raw Type of Collection object is passed to method which accepts Generic parameter Java:接受字符串对象作为参数并返回字数的写入方法 - Java: write method that accepts string object as argument and returns word count 无法将对象添加到jComboBox; addItem(…)方法仅接受String - Unable to add an object to a jComboBox; addItem(…) method only accepts String 将原始 sql 查询映射到 DTO 对象 Spring - Mapping raw sql query into DTO object Spring 使用WebTarget时指定原始查询字符串 - Specify raw query string when using WebTarget
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM