an-rahulpandey / cordova-plugin-dbcopy

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

specifying location in db.copy #44

Closed anilkunchalaece closed 7 years ago

anilkunchalaece commented 7 years ago

When i tried the following

        window.plugins.sqlDB.copy("demo.db.sqlite",0,function() {
            console.log("db read")
            db = $cordovaSQLite.openDB({name : 'demo.db.sqlite',location : 'default'});
        }, function(error) {
            console.log("error in copy db")
            db = $cordovaSQLite.openDB("demo.db");
        })

It is giving me following error dbcopyissue

i think i am specifying the location.. isn't it ? Or am i doing anything wrong ?

an-rahulpandey commented 7 years ago

Can you paste the log from Xcode? or do this in error function console -

console.log("error in copy db", error)

anilkunchalaece commented 7 years ago
INSTALL SUCCESS

LAUNCH SUCCESS

0     178269   log      error in copy db, DB Already Exists
1     178271   log      Error in Error callbackId: sqlDB368979961 : Error: Database location or iosDatabaseLocation setting is now mandatory in openDatabase call.
JS changed:   www/js/app.js
JS changed:   www/js/app.js
0     182186   log      error in copy db, DB Already Exists

i am using ionic run command.

anilkunchalaece commented 7 years ago

Hi, Problem is in line db = $cordovaSQLite.openDB("demo.db");

thanks for quick reply

an-rahulpandey commented 7 years ago

Like the error says you have to pass databaselocation or iOSDatabaseLocation paramter while opening the db. For. e.g

$cordovaSQLite.openDB({name : 'demo.db.sqlite',location : 'default'});

location depends on where you copied the db.

anilkunchalaece commented 7 years ago

Hi, i am not getting any tables from the data base, where am i doing wrong ?

` window.plugins.sqlDB.copy("demo.db",0,function() {
            console.log("db read")
            db = $cordovaSQLite.openDB({name : 'demo.db',location : 'default'});
        }, function(error) {
            console.log("error in copy db",error.message)
            db = $cordovaSQLite.openDB({name: "demo.db",location: 'default'})
        })`

and in controller

` $scope.showTables = function(){
      console.log("show table")
      $cordovaSQLite.execute(db,"SELECT name FROM sqlite_temp_master WHERE type=?",['table']).then(function(res){
        console.log("tables"+res.rows.length)
      }),function(err){
        console.log('error in reading tables'+err)
      }
    }

})`

in assests folder the db is copying and have the tables

an-rahulpandey commented 7 years ago

Remove the old db and recopy it. I think there might something wrong with the database or query. Use this to check sqlite database - http://sqlitebrowser.org/

anilkunchalaece commented 7 years ago

dbcheck

it is showing file. for reading the data i am using this, it's also giving me nothing


          $scope.loadDb = function(){
            console.log("values reading from db");
            $scope.val = [];
            $cordovaSQLite.execute(db, "SELECT * FROM example").then(function(res) {
                console.log(res.rows.length);
                for (var i = 0; i < res.rows.length; i++) {
                    $scope.val.push(res.rows.item(i).firstname)
                    //console.log('added' + res.rows.item(i).firstname)
                }

            }),function(err){
                console.log('error'+err.message)
            }
 //       })
    }
an-rahulpandey commented 7 years ago

Have you deleted the old app and installed new app? Also what is the error message in $cordovaSQLite.execute function?

anilkunchalaece commented 7 years ago

i uninstalled and run the emulator. now it is working. Thankyou so much for your quick replys.. btw what is the problem ?

an-rahulpandey commented 7 years ago

It might be database location problem which was copied somewhere else. Sqlite Plugin would have created a new blank database.