如何按顺序执行Google可视化查询?

时间:2017-06-13 09:22:56

标签: google-visualization

我必须在顺序中执行几个查询并比较第一个和第二个查询数据并相应地绘制表格。我真的很无知找出问题所在。我知道,查询执行是异步的。请帮忙。

//First Query
        function drawVisualization() {
            alert(" I am first");
            var sqlLastQuarterWeeks = "sql?tq=select MonthName, WeekStart, WeekEnd &sqlQueryID=last_quarter_weeks";
            var qryLastQuarterWeeks = new google.visualization.Query(sqlLastQuarterWeeks);
            qryLastQuarterWeeks.send(handleLastQuarterWeeksSqlQueryResponse);
        }
        function handleLastQuarterWeeksSqlQueryResponse(dataQueryLastQuarterWeeksResponse) {
            if (dataQueryLastQuarterWeeksResponse.isError()) {
                alert('Error in query: ' + dataQueryLastQuarterWeeksResponse.getMessage() + ' ' + dataQueryLastQuarterWeeksResponse.getDetailedMessage());
                return;
            }
            gblWeeksInformation = dataQueryLastQuarterWeeksResponse.getDataTable();

            drawLastQuarterWeeksAnalysis();

            //Second Query
            function drawLastQuarterWeeksAnalysis() {
                alert("I am second");
                var sqlLastQuarterWeeksAnalysis = "sql?tq=select Project, Passed, Failed, WeekStart, WeekEnd, WeekNumber &sqlQueryID=last_quarter_weeks_analysis";
                var qryLastQuarterWeeksAnalysis = new google.visualization.Query(sqlLastQuarterWeeksAnalysis);
                qryLastQuarterWeeksAnalysis.send(handleLastQuarterWeeksAnalysisSqlQueryResponse);
            }

            function handleLastQuarterWeeksAnalysisSqlQueryResponse(dataQueryLastQuarterWeeksAnalysisResponse) {
                if (dataQueryLastQuarterWeeksAnalysisResponse.isError()) {
                    alert('Error in query: ' + dataQueryLastQuarterWeeksAnalysisResponse.getMessage() + ' ' + dataQueryLastQuarterWeeksAnalysisResponse.getDetailedMessage());
                    return;
                }
                var dtLastQuarterWeeksAnalysis = dataQueryLastQuarterWeeksAnalysisResponse.getDataTable();
                alert(dtLastQuarterWeeksAnalysis.getNumberOfRows());
                var intNumberOfRows = dtLastQuarterWeeksAnalysis.getNumberOfRows();
                var intRowCounter;
                var tblWeekOverAnalysis = new google.visualization.DataTable();
                for (intRowCounter = 0; intRowCounter < WEEKLY_TESTS_TABLE_COLUMNS.length; intRowCounter++) {
                    if (WEEKLY_TESTS_TABLE_COLUMNS[intRowCounter] !== null) {
                        var colDataType = WEEKLY_TESTS_TABLE_COLUMNS[intRowCounter].split(':')[0];
                        var colDataValue = WEEKLY_TESTS_TABLE_COLUMNS[intRowCounter].split(':')[1];
                        tblWeekOverAnalysis.addColumn(colDataType, colDataValue);
                    }
                }
                var tblWeekOverAnalysisRow = new Array();
                for (intRowCounter = 0; intRowCounter < dtLastQuarterWeeksAnalysis.getNumberOfRows() ; intRowCount++) {
                    var strApplicationName = dtLastQuarterWeeksAnalysis.getValue(intRowCounter, 0);
                    tblWeekOverAnalysisRow[intRowCounter] = strApplicationName;
                    var strTestRunDates = dtLastQuarterWeeksAnalysis.getValue(intRowCounter, 3);
                    var arrTestRunDates = removeDuplicates(strTestRunDates);
                    var arrTestRunResults = getSortedTestRuns(strTestRunDates);
                    for (var intRowIterator = 0; intRowIterator < arrTestRunResults.length; intRowIterator++) {
                        var strTestRunDate = getTestRunOfDate(arrTestRunResults[intRowIterator], gblWeeksInformation);
                        tblWeekOverAnalysisRow[intRowCounter] = arrTestRunResults[intRowIterator];
                    }
                }
            }
        }

当我查询行数时,我得到两个执行的相同答案。我在这里缺少什么?

基于我之前的question尝试解决方案:没有运气。

<script type="text/javascript">
        google.setOnLoadCallback(drawVisualization);
        function drawVisualization() {
            var sqlQuery = "sql?tq=select MonthName, WeekStart, WeekEnd &sqlQueryID=last_quarter_weeks";
            var query1 = new google.visualization.Query(sqlQuery);

            query1.send(function (queryResponse) {
                drawQuestions(queryResponse);
            });

            var sqlQuery2 = "sql?tq=select Project, Passed, Failed, WeekStart, WeekEnd, WeekNumber &sqlQueryID=last_quarter_weeks_analysis";
            var query2 = new google.visualization.Query(sqlQuery2);

            query2.send(function (queryResponse) {
                drawQuestions(queryResponse);
            });

        }
        function drawQuestions(response) {
            alert(response.getDataTable().getNumberOfRows());
            //answer is 11 & 11. expected is 11 & 180
        }
    </script> 

由于

1 个答案:

答案 0 :(得分:0)

道歉。我整理出来了。

var sqlQuery2 = "sql?tq=select Project, Passed, Failed, WeekStart, WeekEnd, WeekNumber &sqlQueryID=last_quarter_weeks_analysis";

我收到了错误的列名,导致查询错误。此行为不允许执行第二个查询并始终返回第一个查询。