wildcard

cnicolapc

Active Member
Licensed User
Longtime User
Hi,
I need to assign to a variable that has a wildcard value (any character and any number) how can I do?.
eg:
main.Cercacategorie = "%" & "*" & "%" (which is not correct)
Thanks in advance
Nicola
 

kickaha

Well-Known Member
Licensed User
Longtime User
It is not clear what you are trying to do. Could you post a fuller explanation, and the code so that we can help?
 
Upvote 0

cnicolapc

Active Member
Licensed User
Longtime User
hi
I created a variable to be used in a SQL statement like this.
trivial example:
Value = "dog"
main.Cercacategorie = "%" & value & "%"
Cursor1 SQL1.ExecQuery = ("SELECT cosa FROM articoli where categoria like '" & main.Cercacategorie & "' ORDER BY cosa")

But I need that with a command variable is reset and allow you to view any character and any number so I have to replace "%" & value & "%" with what ?
thank You
Nicola
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
B4X:
Cursor1 SQL1.ExecQuery = ("SELECT cosa FROM articoli where categoria like '" & main.Cercacategorie & "' ORDER BY cosa")

I often see that programmers concatenate their select statement string with variables like this.

Be aware that this is not very good technique for the SQL engine. Every time you create a statement like this it is a completely NEW statement for the SQL engine so the statement has to be parsed again, a new execution plan has to be found and so on. A better way is to use ExecQuery2 like this:

B4X:
SQL1.ExecQuery2 = ("SELECT cosa FROM articoli where categoria like ? ORDER BY cosa", array as string(main.Cercacategorie))

So every time you call this statement the SQL engine recognizes that this is a statement called before and can use the cached execution plan.

If you do many select statements like this then the performance will increase.
 
Upvote 0
Top