user8087816
user8087816

Reputation:

Variables in Queries - Server-side Scripts

I want to be able to build an SQL query using variables.

How can I create the equivalent of this PHP statement in a Google App Maker server-side script?

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

-('$orderNo' as a variable)

This may be achieved through a calculated model, if so, I need to understand how to use variables within the calculated SQL query.

Like this: https://developers.google.com/appmaker/models/cloudsql#sql_calculated_model

The variable here ultimately needs to be an ID property on the page.

Entirely different approaches are welcome

Thanks a lot.

Upvotes: 1

Views: 617

Answers (1)

Pavel Shkleinik
Pavel Shkleinik

Reputation: 6347

You can use datasource Query Builder (https://developers.google.com/appmaker/models/datasources#query_builder): enter image description here

or hack into 'where' query property (server script):

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()

You can find examples in templates (https://developers.google.com/appmaker/templates/). Q&A Forum (query builder), Partner Management (how to use 'where' query property).

Upvotes: 1

Related Questions