LInkItem SQL query

Feedback


SQL query supports the setting of other query conditions. For instance, attributeFilter, groupBy, ids, joinItems, linkItems, orderBy, etc. Here we take setting LinkItem as an example to construct a SQL query to get the records with equal Capital values in the Countries@World and Capitals@World layers.

Two parameters need to be transferred for this SQL query: queryMode and queryParameters. Here queryMode is SqlQuery. The code is as follows:

//LInkItem SQL query

function SQLQueryByLinkItem()

{

    var commit=getcommit();

    var uri="http://localhost:8090/iserver/services/map-world/rest/maps/World Map/queryResults.rjson";

    //Set the request body parameters

    var entry={};

    entry.queryMode="SqlQuery";

entry.queryParameters={

    "startRecord": 0,

    "queryParams": [{

        "name": "Capitals@world",

        "linkItems": [{

            "datasourceConnectionInfo": {

                "engineType": "UDB",

                "readOnly": false,

                "connect": true,

                "openLinkTable": false,

                "alias": "World",

                "exclusive": false

            },

            "name": null,

            "foreignKeys": ["Capital"],

            "primaryKeys": ["Capital"],

            "linkFilter": "Capital = Capital",

            "foreignTable": "Countries"

        }]

    }],

    "expectCount": 100000,

    "queryOption": "ATTRIBUTEANDGEOMETRY"

};

    commit.open("POST",encodeURI(uri),false,"","");

    commit.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

    //alert(toJSON(entry));

    commit.send(toJSON(entry));    

    //Parse the json string returned from the server to a JavaScript object

    var response = json_parse(commit.responseText, null);       

    //Gets the Div container for display.

    var container = document.getElementById('container');

    container.innerHTML="";

    //Determine whether the query is successful

    if(!response.succeed)

    {

        //Query failed

        container.innerHTML+="<p>Query failed</p>";

        container.innerHTML+="<p>Error code: "+response.error.code+"</p><p>Cause: "+response.error.errorMsg+"</p>";

    }else

    {

        //Query succeeded

        container.innerHTML+="<p>Query succeeded</p>";

        container.innerHTML+="<p>URI of queryResult resource: "+response.newResourceLocation+"</p>";

    }   

}

linkItems is used to specify the parameters for linking external table, please see LinkItem for details. Please refer to SQL Query for other parameters.

Perform the query to get a URI for the queryResult resource similar to http://localhost:8090/iserver/services/map-world/rest/maps/World Map/queryResults/3jx2ilcv_c81111e25a7f404ea36b2c8690756453.rjson 的 queryResult. The queryResult resource contains information about records satisfying the condition.

Please refer to Parsing queryResult to know more about the parsing of the queryResult resource.