From wiki.ginstr.com
Jump to: navigation, search

gn:act_query

gn:act_query has integrated gn:act_getWidgetData action. The first task it completes is to retrieve widget data in dbRequest defined in widget attributes. Next, it accesses data stored by retrieving widget data in persistent storage and makes a query with it.

Values for keys of query are defined in dbSchema as key=”key, key1, key2…”

Values for fields of query are defined in dbSchema as fields=”field, field1, field2…”

This query returns only values that match keys values from database. If no match is found, nothing is returned. Query action can also be used in "if" action to check if a record exists in database or not.

Query actions can also be negated.

i.e. if it returns some value it will give result as nothing is returned or if it returns no value it will give result as value is returned. This is achieved using ! before the action. This is useful in "if" action where query result is checked.

If query will be executed with a number without decimal places when querying with number datatype, it is important to add the attribute gn:trimDecimalPlaces="true" to GnEditText, which will trim decimal places at the end when widget data is gathered. This attribute must be added to the widget from which the data is saved in order that data gets saved without the decimal point.

Can be used on widgets
any widget
Event trigger for action
click on the widget that contains this action in attributes, or in the action set, conditional action.
Can be used as

Additional required attributes on bound widget

gn:data_request=”dbRequestName”
required to identify dbRequest (table) of which data is removed from
gn:data_requestAlias=”dbRequestName” (optional)
if alias request is used then query is performed on gn:data_request and result is stored into the same request, but the values for query keys are used from dbRequest mentioned in gn:data_requestAlias.
gn:data_requestAliasAll=”dbRequestName” (optional)
when used query is performed on gn:data_requestAliasAll dbRequest instead of gn:data_request and query result data is stored to gn:data_request.
Values for query keys are used from gn:data_requestAliasAll.
gn:data_requestAliasKeyMap = “saveColumnIdentifier|sourceColumnIdentifier, saveColumnIdentifier|sourceColumnIdentifier,…”
defines different key source column name from key save column name. If dbRequest that is being queried has different key column name from dbRequest which is receiving data KeyMap must be used. What happens in alias query is that the dbRequest that is being queried “key” field names are used and by them looked up dbRequest that will be saved columns that match those fields. Values from those matching columns are then used in the query. This attribute is used in situation where we have different name of key query column from save column.
i.e.
<DbRequest id="1" fields="X,Y,Z,W"/>
<DbRequest id="2" fields="A,B,C,D,E" key="A"/>
We add attribute to widget where “query action” is: gn:data_requestAliasKeyMap=”Y|A” – this means that dbRequest 1 column Y value will be used as key to preform query on dbRequest 2 with column name A.
This will only work with “text” columns and when attribute gn:data_requestAliasAll is present.
gn:data_requestAliasValueMap=”saveColumn|sourceColumn, …”
defines that query which is source will save values to columns in other dbRequest where names do not match, to define those relations mapping is used.
i.e.
<DbRequest id="1" fields="A,Ba,Bb,C,D"/>
<DbRequest id="2" fields="A,B,C"/>
We add to widget where “query action” is : gn:data_requestAliasValueMap”Ba|B” and in other query widget gn:data_requestAliasValueMap=”Bb|B”
This will only work with “text” columns and when attribute gn:data_requestAliasAll is present.
gn:data_writeExistingDbRequestFieldsOnly=”true”
defines that query from database will write to in memory dbRequest only fields that are defined in dbSchema of that dbRequest and drop all other fields.
This is useful when querying another dbRequest and we want to keep fields only relevant to dbRequest we save to in case there are some additional columns.
i.e.
<DbRequest id=”A” fields=”a,b,c,d”/>
<DbRequest id=”B” fields=”a,b,e,g”/>
After query with dbRequest B columns “a,b,e,g” are returned, but only “a” and “b” values are copied from dbRequest A to dbRequest B and overwritten but “c” and “d” are dropped because destination dbRequest did not contain those columns

Additional required attributes on other widgets

For widgets whose data will be extracted:

  • gn:data_request=”dbRequestName” – must be identical to the name of the request in bound widget
  • gn:data_field=”fieldName” – must be identical to field in queries.xml for this dbRequest

Action signature

gn:act_query=[]
[gn:act_query]|[]
[gn:act_query]|[@+id/widget1,…,@+id/widget2]
![gn:act_query]|[]

Value field content

If no value is provided, data is acquired from all widgets on screen and saved into the persistent storage and to the database. Once it is acquired dbRequest query is performed.

If widget id’s are provided, data is acquired only from those widgets and saved into the persistent storage. Once it is acquired dbRequest query is performed.