title: Working with Cordova Sqlite plugin in ionic 2
body: <p>I'm new to ionic 2 development (haven't worked with ionic-1 either).</p>
  
  <p>I'm trying to use cordova sqlite plugin in the application. I followed <a href="https://www.thepolyglotdeveloper.com/2015/12/use-sqlite-in-ionic-2-instead-of-local-storage/" rel="nofollow">Use SQLite in Ionic 2</a> link. Was able to add the plugin into to project using following command. </p>
  
  <blockquote>
    <p>$ ionic plugin add cordova-sqlite-storage</p>
  </blockquote>
  
  <p>After deploying the app on real device data.db was created and opened and also the <code>people</code>table was created successfully. 
  Following is the log from the Xcode :</p>
  
  <blockquote>
    <p>2016-10-17 16:29:16.435992 SqlProject[238:3982] -[SQLitePlugin pluginInitialize] [Line 67] no cloud sync at path: /var/mobile/Containers/Data/Application/DFDADD59-D48E-4D4C-B8F0-23EEDE169471/Library/LocalDatabase
    2016-10-17 16:29:16.436138 SqlProject[238:4034] -[SQLitePlugin openNow:] [Line 137] open full db path: /var/mobile/Containers/Data/Application/DFDADD59-D48E-4D4C-B8F0-23EEDE169471/Library/LocalDatabase/data.db
    2016-10-17 16:29:16.443765 SqlProject[238:4034] -[SQLitePlugin openNow:] [Line 163] Good news: SQLite is thread safe!
    2016-10-17 16:29:16.448487 SqlProject[238:3982] <strong>OPEN database: data.db - OK</strong>
    2016-10-17 16:29:16.463667 SqlProject[238:3982] <strong>TABLE CREATED:</strong>  [object Object]</p>
  </blockquote>
  
  <p><strong>Code for Opening Database:</strong></p>
  
  <blockquote>
    <p>import { SQLite } from 'ionic-native';</p>
  </blockquote>
  
  <pre><code> constructor(platform: Platform) {
     platform.ready().then(() =&gt; {
     StatusBar.styleDefault();
  
     let database = new SQLite();
          database.openDatabase({
              name: "data.db",
              location: "default"
          }).then(() =&gt; {
              database.executeSql("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY AUTOINCREMENT, firstname TEXT, lastname TEXT)", {}).then((data) =&gt; {
                  console.log("TABLE CREATED: ", data);
  
              }, (error) =&gt; {
                  console.error("Unable to create table", error);
  
              })
          }, (error) =&gt; {
  
              console.error("Unable to open database", error);
          });
     });
  }
  </code></pre>
  
  <p>But, now I'm getting error while <strong>Inserting</strong> and <strong>Fetching</strong> the records from the db.</p>
  
  <pre><code> public add() {
  
   console.log("Inside the add function- ");
  
   this.database.executeSql("INSERT INTO people (firstname, lastname) VALUES (?, ?)", ['mahesh', 'bhalerao']).then((data) =&gt; {
  
     console.log("INSERTED: " + JSON.stringify(data));
  
   }, (error) =&gt; {
     console.log("ERROR: " + JSON);
   });
  }
  
   public fetchRecords() {
  
      this.database.executeSql("SELECT * FROM people", []).then((data) =&gt; {
                 alert("executeSql refresh function success");
  
          this.people = [];
  
          if(data.rows.length &gt; 0) {
              for(var i = 0; i &lt; data.rows.length; i++) {
                  this.people.push({firstname: data.rows.item(i).firstname, lastname: data.rows.item(i).lastname});
              }
          }
      }, (error) =&gt; {
          console.log("ERROR: " + JSON.stringify(error.err));
      });
  }
  </code></pre>
  
  <p>I'm getting undefined error.</p>
  
  <blockquote>
    <p>ERROR: undefined</p>
  </blockquote>
  
  <p>Not sure what's going wrong.</p>
  
  <p>Any help would be appreciated.
  Thanks!</p>