R RichardN Well-Known Member Licensed User Longtime User Oct 12, 2014 #1 I have seen the following two uses of ExecQuery2() but I am unclear as to the difference in use of Object and String. Code: Copy '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: Oct 12, 2014
I have seen the following two uses of ExecQuery2() but I am unclear as to the difference in use of Object and String. Code: Copy '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 ?
mc73 Well-Known Member Licensed User Longtime User Oct 12, 2014 #2 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
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'.
LucaMs Expert Licensed User Longtime User Oct 12, 2014 #3 RichardN said: I have seen the following two uses of ExecQuery2() but I am unclear as to the difference in use of Object and String. Code: Copy 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 ? Click to expand... 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 said: I have seen the following two uses of ExecQuery2() but I am unclear as to the difference in use of Object and String. Code: Copy 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 ? Click to expand... 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
R RichardN Well-Known Member Licensed User Longtime User Oct 12, 2014 #4 @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
@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.
LucaMs Expert Licensed User Longtime User Oct 12, 2014 #5 In the meantime, I did a little test. Result: It seems that there is no difference Attachments lm SQLite insert methods.zip lm SQLite insert methods.zip 12.5 KB · Views: 364 Upvote 0
mc73 Well-Known Member Licensed User Longtime User Oct 12, 2014 #6 RichardN said: @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? Click to expand... 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
RichardN said: @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? Click to expand... 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.
LucaMs Expert Licensed User Longtime User Oct 12, 2014 #7 mc73 said: blob is an object, not a string, thus you cannot insert it, using an array of strings Click to expand... ...even using an array of objects, so there is no difference between the two methods. Upvote 0
mc73 said: blob is an object, not a string, thus you cannot insert it, using an array of strings Click to expand... ...even using an array of objects, so there is no difference between the two methods.
mc73 Well-Known Member Licensed User Longtime User Oct 12, 2014 #8 LucaMs said: ...even using an array of objects, so there is no difference between the two methods. Click to expand... 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
LucaMs said: ...even using an array of objects, so there is no difference between the two methods. Click to expand... 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.