简体   繁体   English

如何在C ++ Builder 10.2中将查询转换为参数查询

[英]how to convert a query into a parametric one in C++ Builder 10.2

I have "normal" string query 我有“普通”字符串查询

String sqlquery = Format("select * from events where location = %d",ARRAYOFCONST(parameter_value));

how to convert this query into a parametric one in C++ Builder 10.2 (i use postgres database) 如何在C ++ Builder 10.2中将此查询转换为参数查询(我使用postgres数据库)

Per the TPSQLQuery.SQL property documentation: 根据TPSQLQuery.SQL属性文档:

The SQL statement in the SQL property may contain replaceable parameters, following standard SQL-92 syntax conventions. 遵循标准SQL-92语法约定, SQL属性中的SQL语句可以包含可替换参数。 Parameters are created and stored in the Params property. 参数已创建并存储在Params属性中。

For example: 例如:

PSQLQuery1->ParamCheck = true; // true by default
PSQLQuery1->SQL->Text = "select * from events where location = :Location";
PSQLQuery1->Params->Items[0]->AsInteger =  parameter_value;
// alternatively:
// PSQLQuery1->ParamByName("Location")->AsInteger = parameter_value;
PSQLQuery1->Open();
...

Have a look at the TPSQLQuery.Params documentation for more details. 请查看TPSQLQuery.Params文档以获取更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM