Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/416.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我不是';无法在爱奥尼亚1的cordova sqlite存储中打开db_Javascript_Android_Sqlite_Cordova_Ionic Framework - Fatal编程技术网

Javascript 我不是';无法在爱奥尼亚1的cordova sqlite存储中打开db

Javascript 我不是';无法在爱奥尼亚1的cordova sqlite存储中打开db,javascript,android,sqlite,cordova,ionic-framework,Javascript,Android,Sqlite,Cordova,Ionic Framework,我是爱奥尼亚1的新手,在sqlite存储中创建数据库时遇到了很多问题。你能帮我吗 我正在使用名为“cordova sqlite storage”的插件 问题是,当代码传入openDB命令时,它会在那里停止,无法继续 按照我的代码: js/sqlite.js var sqlite = angular.module('sqlite', ['ionic', 'ngCordova']); sqlite.run(function ($ionicPlatform, $cordovaSQLite) {

我是爱奥尼亚1的新手,在sqlite存储中创建数据库时遇到了很多问题。你能帮我吗

我正在使用名为“cordova sqlite storage”的插件 问题是,当代码传入openDB命令时,它会在那里停止,无法继续

按照我的代码:

js/sqlite.js

var sqlite = angular.module('sqlite', ['ionic', 'ngCordova']);

sqlite.run(function ($ionicPlatform, $cordovaSQLite) {
    $ionicPlatform.ready(function () {
        var db = $cordovaSQLite.openDB({ name: "rollers.db", bgType: 1 });
        $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS clientes (id integer primary key, razaoSocial varchar(40), nomeFantasia varchar(40), CNPJ text, Endereco text)");
        $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS instalacao (id integer primary key, idCliente int, DataInst datetime)");
        $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS manutencao (id integer primary key, idCliente int, idInstalacao int, DataManut datetime)");
        $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS equipamento (id integer primary key, idInstalacao int, idManutencao int, TC int, Rolo varchar(40))");
    });
})

sqlite.factory('clientesFactory', function ($cordovaSQLite) {
    return {
        insert: function (firstname, lastname, avatar, message) {
            var query = "INSERT INTO clientes    (razaoSocial, nomeFantasia, CNPJ, Endereco) VALUES (?, ?, ?, ?);";
            var values = [firstname, lastname, avatar, message];

            $cordovaSQLite.execute(db, query, values).then(
              function (res) {
                  console.log('INSERTED ID: ' + res.insertId);
              },
              function (err) {
                  console.log('ERROR: ' + err);
              }
            );
        },

        insertInstalacao: function (idCliente, DataInst) {
            var query = "INSERT INTO instalacao  (idCliente, DataInst) VALUES (?, ?);";
            var values = [idCliente, DataInst];

            $cordovaSQLite.execute(db, query, values).then(
              function (res) {
                  console.log('INSERTED ID: ' + res.insertId);
              },
              function (err) {
                  console.log('ERROR: ' + err);
              }
            );
        },

        insertInstalacao: function (idCliente, idInstalacao, DataManut) {
            var query = "INSERT INTO manutencao  (idCliente, idInstalacao, DataManut) VALUES (?, ?, ?, ?);";
            var values = [idCliente, idInstalacao, DataManut];

            $cordovaSQLite.execute(db, query, values).then(
              function (res) {
                  console.log('INSERTED ID: ' + res.insertId);
              },
              function (err) {
                  console.log('ERROR: ' + err);
              }
            );
        },

        insertInstalacao: function (idInstalacao, idManutencao, TC, Rolo) {
            var query = "INSERT INTO equipamento (idInstalacao, idManutencao, TC, Rolo) VALUES (?, ?, ?, ?);";
            var values = [idInstalacao, idManutencao, TC, Rolo];

            $cordovaSQLite.execute(db, query, values).then(
              function (res) {
                  console.log('INSERTED ID: ' + res.insertId);
              },
              function (err) {
                  console.log('ERROR: ' + err);
              }
            );
        },

        select: function (id) {
            var query = "SELECT * FROM clientes WHERE id=?";
            var values = [id];

            $cordovaSQLite.execute(db, query, values).then(
              function (res) {
                  if (res.rows.length > 0) {
                      var first = res.rows.item(0);
                      console.log(res.rows.length + ' records, fist: ' + first.firstname + ' ' + first.lastname + ' - ' + first.avatar);
                  } else {
                      console.log('No records found');
                  }
              }
            );
        }
    }
});
sqlite.run(function ($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function () {
var db = $cordovaSQLite.openDB({ name: "rollers.db", location: 'default' });
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS clientes (id integer primary key, razaoSocial text, nomeFantasia text, CNPJ text, Endereco text)");
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS instalacao (id integer primary key, idCliente integer, DataInst text)");
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS manutencao (id integer primary key, idCliente integer, idInstalacao integer, DataManut text)");
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS equipamento (id integer primary key, idInstalacao integer, idManutencao integer, TC integer, Rolo text)");
});
});
index.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/ionic.app.css" rel="stylesheet">
    -->

    <!--For users deploying their apps to Windows 8.1 or Android Gingerbread, platformOverrided.js
    will inject platform-specific code from the /merges folder -->
    <script src="js/platformOverrides.js"></script>

    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="lib/ngCordova/dist/ng-cordova.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/sqlite.js"></script>
    <script src="js/app.js"></script>
    <script src="js/controllers.js"></script>
    <script src="js/services.js"></script>
  </head>
  <body ng-app="starter">
    <ion-nav-view></ion-nav-view>
  </body>
</html>
app.js:

// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
// 'starter.services' is found in services.js
// 'starter.controllers' is found in controllers.js
SLAVE_AAPT_TIMEOUT = 30
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'sqlite'])
//angular.module('starter', ['ionic', 'starter.controllers', 'starter.services'])

.run(function ($ionicPlatform) {
    $ionicPlatform.ready(function () {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        if (cordova.platformId === "ios" && window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
            cordova.plugins.Keyboard.disableScroll(true);

        }
        if (window.StatusBar) {
            // org.apache.cordova.statusbar required
            StatusBar.styleDefault();
        }
    });
})

.config(function ($stateProvider, $urlRouterProvider) {

    // Ionic uses AngularUI Router which uses the concept of states
    // Learn more here: https://github.com/angular-ui/ui-router
    // Set up the various states which the app can be in.
    // Each state's controller can be found in controllers.js
    $stateProvider

    // setup an abstract state for the tabs directive
      .state('tab', {
          url: '/tab',
          abstract: true,
          templateUrl: 'templates/tabs.html'
      })

    // Each tab has its own nav history stack:

    .state('tab.home', {
        url: '/dash',
        views: {
            'tab-home': {
                templateUrl: 'templates/home.html',
                controller: 'HomeCtrl'
            }
        }
    })

    .state('tab.manutencao', {
        url: '/manutencao',
        views: {
            'tab-manutencao': {
                templateUrl: 'templates/manutencao.html',
                controller: 'InstalacaoCtrl'
            }
        }
    })

    .state('tab.instalacao', {
        url: '/instalacao',
        views: {
            'tab-instalacao': {
                templateUrl: 'templates/instalacao.html',
                controller: 'InstalacaoCtrl'
            }
        }
    })

    .state('tab.instalacao-detalhe', {
        url: '/instalacao-detalhe',
        views: {
            'tab-instalacao-detalhe': {
                templateUrl: 'templates/instalacao-detalhe.html',
                controller: 'InstalacaoDetalheCtrl'
            }
        }
    })

    .state('tab.cliente', {
        url: '/cliente',
        views: {
            'tab-cliente': {
                templateUrl: 'templates/cliente.html',
                controller: 'ClienteCtrl'
            }
        }
    })

    .state('tab.cliente-detalhe', {
        url: '/cliente-detalhe',
        views: {
            'tab-cliente-detalhe': {
            templateUrl: 'templates/cliente-detalhe.html',
            controller: 'ClienteDetalheCtrl'
            }
        }
    });

    // if none of the above states are matched, use this as the fallback
    $urlRouterProvider.otherwise('/tab/dash');

});
//Ionic Starter应用程序
//angular.module是创建、注册和检索angular模块的全局位置
//“starter”是此角度模块示例的名称(也在index.html中的属性中设置)
//第二个参数是“requires”的数组
//可以在services.js中找到“starter.services”
//可以在controllers.js中找到“starter.controllers”
从机超时=30
angular.module('starter'、['ionic'、'starter.Controller'、'starter.services'、'sqlite']))
//angular.module('starter'、['ionic'、'starter.Controller'、'starter.services']))
.run(函数($ionicPlatform){
$ionicPlatform.ready(函数(){
//默认情况下隐藏附件栏(删除此选项可在键盘上方显示附件栏)
//表格输入)
if(cordova.platformId==“ios”&&window.cordova&&window.cordova.plugins&&window.cordova.plugins&&window.plugins.Keyboard){
插件键盘hideKeyboardAccessoryBar(真);
插件。键盘。禁用滚动(真);
}
如果(窗口状态栏){
//需要org.apache.cordova.statusbar
StatusBar.styleDefault();
}
});
})
.config(函数($stateProvider,$urlRouterProvider){
//Ionic使用AngularUI路由器,它使用状态的概念
//在此处了解更多信息:https://github.com/angular-ui/ui-router
//设置应用程序可以处于的各种状态。
//每个州的控制器都可以在controllers.js中找到
$stateProvider
//设置tabs指令的抽象状态
.state('tab'{
url:“/tab”,
摘要:没错,
templateUrl:'templates/tabs.html'
})
//每个选项卡都有自己的导航历史堆栈:
.state('tab.home'{
url:“/dash”,
观点:{
“制表符主页”:{
templateUrl:'templates/home.html',
控制器:“HomeCtrl”
}
}
})
.state('tab.manutencao'{
url:“/manutencao”,
观点:{
“tab manutencao”:{
templateUrl:'templates/manutencao.html',
控制器:“InstalacaoCtrl”
}
}
})
.state('tab.instalacao'{
url:“/instalacao”,
观点:{
“tab instalacao”:{
templateUrl:'templates/instalacao.html',
控制器:“InstalacaoCtrl”
}
}
})
.state('tab.instalacao detalhe'{
url:“/instalacao detalhe”,
观点:{
“tab instalacao detalhe”:{
templateUrl:'templates/instalacao detalhe.html',
控制器:“InstalacaoDetalheCtrl”
}
}
})
.state('tab.cliente'{
url:“/cliente”,
观点:{
“tab客户”:{
templateUrl:'templates/cliente.html',
控制器:“clientCtrl”
}
}
})
.state('tab.cliente detalhe'{
url:“/cliente detalhe”,
观点:{
“tab客户详细信息”:{
templateUrl:'templates/cliente detalhe.html',
控制员:'ClienteDetalheCtrl'
}
}
});
//如果上述状态均不匹配,则将其用作回退
$urlRouterProvider。否则('/tab/dash');
});
如果你能帮助我,我会非常感激

感谢您的关注。

在sqlite.js中尝试一下

sqlite.run(function ($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function () {
var db = $cordovaSQLite.openDB({ name: "rollers.db", location: 'default' });
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS clientes (id integer primary key, razaoSocial text, nomeFantasia text, CNPJ text, Endereco text)");
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS instalacao (id integer primary key, idCliente integer, DataInst text)");
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS manutencao (id integer primary key, idCliente integer, idInstalacao integer, DataManut text)");
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS equipamento (id integer primary key, idInstalacao integer, idManutencao integer, TC integer, Rolo text)");
});
});
在sqlite.js中试试这个

sqlite.run(function ($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function () {
var db = $cordovaSQLite.openDB({ name: "rollers.db", location: 'default' });
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS clientes (id integer primary key, razaoSocial text, nomeFantasia text, CNPJ text, Endereco text)");
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS instalacao (id integer primary key, idCliente integer, DataInst text)");
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS manutencao (id integer primary key, idCliente integer, idInstalacao integer, DataManut text)");
    $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS equipamento (id integer primary key, idInstalacao integer, idManutencao integer, TC integer, Rolo text)");
});
});

谢谢你的帮助。我使用了你所说的,只是改变了调用我的sqlite.js的位置,一切都很好。在cordova.js之后,他在index.html中被调用。当我把它放在cordova.js之前的一个地方时,一切都很好。谢谢你的帮助。我使用了你所说的,只是改变了调用我的sqlite.js的位置,一切都很好。在cordova.js之后,他在index.html中被调用。当我把它放在cordova.js之前的一个地方时,一切都很好。