Android Question string literals and single quotes

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Have a string variable (strObject, will be a table or a view) that needs to be enclosed in single quotes:

B4X:
strSQL = $"select ObjectType, ObjectName, ColumnName, Affinity, ColumnID
 from SysColumns where ObjectName = ${Chr(39) & strObject & Chr(39)}
 order by ColumnID asc"$

(In this particular Sub using a parameter SQL will be incovenient.)

Can I do this by putting in the ' character directly, rather than using Chr(39)?

RBS
 

Mahares

Expert
Licensed User
Longtime User
B4X:
$"select ObjectType, ObjectName, ColumnName, Affinity, ColumnID
 from SysColumns where ObjectName ='${strObject}'"$
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Correct solution is to use parameterized queries.
That is precisely what I was going to suggest, but OP explicitly does not want a parameterized query. I don't know sometimes whether to impose what I think the correct way or simply respond with the OP wishes in mind.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Did you notice the order clause? Your solution uses a different SQL.
The emphasis was on the single quote. You have worked long enough with SQLite to know where to add the ORDER clause.
B4X:
$"select ObjectType, ObjectName, ColumnName, Affinity, ColumnID
 from SysColumns where ObjectName ='${strObject}'  order by ColumnID"$
or even this although the first is preferred:
B4X:
$"select ObjectType, ObjectName, ColumnName, Affinity, ColumnID
 from SysColumns where ObjectName ='${strObject}' "$ & " order by ColumnID"
Unfortunately, your nitpicking always gets in your way.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
The emphasis was on the single quote. You have worked long enough with SQLite to know where to add the ORDER clause.
B4X:
$"select ObjectType, ObjectName, ColumnName, Affinity, ColumnID
 from SysColumns where ObjectName ='${strObject}'  order by ColumnID"$
or even this although the first is preferred:
B4X:
$"select ObjectType, ObjectName, ColumnName, Affinity, ColumnID
 from SysColumns where ObjectName ='${strObject}' "$ & " order by ColumnID"
Unfortunately, your nitpicking always gets in your way.
>> Unfortunately, your nitpicking always gets in your way.

??? I am not familiar with these smart string literals and it was not directly obvious to me.
It is somewhat confusing how the $, the { and the "" exactly work.
No idea how you came to the conclusion I always nitpick.

RBS
 
Upvote 0
Top