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

queries.xml

queries.xml is an XML file located in app/database/ folder.
This file contains all queries which are used to read any data from the database.
It is necessary to create a "layout" for that data which is identical to the persistent storage structure. These "layouts" are called views. Once a view is created data is copied based on query from the database view into the persistent storage structure.
Queries defined in queries.xml file are used by rawQuery actions.

XML Attributes Description

Attribute Description
id represents a view name
appId optional attribute used in cases where external table data will be queried, represents an id of the ginstr app where table from the "table" attribute belongs.
table represents a table on which this querry will be executed
keys represents a list of view keys (column names) which belong to the same table and will be used to query the data
type represents a list of query types

More information here

List of supported actions

gn:act_rawQueryToWidgets
gn:act_rawQueryCountToTarget
gn:act_queryWiFiFingerprint
gn:act_queryGSMFingerprint
gn:act_queryBTFingerprint
gn:act_queryBLEFingerprint

Example

<?xml version="1.0" encoding="utf-8"?>
<queries>
  <query 
    id="employeesByRecordId" 
    table="employees"
    keys="_id" />

  <query id="employeesByNFCTag" 
    table="employees"
    keys="employee_NFCtag" />

  <query id="devicesOverviewByNameAndFacilitySortByName" 
    appId="caregiverChecklist"
    table="devices"
    keys="device_facility,device_name" />

  <query 
    id="driversByFirstAndLastName" 
    table="drivers"
    type="INDEX"
    keys="Driver_firstName,Driver_lastName" />
</queries>

View types

View type Description
AND returns documents for key group (default value)
OR returns documents for each key in key group
INDEX returns list of document ids for key group

Workflow

Create a table definition in configuration.xml file

<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://www.ginstr.com/schema/configuration" 
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               generate="true">
<tables>
<table id="assetItems" name="assetLocationManager_assetItems">
 <columnText id="assetItem_assetNumber" name="assetLocationManager_assetItem_assetNumber" required="true" unique="true" />
 <columnText id="assetItem_code" name="assetLocationManager_assetItem_code" />
 <columnText id="assetItem_nfcTag" name="assetLocationManager_assetItem_nfcTag" />
 <columnText id="assetItem_assignment" name="assetLocationManager_assetItem_assignment" />
</table>
</configuration>

Create a query definition in queries.xml file based on defined table

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<queries>
	<query
		id="assetItemsByAssetNumber"
		table="assetItems"
		keys="assetItem_assetNumber"
		/>
</queries>

Insert an action in layout file with defined query id

[gn:act_rawQueryToWidget]|[assetItems,assetItemsByAssetNumber,assetItem_assetNumber,@+id/assetItem_assetNumber1;@+id/assetItem_assetNumber2]

In the above example, with the key based on the value from @+id/assetItem_assetNumber2 widget once the action has executed the result from assetItem_assetNumber column will be stored in @+id/assetItem_assetNumber1 widget

Insert an action in layout file with defined query id

[gn:act_rawQueryToWidget]|[assetItems,assetItemsByAssetNumber,_id,@+id/assetItem_id;@+id/assetItem_assetNumber2]

In the above example, with the key based on the value from @+id/assetItem_assetNumber2 widget once the action has executed the row id will be stored in @+id/assetItem_id widget