This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//aqui no controller | |
chatsFactory.select().then(function(res){ | |
if (res!=null) { | |
$scope.urldireciona = res.url; | |
// $scope.urldireciona = res["licenca"]; | |
console.log($scope.urldireciona); | |
} else { | |
console.log('No records found'); | |
} | |
}) | |
//aqui mexemos com o banco de dado sqlite | |
$conjunto.factory('chatsFactory', function($cordovaSQLite,$ionicPopup, $state,$http) { | |
if (window.cordova) { | |
db = $cordovaSQLite.openDB({ name: "DBUrl.db", location:"default" }); //device | |
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS chats (id integer primary key AUTOINCREMENT, url text, licenca text)"); | |
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS Usuario (id INTEGER PRIMARY KEY AUTOINCREMENT,matricula TEXT not null, cpf TEXT not null );"); | |
}else{ | |
db = window.openDatabase("DBUrl.db", '1', 'DBUrl', 1024 * 1024 * 100); // browser | |
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS enderecos (id integer primary key AUTOINCREMENT, url text, licenca text)"); | |
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS Usuario (id INTEGER PRIMARY KEY AUTOINCREMENT,matricula TEXT not null, cpf TEXT not null );"); | |
} | |
return { | |
//aqui inserimos na tabela enderecos chatsFactory.insert | |
insert : function(url, licenca) { | |
var query = "INSERT INTO enderecos (url, licenca) VALUES (?, ?)"; | |
var values = [url,licenca]; | |
$cordovaSQLite.execute(db, query, values).then( | |
function(res) { | |
$state.go('app.loginmat'); | |
}, | |
function(err) { | |
alert("Erro ao Inserir no Sqlite!"); | |
} | |
); | |
}, | |
//selecionamos a tabela enderecos | |
select : function() { | |
var query = "SELECT distinct(url), licenca FROM enderecos "; | |
return $cordovaSQLite.execute(db, query); | |
}, | |
//inserimos na tabela usuario | |
insertUsuario : function(matricula, cpf) { | |
var query = "INSERT INTO Usuario (matricula, cpf) VALUES (?, ?)"; | |
var values = [matricula,cpf]; | |
$cordovaSQLite.execute(db, query, values).then( | |
function(res) { | |
alert("deu certo"); | |
}, | |
function(err) { | |
alert("deu erro"); | |
} | |
); | |
}, | |
//selecionamos da tabela usuario | |
selectUsuario : function() { | |
var query = "SELECT * FROM Usuario "; | |
$cordovaSQLite.execute(db, query).then( | |
function(res) { | |
if (res.rows.length > 0) { | |
var first = res.rows.item(0); | |
console.log(res.rows.length + ' records, fist: ' +res.matricula+' '+res.cpf); | |
} else { | |
console.log('No records found'); | |
} | |
} | |
); | |
}, | |
//deletamos das duas tabelas | |
deletabd : function() { | |
var query = "Delete from Usuario"; | |
$cordovaSQLite.execute(db, query).then( | |
function(res) { | |
console.log("apagou tudo"); | |
} | |
); | |
var queryurl = "Delete from enderecos"; | |
$cordovaSQLite.execute(db, queryurl).then( | |
function(res) { | |
console.log("apagou tudo"); | |
} | |
); | |
} | |
} | |
//vou fazer fora | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment