Android Question Use Of SQL.ExecQuery2() With Array

RichardN

Well-Known Member
Licensed User
Longtime User
I have seen the following two uses of ExecQuery2() but I am unclear as to the difference in use of Object and String.

B4X:
'Corrected for SQL query

Cursor = SQL.ExecQuery2("SELECT * FROM MyTable WHERE fieldX = ? AND fieldY = ?", Array as String(var1,var2)

Cursor = SQL.ExecQuery2"SELECT * FROM MyTable WHERE fieldX = ? AND fieldY = ?", Array as Object(var1,var2)

The two methods appear variously used. Are they interchangeable ?
 
Last edited:

mc73

Well-Known Member
Licensed User
Longtime User
Insertions cannot be done using execQuery. You should use execNonQuery and 'array as object'. Selects are done using execQuery and you should use 'array as string'.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I have seen the following two uses of ExecQuery2() but I am unclear as to the difference in use of Object and String.

B4X:
Cursor = SQL.ExecQuery2("INSERT INTO MyTable VALUES(?,?)", Array as String(var1,var2)

Cursor = SQL.ExecQuery2("INSERT INTO MyTable VALUES(?,?)", Array as Object(var1,var2)

The two methods appear variously used. Are they interchangeable ?

Good question.

In fact SQLite saves everything in the form of text.
In the case of numbers, you have to see how they are saved using the two different methods, this depends on B4A conversions.

Personally, instead of waiting for an answer, I try :)
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
@mc73

Sorry I used a bad example with an INSERT should have used SELECT...but thank you for correcting me. The question hinges around Array as 'Object' or 'String'..... I note you suggest the use of 'As Object' with ExecNonQuery() and 'As String' with ExecQuery()........... Why?

@LucaMs... I also like experimenting. Unfortunately the B4A >> Sqlite interface can be very unforgiving if you cast variables incorrectly so this aspect needs to be understood fully and correctly.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
In the meantime, I did a little test.

Result:
upload_2014-10-12_11-46-23.png


It seems that there is no difference
 

Attachments

  • lm SQLite insert methods.zip
    12.5 KB · Views: 205
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
@mc73
The question hinges around Array as 'Object' or 'String'..... I note you suggest the use of 'As Object' with ExecNonQuery() and 'As String' with ExecQuery()........... Why?

As an example, blob is an object, not a string, thus you cannot insert it, using an array of strings. On the other side, a 'select' is usually made by filtering ids and other fields, most of the time, string or ints. Thus, you may use array of strings.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
...even using an array of objects, so there is no difference between the two methods.
Try inserting an array of bytes (an image buffer for example), using 'array as string', and you'll get a casting error from the compliler.
 
Upvote 0
Top