React native için sqlite sorguları


db.transaction((tx) => {
tx.executeSql('SELECT * FROM pet', [], (tx, results) => {
let myList = [];
if (results.rows.length > 0) {
for (var i = 0; i < results.rows.length; i++) {
var pet = results.rows.item(i);
myList.push(pet.owner);
}
this.setState({myList: myList});
}
});

tx.executeSql('SELECT * FROM pet WHERE owner=?', ['petowner'], (tx, results) => {
var len = results.rows.length;
if (len > 0) {
var row = results.rows.item(0);
this.setState({petname: row.petname});
}
});
});


/* db.transaction((tx) => {
tx.executeSql('INSERT INTO Users (name) VALUES (:name)', ['oguz']);
});*/


/* 'INSERT INTO table_user (user_name, user_contact, user_address) VALUES (?,?,?)',
[user_name, user_contact, user_address],*/



/* db.transaction((tx) => {
tx.executeSql('INSERT INTO pet (owner, patname) VALUES (?,?)', ['kedicik', 'miyav']);

});*/

/* db.transaction((tx) => {
// tx.executeSql('DROP TABLE IF EXISTS Users', []);
tx.executeSql('CREATE TABLE IF NOT EXISTS Users(user_id INTEGER PRIMARY KEY NOT NULL, name VARCHAR(30))', []);
tx.executeSql('INSERT INTO Users (name) VALUES (:name)', ['Oguz']);

tx.executeSql('SELECT * FROM Users', [], (tx, results) => {

for (var i = 0; i < results.rows.length; i++) {
var row = results.rows.item(0);
this.setState({getvalue: row.name});
console.log('item:' , results.rows.item(i));
}
});
});*/

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir