an-rahulpandey / cordova-plugin-dbcopy

Copy SQLite Database from www folder to default app database location
Apache License 2.0
89 stars 48 forks source link

Error callback when all is ok #23

Closed juanluisrodriguez closed 8 years ago

juanluisrodriguez commented 8 years ago

I have this code

window.plugins.sqlDB.copy("test.db", function() {
      console.log('OK');
    }, function(error) {
      console.error("There was an error copying the database: " + error);
    });

When i put a wrong database (test2.db for example) I have nothing. but when all is ok, i have:

error There was an error copying the database: File Copied

I use the ios emulator with ionic.

any idea?

an-rahulpandey commented 8 years ago

Where are you putting the database, is it located inside the www folder and the file has an extension which you are providing in the plugin call? Can you provide some more information like is it specific to some iOS version or SDK version?

juanluisrodriguez commented 8 years ago

Yes, the database is 'test.db' and is in the www folder. I try it in iphone-6 simulator with ios 9.2 It is with ionic

With:

angular.module('starter', ['ionic', 'ngCordova'])
  .run(function($ionicPlatform,$cordovaSQLite) {
    $ionicPlatform.ready(function() {

      window.plugins.sqlDB.copy("test.db", function() {
        console.log('Copy');
        db = $cordovaSQLite.openDB("test.db");
      }, function(error) {
        console.error("There was an error copying the database: " + error);
        db = $cordovaSQLite.openDB("test.db");

      });

    });
  })

I dont have logs messages and the db isnt open

WIth:

.run(function($ionicPlatform,$cordovaSQLite) {
    $ionicPlatform.ready(function() {
      window.plugins.sqlDB.remove("test.db", function() {
        console.log('remove ok');
      }, function() {
        console.log('error remove');
      });

      window.plugins.sqlDB.copy("test.db", function() {
        console.log('Copy');
        db = $cordovaSQLite.openDB("test.db");
      }, function(error) {
        console.error("There was an error copying the database: " + error);
        db = $cordovaSQLite.openDB("test.db");

      });

    });
  })

I have logs: 0 126943 log error remove 1 126985 error There was an error copying the database: File Copied 2 126986 log OPEN database: test.db 3 126989 log DB opened: test.db

And test.db have my database with my tables

When I have more time I'll do more tests and will analize the source code. If I 'm the only one it is probably my fault

felipeblan commented 8 years ago

You are not the only one the plugin was working just fine. But today I was making a few tests and i am having the same issue no idea what is happenig i am jus going to create my tables by hand.

an-rahulpandey commented 8 years ago

@aprendizenlared What is the cordova version are you using and if possible can you attach the sample database which you are using?

an-rahulpandey commented 8 years ago

@aprendizenlared @felipeblan I just realize you are not passing the location parameter, please pass the second argument to the plugin. For e.g like this

window.plugins.sqlDB.copy("test.db", 0, function() {
      console.log('OK');
    }, function(error) {
      console.error("There was an error copying the database: " + error);
    });

See the Read Me file for required location value.

felipeblan commented 8 years ago

You are right thanks for your answer. The thing is that I wasnt putting the locacion value and it worked like that the first time. Thank you.

juanluisrodriguez commented 8 years ago

No comments :S

Sorry, this is ok.

Copy and paste but may delete the second parameter unintentionally :S Sorry

an-rahulpandey commented 8 years ago

@aprendizenlared So putting a location worked for you?

juanluisrodriguez commented 8 years ago

Yes, now it works

QuickInsure commented 8 years ago

I have given the location but still facing the same problem.

I am using GenyMotion android emulator.

window.plugins.sqlDB.copy("populated.sqlite.db",0, function() { db = $cordovaSQLite.openDB({name:"populated.sqlite.db", iosDatabaseLocation: 'default'}); }, function(error) { console.error("There was an error copying the database: " + error); db = $cordovaSQLite.openDB({name:"populated.sqlite.db", iosDatabaseLocation: 'default'}); });

Please help.

Thank You

an-rahulpandey commented 8 years ago

@QuickInsure What is the Android version?