简体   繁体   中英

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...

Why? I can call 'toString' for each passed int object, but I don't see any logic here. Why Google don't provide rawQuery that accept list of Objects?

Are there any limitation or constrains for that?

Probably I miss something?

Thank you.

Probably because rawQuery isn't the prefered method of querying. 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 supports the concept of "type affinity" on columns. 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 ?

No complex objects are accepted in the list of parameters, as stated on the documentation for the parameter bindArgs :

Parameters

sql the SQL statement to be executed. Multiple statements separated by semicolons are not supported.

bindArgs only byte[], String, Long and Double are supported in bindArgs.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM