SQLError无法准备语句

时间:2017-05-30 08:26:17

标签: angularjs sqlite

嗨我试图动态地按角度对我的sqlite进行ORDER。但它总是说erro rcould不能准备声明..它重定向到我的订单字符串..但是当我手动设置我的ASC或DESC时它工作得很好。我的问题是如何将我的字符串设置为我的查询

这是我的js。 order_by_field等于名称,顺序等于ASC或DESC

//Sort Priority Ascending
            $scope.sortAsc = function() {
                sort_orderby('name', 'asc');
                $scope.orderByPopover.hide();
            };

            //Sort Priority Descending
            $scope.sortDesc = function() {
                sort_orderby('name', 'desc');
                $scope.orderByPopover.hide();
            };

            function sort_orderby(order_by_field, order) {

                var query = "SELECT * FROM listJobs ORDER BY '" + order_by_field + "' '"+ order +"' ";
                $cordovaSQLite.execute(db, query, [])
                    //If success
                    .then(function(data) {

                            offlineGetJobList();
                            console.log(data.rows)
                        },
                        function(err) {
                            console.error(err);
                        });



            }

1 个答案:

答案 0 :(得分:1)

var query = "SELECT * FROM listJobs ORDER BY '" + order_by_field + "' '"+ order +"' ";

应该是

var query = "SELECT * FROM listJobs ORDER BY " + order_by_field + " "+ order +" ";