behnam_tr Active Member Licensed User Longtime User Dec 20, 2022 #1 hi how can i convert this string to smart string i have a problem With ' character B4X: Dim RS2 As ResultSet=Main.Sql1.ExecQuery(" Select kala.id,kala.catid,kala.name WHERE kala.name LIKE '%"&stext&"%' Or kala.id='"&stext&"' " ) B4X: Dim RS2 As ResultSet=Main.Sql1.ExecQuery($" Select kala.id,kala.catid,kala.name WHERE kala.name LIKE ${'%stext%'} Or kala.id=${text} "$)
hi how can i convert this string to smart string i have a problem With ' character B4X: Dim RS2 As ResultSet=Main.Sql1.ExecQuery(" Select kala.id,kala.catid,kala.name WHERE kala.name LIKE '%"&stext&"%' Or kala.id='"&stext&"' " ) B4X: Dim RS2 As ResultSet=Main.Sql1.ExecQuery($" Select kala.id,kala.catid,kala.name WHERE kala.name LIKE ${'%stext%'} Or kala.id=${text} "$)
Solution M M Mahares Dec 22, 2022 Using parameterized query and string literals and also an alias for the table name: Code: Dim RS2 As ResultSet=SQL.ExecQuery2($"SELECT K.id, K.catid, K.name FROM kala K WHERE K.name LIKE ? OR K.id =?"$ , Array As Object($"%${stext}%"$ , text))
Using parameterized query and string literals and also an alias for the table name: Code: Dim RS2 As ResultSet=SQL.ExecQuery2($"SELECT K.id, K.catid, K.name FROM kala K WHERE K.name LIKE ? OR K.id =?"$ , Array As Object($"%${stext}%"$ , text))
E emexes Expert Licensed User Longtime User Dec 20, 2022 #2 The single quotes and % wildcards should be outside the the substitution delimiters eg: B4X: Dim RS2 As ResultSet=Main.Sql1.ExecQuery($" SELECT kala.id,kala.catid,kala.name WHERE kala.name LIKE '%${stext}%' OR kala.id=${text} "$) ps is the second search term ${text} supposed to be enclosed in single quotes too? Or are kala.id and text numeric? Last edited: Dec 20, 2022 Upvote 1
The single quotes and % wildcards should be outside the the substitution delimiters eg: B4X: Dim RS2 As ResultSet=Main.Sql1.ExecQuery($" SELECT kala.id,kala.catid,kala.name WHERE kala.name LIKE '%${stext}%' OR kala.id=${text} "$) ps is the second search term ${text} supposed to be enclosed in single quotes too? Or are kala.id and text numeric?
E emexes Expert Licensed User Longtime User Dec 20, 2022 #3 I know it's an extra line, but it sure makes debugging easier if you gather the SQL query into a string first so that you can see what SQLite is seeing eg: B4X: Dim Query As String = $"SELECT kala.id, kala.catid, kala.name WHERE kala.name LIKE '%${stext}%' OR kala.id = ${text}"$ Log(Query) Dim RS2 As ResultSet = Main.Sql1.ExecQuery(Query) Upvote 0
I know it's an extra line, but it sure makes debugging easier if you gather the SQL query into a string first so that you can see what SQLite is seeing eg: B4X: Dim Query As String = $"SELECT kala.id, kala.catid, kala.name WHERE kala.name LIKE '%${stext}%' OR kala.id = ${text}"$ Log(Query) Dim RS2 As ResultSet = Main.Sql1.ExecQuery(Query)
EnriqueGonzalez Expert Licensed User Longtime User Dec 21, 2022 #4 Just fyi this is the incorrect approach. You should use parametized queries (with ? And array of strings) doing it differently just make it more complex and insecure Upvote 1
Just fyi this is the incorrect approach. You should use parametized queries (with ? And array of strings) doing it differently just make it more complex and insecure
Erel B4X founder Staff member Licensed User Longtime User Dec 21, 2022 #5 EnriqueGonzalez said: Just fyi this is the incorrect approach. You should use parametized queries (with ? And array of strings) doing it differently just make it more complex and insecure Click to expand... That's 100% correct. Upvote 0
EnriqueGonzalez said: Just fyi this is the incorrect approach. You should use parametized queries (with ? And array of strings) doing it differently just make it more complex and insecure Click to expand... That's 100% correct.
M Mahares Expert Licensed User Longtime User Dec 22, 2022 #6 Using parameterized query and string literals and also an alias for the table name: Code: Dim RS2 As ResultSet=SQL.ExecQuery2($"SELECT K.id, K.catid, K.name FROM kala K WHERE K.name LIKE ? OR K.id =?"$ , Array As Object($"%${stext}%"$ , text)) Upvote 1 Solution
Using parameterized query and string literals and also an alias for the table name: Code: Dim RS2 As ResultSet=SQL.ExecQuery2($"SELECT K.id, K.catid, K.name FROM kala K WHERE K.name LIKE ? OR K.id =?"$ , Array As Object($"%${stext}%"$ , text))