查询中的变量 - 服务器端脚本

Variables in Queries - Server-side Scripts

我希望能够使用变量构建 SQL 查询。

如何在 Google App Maker 服务器端脚本中创建与此 PHP 语句等效的语句?

$query = "SELECT * FROM table WHERE orderId = $orderNo";

-('$orderNo' 作为变量)

这可以通过计算模型来实现,如果是这样,我需要了解如何在计算的 SQL 查询中使用变量。

像这样:https://developers.google.com/appmaker/models/cloudsql#sql_calculated_model

这里的变量最终需要是页面上的一个ID属性。

欢迎采用完全不同的方法

非常感谢。

您可以使用数据源查询生成器 (https://developers.google.com/appmaker/models/datasources#query_builder):

或入侵 'where' 查询 属性(服务器脚本):

var newQuery = app.models.Company.newQuery();

newQuery.where = 'Name contains? :SearchText or Address contains? :SearchText or Website contains? :SearchText';
newQuery.parameters.SearchText = 'search term';
companies = newQuery.run()

您可以在模板 (https://developers.google.com/appmaker/templates/) 中找到示例。问答论坛(查询生成器)、合作伙伴管理(如何使用'where'查询属性)。