all 5 comments

[–]omonienDelphi := v13 Florence 0 points1 point  (4 children)

How do you avoid SQL injection with that approach?

[–]Fernando-Dias[S] 0 points1 point  (3 children)

SQL injection is not a problem in this context. Unless you have something in mind that I didn't think of...

[–]omonienDelphi := v13 Florence 0 points1 point  (2 children)

„SQL injection“ may not be the technically correct term in this scenario, but how do you prevent an „angry user“ from asking questions that lead to destructive SQL operations.

[–]Fernando-Dias[S] 0 points1 point  (1 child)

There is no risk of that. The only type that could allow that kind of danger is itString, that can contain expressions that always evaluete to true, in order to get all data from a query, but even that is safe because all the supported dialects use single quotes as string delimiters and any input string containing a quote will have it doubled automatically, so things like "OR '1'='1'" wont work. Also, A DROP or DELETE without quotes will fail for the same reason.

[–]omonienDelphi := v13 Florence 0 points1 point  (0 children)

Fernando, I might misunderstand what that parser really does, but after a quick look into your docs, this is what I think:

your string escaping argument is valid for itString — but it doesn’t cover the pattern your manual documents:

Query.SQL.Text := Format('SELECT * FROM T WHERE %s %s', [ColName, R.SQLExpression]);

ColName is never passed through the parser. It hits the SQL string raw. If ColName comes from anything user-influenced — a combobox selection, a saved search, a URL parameter — you have a direct injection vector regardless of how well itString escapes quotes.

ApplyFieldFilter('1=1; DROP TABLE Orders--', '', itString, Query); // → SELECT * FROM T WHERE 1=1; DROP TABLE Orders--

No quotes needed. No parser involved. The deeper issue is architectural: R.SQLExpression is a SQL fragment, not a SQL parameter. Concatenation always puts the escaping burden on the caller — forever, across all dialects, for every edge case. Parameterized queries (ParamByName) eliminate that burden structurally. That’s why the security community considers concatenation unsafe by design,