0

Currently, the update function in SQLiteDatabase uses String[] for the Where args.

update(String table, ContentValues values, String whereClause, String[] whereArgs)

I find this very strange

A) Normally values are passed using the ContentValues object: I can pass the actual object and SQLiteDatabase will convert it properly using its native binding functions.

For Example I can put in the Content Value a Long and SQLiteDatabase will convert it properly during the insertion.

put(String key, Long value)

B) However, for the Where Condition, I need to actually convert the values in to String by myself. Of course in the majority of the cases this is not problem as a .toString() will do the job. However in some cases the conversion is not so straight forward, for example:

  • to covert a Float number, shall I use "." or "," as decimal point (this varies countries to countries)?
  • how do I convert to String the null value?

QUESTIONS:

Question 1) Do you have any suggestions on the best practice to use the Where Statement?

Question 2) Is there a way to pass the whereArgs as ContentValues in order to use native binding for the conversion?

Question 3) If I will use String[] as whereArgs, I will come to a not aligned situation: the insertion itself uses the native binding functions, but the where statement needs a conversion by myself. I feel this will my generate some conflicts (eg. I insert the float "5.2" but then later I update the line searching by "5,2").

Questions 3.1) Has someone even had similar problems and what was the solution?

Questions 3.2) In order to align the 2 kind of conversions, I was thinking to take care always to the conversion to String: so to pass to ConcentValues only String (converted by me) + of course to use the same conversion for the String[] WhereArgs. Would this be a solution? What are the disadvantages you can foreseen?

Thanks in advance to all of you for your support Enrico

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Enrico
  • 41
  • 1
  • 4
  • for simplicity you can use `rawQuery`. It accepts complete sql query as a string – Vivek Mishra Nov 22 '16 at 08:42
  • Thanks a lot Vivek. I know rawQuery as I used it a lot in a previous project, but unfortunately this does not solve my questions on what would be the best option to use. Do you suggest that I always take the ownership to convert everything into String without using the native binding of SQLite? Did you use this approach in your experience? Do you see any disadvantages? Thanks a lot! Much appreciated! – Enrico Nov 22 '16 at 10:06

0 Answers0