Delphi: how to pass a list as a parameter to a SQL query?

前端 未结 7 748
你的背包
你的背包 2020-12-17 16:44

I have a list of integers or of strings and need to pass it as a parameter for a Delphi DataSet. How to do it?

Here is an example. MyQuery is something like:

7条回答
  •  鱼传尺愫
    2020-12-17 16:54

    Create a temporary table and insert your values in it. Then use that table as part of a subquery.

    For example, create MyListTable in your database. Insert your values into MyListTable. Then do

    select * from myTable where keyvalue in (select keyvalue from MyListTable)
    

    This avoids SQL injection attacks. But it's not elegant, is not performance friendly because you have to insert records before running your query, and can lead to concurrency issues.

    Not my first choice to deal with your situation but it addresses your concern about sql injection.

提交回复
热议问题