# Open existing DB

**URL:** <https://forum.ionicframework.com/t/open-existing-db/190169>\
**Category:** ionic-v3\
**Created:** [May 27, 2020, 6:16am UTC](https://forum.ionicframework.com/t/open-existing-db/190169 "2020-05-27T06:16:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fimenez](https://avatars.discourse-cdn.com/v4/letter/f/f19dbf/32.png) [@fimenez](https://forum.ionicframework.com/u/fimenez)\
**Post date:** [May 27, 2020, 6:16am UTC](https://forum.ionicframework.com/t/open-existing-db/190169/1 "2020-05-27T06:16:26Z")

</div>

Hello, I’m novice in IONIC.

I’m trying open existing DB (SQLite) with a table and this table is populated with data.  
I copy my DB into \*_www\*_ folder directory of Windows10

My code:

this.sqlite.create({  
name: ‘Keeper.db3’,  
location: ‘default’,

DB is opened correctly (i have log) but there’s no data retrievend because rows.lenght returned is not greater than 0.

My Code:

str1: String;  
let str1 = “select \* from users”;  
db.executeSql(str1, ).then(res =\> {  
if (res.rows.lenght \> 0)  
{  
alert(“there are rows”);  
}  
else  
{  
alert(“there aren’t rows”);  
}

Can you help me?

---

<div class="post-metadata">

**Author:** ![alexmigwi](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/alexmigwi/32/125888_2.png) [@alexmigwi](https://forum.ionicframework.com/u/alexmigwi)\
**Post date:** [May 27, 2020, 9:59pm UTC](https://forum.ionicframework.com/t/open-existing-db/190169/2 "2020-05-27T21:59:52Z")

</div>

Check your code for typos…  
On the if it should be … res.rows.length

---

<div class="post-metadata">

**Author:** ![fimenez](https://avatars.discourse-cdn.com/v4/letter/f/f19dbf/32.png) [@fimenez](https://forum.ionicframework.com/u/fimenez)\
**Post date:** [May 29, 2020, 6:39pm UTC](https://forum.ionicframework.com/t/open-existing-db/190169/3 "2020-05-29T18:39:10Z")

</div>

It doesn 't work.  
i’ve read that i need sqlite-cordova-ext plugin to acces to pre-populated Dbs.  
is it right?

thnks

---

<div class="post-metadata">

**Author:** ![alexmigwi](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/alexmigwi/32/125888_2.png) [@alexmigwi](https://forum.ionicframework.com/u/alexmigwi)\
**Post date:** [May 30, 2020, 11:38am UTC](https://forum.ionicframework.com/t/open-existing-db/190169/4 "2020-05-30T11:38:08Z")

</div>

from the plugin docs on ionic

1. Add plugin to your project

```auto
ionic cordova plugin add cordova-sqlite-storage
npm install @ionic-native/sqlite

```

1. In the file you want to use the DB plugin maybe a dataservice.ts that provides data to the app file for example

```auto
import { SQLite, SQLiteObject } from '@ionic-native/sqlite/ngx';

constructor(private sqlite: SQLite) { }

...

// How to create a db or open
// create(config) Opens or creates a SQLite database file.
this.sqlite.create({
  name: 'data.db',
  location: 'default'
})
  .then((db: SQLiteObject) => {

    db.executeSql('create table danceMoves(name VARCHAR(32))', [])
      .then(() => console.log('Executed SQL'))
      .catch(e => console.log(e));

  })
  .catch(e => console.log(e));

// Add CRUD functions and other functionalities you may need

addData(){
// Implementation
...
}

readData(){
// Implementation
...
}

updateData(){
// Implementation
...
}

deleteData(){
// Implementation
...
}
...

```

Read through this tute (though it says ionic3) and you’ll have a general roadmap as to what you can do…  
[Ionic 3, Angular 4 and SQLite CRUD Offline Mobile App](https://www.djamware.com/post/59c53a1280aca768e4d2b143/ionic-3-angular-4-and-sqlite-crud-offline-mobile-app)

---

<div class="post-metadata">

**Author:** ![alexmigwi](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/alexmigwi/32/125888_2.png) [@alexmigwi](https://forum.ionicframework.com/u/alexmigwi)\
**Post date:** [May 30, 2020, 11:41am UTC](https://forum.ionicframework.com/t/open-existing-db/190169/5 "2020-05-30T11:41:31Z")

</div>

Post your code from your file…
