none
[NodeJS][Mobile Apps] MobileServices EasyAPI. SQL Query with multiple result sets RRS feed

  • Question

  • Hi, 

    I am writing an API that reads data

    var query = "<a sql query that returns multiple result sets>"

               req.azureMobile.data.execute(query)

                   .then(function (results) {

                        console.log("results : ", results);
                        res.writeHead("200", { 'Content-Type': 'application/json; charset=utf-8' });
                        res.end(JSON.stringify(results));
                        return next();

                    }, function (error) {
                        console.log("this is the error", error);
                    });

    The result results only contains the first result set. Is there a way to get them all ?

    Many thanks

    Francis



    Friday, April 29, 2016 9:17 AM

Answers

  • Hi Francis,

    The SQL query you pass to data.execute is an object containing various properties describing the query - they are documented at http://azure.github.io/azure-mobile-apps-node/module-azure-mobile-apps_src_data_execute.html.

    Essentially, if you add a property called multiple with a value of true to the query object, the result will be an array of result sets. For example:

    var query = {
      sql: "select * from table1 where value = @value;select * from table2 where value = @value",
      parameters: [{ name: 'value', value: 1 }]
      multiple: true
    };
    req.azureMobile.data.execute(query)
      .then(function (results) {
        // results here is an array - the first element is the results of the first query,
        // the second element the results of the second
      })
      .catch(next); // don't forget to pass errors to the express middleware pipeline

    Hope this helps!

    Dale

    Friday, April 29, 2016 10:50 PM

All replies

  • Hello,

    Thank you for posting here!

    You can fetch multiple result set through REST API, please refer the link.

    And also there is another way by using Android SDK for Azure Mobile Service. Please refer the Stack Over flow for the same.

    Hope this helps.

    Regards,

    Swikruti

    If a post answers your question, please click Mark as Answer on that post and Vote as Helpful.

    • Proposed as answer by Swikruti Bose Thursday, May 5, 2016 11:16 AM
    Friday, April 29, 2016 3:48 PM
  • Hi Francis,

    The SQL query you pass to data.execute is an object containing various properties describing the query - they are documented at http://azure.github.io/azure-mobile-apps-node/module-azure-mobile-apps_src_data_execute.html.

    Essentially, if you add a property called multiple with a value of true to the query object, the result will be an array of result sets. For example:

    var query = {
      sql: "select * from table1 where value = @value;select * from table2 where value = @value",
      parameters: [{ name: 'value', value: 1 }]
      multiple: true
    };
    req.azureMobile.data.execute(query)
      .then(function (results) {
        // results here is an array - the first element is the results of the first query,
        // the second element the results of the second
      })
      .catch(next); // don't forget to pass errors to the express middleware pipeline

    Hope this helps!

    Dale

    Friday, April 29, 2016 10:50 PM