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 asnothing is returned
or if it returnsno value
it will give result asvalue 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 fromdbRequest
mentioned ingn:data_requestAlias
. gn:data_requestAliasAll=”dbRequestName”
(optional)- when used query is performed on
gn:data_requestAliasAll
dbRequest
instead ofgn:data_request
and query result data is stored togn: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 fromdbRequest
which is receiving dataKeyMap
must be used. What happens in alias query is that thedbRequest
that is being queried“key”
field names are used and by them looked updbRequest
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 thatdbRequest 1
column Y value will be used as key to preform query ondbRequest 2
with column name A. - This will only work with
“text”
columns and when attributegn: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 widgetgn:data_requestAliasValueMap=”Bb|B”
- This will only work with
“text”
columns and when attributegn:data_requestAliasAll
is present. gn:data_writeExistingDbRequestFieldsOnly=”true”
- defines that query from database will write to in memory
dbRequest
only fields that are defined indbSchema
of thatdbRequest
and drop all other fields. - This is useful when querying another
dbRequest
and we want to keep fields only relevant todbRequest
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 fromdbRequest A
todbRequest B
and overwritten but“c”
and“d”
are dropped because destinationdbRequest
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 widgetgn:data_field=”fieldName”
– must be identical to field in queries.xml for thisdbRequest
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.