如何修复prepare语句失败并出现错误:“1” - 使用SQLite?

时间:2022-06-03 23:08:29

I created a factory with a function that deliver a query for $cordovaSQLite.execute. I am sure that the query is correctly because I run that right in the database using SQLiteBrowser in this works perfectly. In the console I have a message informing that the database was opened. But this function is not returning the data that I need.

我创建了一个带有函数的工厂,该函数为$ cordovaSQLite.execute提供查询。我确信查询是正确的,因为我使用SQLiteBrowser在数据库中运行正确,这完美。在控制台中,我有一条消息,通知数据库已打开。但是这个函数没有返回我需要的数据。

I received this error: prepare statement failed with error: 1.

我收到此错误:prepare语句失败,错误:1。

This is my code:

这是我的代码:

factotyDatabase.js
var app = angular.module('anotei');

app.factory('factoryDatabase', function($cordovaSQLite, $ionicLoading, $q){

var currentDB = undefined;
var DATABASE_NAME = 'anotei.db';
var PATH = 'anotei.db';

return{
    init: function(){
        if(currentDB == undefined){
            currentDB = window.sqlitePlugin.openDatabase({
                name: DATABASE_NAME,
                createFromResources: PATH
            });
        }
        return currentDB;
    },

    executeQuery: function(deliveredQuery, fields){
        var defer = $q.defer();
        $ionicLoading.show();

        var resp = $cordovaSQLite.execute(currentDB, deliveredQuery, fields);
        resp.then(
            function(execution){
                defer.resolve(execution);
                $ionicLoading.hide();
            },
            function(error){
                $ionicLoading.hide();
                    defer.reject(error);
                    console.log(error);
                }
            );
            return defer.promise;
        }


    }
});

// This is the service with the function that calls the factory

var app = angular.module('anotei');

app.service('serviceSubject', function($q, factoryDatabase){

    return{
        getSubjects: function(){
        var defer = $q.defer();

        var resp = factoryDatabase.executeQuery('select * from materias');

        resp.then(
            function(resultSet){
                var listMateria = [];

                for(var i = 0; i < resultSet.rows.length; i++){
                    var materia = {};

                    materia.id_materia = resultSet.rows.item(i).id_materia;
                    materia.nome = resultSet.rows.item(i).nome;
                    materia.max_faltas = resultSet.rows.item(i).max_faltas;
                    materia.professor = resultSet.rows.item(i).professor;
                    materia.email_prof = resultSet.rows.item(i).email_prof;
                    materia.num_faltas = resultSet.rows.item(i).num_faltas;

                    listMateria.push(materia);
                }
                defer.resolve(listMateria);
            },
            function(error){
                console.log(error);
                }
            );

            return defer.promise;
        }
    }

});

1 个解决方案

#1


1  

I solved the problem.

我解决了这个问题。

I was just using an old version of $cordovaSQLite. I just uninstalled that and run again:

我刚刚使用旧版本的$ cordovaSQLite。我刚刚卸载并重新运行:

Plugin add for cordova https://github.com/litehelpers/Cordova-sqlite-storage.git

插件添加为cordova https://github.com/litehelpers/Cordova-sqlite-storage.git

Problem was fixed. Thanks!!!

问题得到解决。谢谢!!!

#1


1  

I solved the problem.

我解决了这个问题。

I was just using an old version of $cordovaSQLite. I just uninstalled that and run again:

我刚刚使用旧版本的$ cordovaSQLite。我刚刚卸载并重新运行:

Plugin add for cordova https://github.com/litehelpers/Cordova-sqlite-storage.git

插件添加为cordova https://github.com/litehelpers/Cordova-sqlite-storage.git

Problem was fixed. Thanks!!!

问题得到解决。谢谢!!!