Select data from SQLite using Ionic Native

I already created database and table. And I inserted some data and try to select data from the table. But I get respond length of data that I’ve inserted but not value from the table.How can I get it??
Here is my code.

this.sqlite.create({
			name: 'yps.db',
			location: 'default'
		})
		.then((db: SQLiteObject) => {
			db.executeSql('select * from auth_data',{})
			.then((data) => {
				console.log(data)
				console.log(data.rows.length);
				var auth = data.rows.item;
				console.log(auth)
			})
			.catch(e => {
				console.log(e);
			})
		})
1 Like

In your then:

for (let i = 0; i < data.rows.length; i++) {
        let item = data.rows.item(i);
        // do something with it

        this.results.push(item);
}
4 Likes

Wow!! It’s work. Thank you very much!!!

when i tried your code got this error can you pls tell what is wrong

ERROR TypeError: Cannot read property ‘then’ of undefined
at LoginPage.push…/src/app/pages/login/login.page.ts.LoginPage.onClickSubmit (login.page.ts:36)
at Object.eval [as handleEvent] (LoginPage.html:13)
at handleEvent (core.js:23097)
at callWithDebugContext (core.js:24167)
at Object.debugHandleEvent [as handleEvent] (core.js:23894)
at dispatchEvent (core.js:20546)
at core.js:22036
at SafeSubscriber.schedulerFn [as _next] (core.js:13517)
at SafeSubscriber.push…/node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:196)
at SafeSubscriber.push…/node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:134)

And my code

this.sqlite.create({
name: ‘prompt_db.db’,
location: ‘default’
}).then((db: SQLiteObject) => {
// tslint:disable-next-line:max-line-length
db.executeSql(‘create table if not exist users(id int(10) primary key,name VARCHAR(32), username varchar(100), password varchar(100), key varchar(300))’, )
.then(() => console.log(‘Executed SQL’))
.catch(e => console.log(e));
})
.catch(e => console.log(e));
}

type or paste code here