From wiki.ginstr.com
Revision as of 15:22, 12 July 2017 by Mark (talk | contribs) (Query with multiple keys and queryType defined, where the keys are split by SPLITKEYVALUES)
Jump to: navigation, search

gn:act_rawQueryToWidget

Description
Action used to query data from database and store value to a target.
Action returns
boolean

Action signatures

Query with keys

[gn:act_rawQueryToWidget]|[table,query,column,target;key{n}]
Parameter Description
table table name from which to query data
query query name defined in queries.xml
column table column name from which value will be used
target target where the value from column will be stored
key{n} key to use as values for query

Can be:

Example

locations - table name
locationsByName - query name
location_name - column name
@+id/location_name - target
@+id/location_name - key
[gn:act_rawQueryToWidget]|[locations,locationsByName,location_name,@+id/location_name;@+id/location_name]
queries.xml
<query id="locationsByName"
  columns="location_name" 
  keys="location_name" />

Query without keys

[gn:act_rawQueryToWidget]|[table,query,column,target]
Parameter Description
table table name from which to query data
query query name defined in queries.xml
column table column name from which value will be used
target target where the value from column will be stored

Example

services - table name
services - query name
service_name - column name
@+id/service_name - target
[gn:act_rawQueryToWidget]|[services,services,service_name,@+id/service_name]
queries.xml
<query 
  id="services"
  columns="
    service_name,
    service_comments" />

Query without target to check if some record exists

[gn:act_rawQueryToWidget]|[table,query,column;key{n}]
Parameter Description
table table name from which to query data
query query name defined in queries.xml
column table column name from which value will be used
key{n} key to use as values for query

Can be:

Example

assetItems - table name
assetItemsByCode - query name
assetItem_nfcTag - column name
@+id/assetItem_code - key
[gn:act_rawQueryToWidget]|[assetItems,assetItemsByCode,assetItem_nfcTag;@+id/assetItem_code]
queries.xml
<query 
  id="assetItemsByCode"
  columns="
    assetItem_assetNumber,
    assetItem_code,
    assetItem_nfcTag,
    assetItem_assignment"
  keys="assetItem_code" />

Query without column that stores entire result to targets that accept multiple rows

[gn:act_rawQueryToWidget]|[table,query,,target;key{n}]
Parameter Description
table table name from which to query data
query query name defined in queries.xml
target target where the value from column will be stored
key{n} key to use as values for query

Can be:

Example

bebraTimeRecordingbokings - table name
bebraTimeRecordingbokingsByConstructionSiteAndActive - query name
- - all columns
@+id/lstSite - target
@+id/bebraTimeRecording_constructionSite,@variable/true - keys
[gn:act_rawQueryToWidget]|[bebraTimeRecordingbokings,bebraTimeRecordingbokingsByConstructionSiteAndActive,-, @+id/lstSite;@+id/bebraTimeRecording_constructionSite,@variable/true]
queries.xml
<query 
  id="bebraTimeRecordingbokingsByConstructionSiteAndActive" 
  columns="
    nfc,
    user,
    name,
    surname,
    personellnum,
    comment,
    userlocation,
    deviceSerial,
    timestamp,
    timestampEnd,
    workingTimeInHours,
    constructionSite,active" 
  keys="constructionSite,active" />

Query with multiple keys and queryType defined

[gn:act_rawQueryToWidget]|[table,query,column,target,queryType;key{n}]
Parameter Description
table table name from which to query data
query query name defined in queries.xml
column table column name from which value will be used
target target where the value from column will be stored
queryType defines type of query to be executed (See Query types for db queries)
key{n} key to use as values for query

Can be:

Example

users - table name
userById - query name
username - column name
@+id/gnEditTextName - target
sorttop - queryType
@variable/userId,@variable/userName - key
[gn:act_rawQueryToWidget]|[users,userById,username,@+id/gnEditTextName, sorttop;@variable/userId,@variable/userName]

Query with multiple keys and queryType defined, where the keys are split by SPLITKEYVALUES

[gn:act_rawQueryToWidget]|[table,query,-,target,queryType,viewType;key{n}]
Parameter Description
table table name from which to query data
query query name defined in queries.xml
target target where the value from column will be stored
queryType defines type of query to be executed (See Query types for db queries)
viewType used for special purpose

Can be:

  • SPLIKEYVALUES - used to notify this action to split each key value by or , and to execute queries for each split key
key{n} key to use as values for query

Can be:

Example

Drivers - table name
driversByFirstAndLastName - query name
- - all columns
+id/lstDriversNoSub - target
regular - queryType
SPLITKEYVALUES - viewType
+id/Driver_firstAndLastName - key
[gn:act_rawQueryToWidget]|[Drivers,driversByFirstAndLastName,-,@+id/lstDriversNoSub,regular,SPLITKEYVALUES;@+id/Driver_firstAndLastName]
queries.xml
<query 
  id="driversByFirstAndLastName" 
  columns="
    Driver_firstName,
    Driver_lastName,
    Driver_firstAndLastName,
    Driver_comments,
    Driver_subName"
  type="INDEX"
  keys="Driver_firstName,Driver_lastName" />

Query types for db queries

queryType Description
regular standard query
sort query that returns all matches sorted i.e. if by timestamp, from earliest to latest.

In queries.xml query keys=”key,key,...,lastKey”, lastkey must be the column by which we want to sort

sortreverse query that returns all matches sorted i.e. if by timestamp, from latest to earliest.

In queries.xml query keys=”key,key,...,lastKey”, lastkey must be the column by which we want to sort

sorttop query that returns single first result and is sorted like sort query
sortreversetop query that returns single first result and is sorted like sortreverse query
paging query that returns results with limit and skip, unsorted
count count returns number of matching row results