Javascript 使用sqlite数据库的参数化select查询在angular js中不起作用
我想使用where子句获取数据,但我无法这样做。Javascript 使用sqlite数据库的参数化select查询在angular js中不起作用,javascript,android,angularjs,sqlite,ionic-framework,Javascript,Android,Angularjs,Sqlite,Ionic Framework,我想使用where子句获取数据,但我无法这样做。 (例如:如果我在用户名中输入“sid”,它应该给出与“sid”链接的所有记录)。请告诉我需要更改的内容。 下面是我的代码: var example = angular.module('starter', ['ionic', 'ngCordova']) .run(function($ionicPlatform, $cordovaSQLite) { $ionicPlatform.ready(function() { if(wi
(例如:如果我在用户名中输入“sid”,它应该给出与“sid”链接的所有记录)。请告诉我需要更改的内容。
下面是我的代码:
var example = angular.module('starter', ['ionic', 'ngCordova'])
.run(function($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
db = window.openDatabase("my.db","1.0","my.db",100000);
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
window.alert("Database Created .. !")
});
});
example.controller("ExampleController", function($scope, $cordovaSQLite) {
$scope.insert = function(firstname, lastname) {
var query = "INSERT INTO people (firstname,lastname) VALUES (?,?)";
$cordovaSQLite.execute(db, query, [firstname, lastname]).then(function(res) {
console.log("INSERT ID -> " + res.insertId);
}, function (err) {
console.error(err);
});
}
$scope.select = function(firstname) {
$cordovaSQLite.execute(db,"SELECT firstname, lastname FROM people where lastname=?",[firstname]).then(function(res) {
if(res.rows.length >0)
for(var i=0;i<=res.rows.length;i++){
window.alert("SELECTED -> " + res.rows.item(i).firstname + " " + res.rows.item(i).lastname);
} else {
console.log("No results found");
}
}, function (err) {
console.error(err);
});
}
});
var-example=angular.module('starter',['ionic','ngCordova']))
.run(函数($ionicPlatform,$cordovaSQLite){
$ionicPlatform.ready(函数(){
if(window.cordova&&window.cordova.plugins.Keyboard){
插件键盘hideKeyboardAccessoryBar(真);
}
如果(窗口状态栏){
StatusBar.styleDefault();
}
db=window.openDatabase(“my.db”,“1.0”,“my.db”,100000);
$cordovaSQLite.execute(db,“创建表,如果不存在人(id整数主键,firstname文本,lastname文本)”);
window.alert(“已创建数据库…”)
});
});
示例控制器(“示例控制器”,函数($scope,$cordovaSQLite){
$scope.insert=函数(firstname,lastname){
var query=“插入到人员(firstname,lastname)值(?,)”;
$cordovaSQLite.execute(数据库,查询,[firstname,lastname])。然后(函数(res){
log(“插入ID->”+res.insertId);
},函数(err){
控制台错误(err);
});
}
$scope.select=函数(名字){
$cordovaSQLite.execute(db,“从lastname=?”的人中选择firstname,lastname,[firstname])。然后(函数(res){
如果(res.rows.length>0)
对于(var i=0;i只需使用以下代码在angular js for sqlite数据库中进行参数化select查询
$scope.login = function(firstname,lastname) {
$cordovaSQLite.execute(db,"SELECT firstname, lastname FROM people where firstname=? and lastname=?",[firstname,lastname]).then(function(res) {
if(res.rows.length >0)
window.location="login.html";
}, function (err) {
console.error(err);
});
}
你能准确地描述一下什么不起作用吗?你做过调试吗?我的问题解决了,先生。谢谢:)很高兴你解决了:)