0
こんにちは私はアンドロイドプロジェクトに取り組んでいます。私はWindowsマシン上にあらかじめ用意されたSQLiteデータベースに接続しようとしていました。 私はWindowsマシンでテストできるかどうか、またはエミュレータで出力を見ることができないので、テストするためにアンドロイドデバイスに接続する必要があるかどうかを知りたい。 .Thanksイオンフレームワークを使用したSQLiteの接続とテスト
enter code here
<!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">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
</head>
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar-stable">
<h1 class="title">Ionic DataBase</h1>
</ion-header-bar>
<ion-content ng-controller="ExampleController">
<button class="button" ng-click="SelectAll()">select</button>
<button class="button" ng-click="insert()">INSERT</button>
</ion-content>
</ion-pane>
</body>
</html>
enter code here
app.js上記
var example = angular.module('starter', ['ionic', 'ngCordova'])
var db = null;
example.run(function ($ionicPlatform,$cordovaSQLite) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
//window.Plugin.sqlDB.copy("newdata.db"), function()
{
db = $cordovaSQLite.openDatabase("newdata.db");
//}, function (error) {
db = $cordovaSQLite.openDatabase("newdata.db");
}
});
});
example.controller("ExampleController", function ($scope, $cordovaSQLite) {
$scope.SelectAll = function() {
var query = "select ID, Dept from Department";
$cordovaSQLite.execute(db, query, []).then(function (res) {
if (res.rows.length > 0) {
for (var i = 0; i < res.rows.length; i++) {
}
}
console.log("selected-> " + res.rows.item(i).ID + " " + res.rows.item(i).Dept);
}, function (err) {
console.error("No result found");
});
}
});
example.controller("ExampleController", function($scope, $cordovaSQLite) {
$scope.insert = function (Dept) {
var query = "INSERT INTO Department (Dept) VALUES (Finance)";
$cordovaSQLite.execute(db, query, [Dept]).then(function (res) {
console.log("INSERT ID -> " + res.insertId);
}, function (err) {
console.error(err);
});
}
});
を助けてください私のプロジェクトで使用されるコードです。
、あなたの代わりに「コルドバ」の「コルドバ」と入力しました –