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

how to use this plugin? #2

Closed sangariv closed 10 years ago

sangariv commented 10 years ago

Hi Can you guide me to use this plugin in commandline ? window.plugins is always undefined to me.

an-rahulpandey commented 10 years ago

How did you add the plugin and what platform are you using. What is the exact error message, does it showing window.plugins.sqlDB undefined?

sangariv commented 10 years ago

hi, i have copied the databasehelper.java and sqldb.java under src folder of my project. Then added the sqldb.js inside www folder. Then added my demo.sqlite file under assets directory. and called in javscript as you said . function dbcopy() { window.plugins.sqlDB.copy("demo",copysuccess,copyerror); }

an-rahulpandey commented 10 years ago

Do not add the plugin manually, please add the plugin using the Cordova CLI -

cordova plugin add https://github.com/an-rahulpandey/cordova-plugin-dbcopy.git

sangariv commented 10 years ago

ok let me add using this.Thankyou

sangariv commented 10 years ago

Hi, i my sample database name is test.sqlite have defined like this var db = window.plugins.sqlDB.copy("test",copysuccess,copyerror); alert(db); but i get it as "undefined" please guide me where i am wrong.

an-rahulpandey commented 10 years ago

Use the demo code as shown in the read me, call the dbcopy function and put the console.log or alert in the copysuccess method. If you are using any IDE, you can check for error in their log section.

sangariv commented 10 years ago

HI, I am having my "test.sqlite" inside assets directory and trying to call like below.still i get alert as copy error. document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
 alert("onDeviceReady");
  var db =   window.plugins.sqlDB.copy("test",copysuccess,copyerror);
  alert(db);

}

function copysuccess() { alert("copysuccess");

}

function copyerror() { alert("copyerror");

}

an-rahulpandey commented 10 years ago

First delete your existing app from the device, then compile and run the new app with this change

var db = window.plugins.sqlDB.copy("test.sqlite",copysuccess,copyerror);

Also if you are using eclipse, check the Logcat. I have not removed the logging from the current code, it will also give you the exact error message.

One more thing, it goes to copy error method - 1) When there is a problem while copying the database. 2) When the database already exists in the current location.

You can use following method to know the exact issue -

function copyerror(e) { alert(JSON.stringify(e)); }

sangariv commented 10 years ago

Hi, Just now i got into copy success function i just changed the line var db = window.plugins.sqlDB.copy("test.sqlite",copysuccess,copyerror); into var db = window.plugins.sqlDB.copy("test.db",copysuccess,copyerror);

Thanks

sangariv commented 10 years ago

HI, select query inside copy success always returns "no table found".below is my code document.addEventListener("deviceready", onDeviceReady, false);

var db function onDeviceReady() { alert("onDeviceReady"); window.plugins.sqlDB.copy("Databases.db",copysuccess,copyerror);

}

function copysuccess() { alert("copysuccess"); db = window.openDatabase("Databases", "1.0", "Test DB", 1000000);

db.transaction(queryDB, errorCB);

}

function copyerror() { alert("copyerror"); //db.transaction(queryDB, errorCB);

}

function queryDB(tx) {

alert("started");

tx.executeSql("select id from halal_product",[],renderEntries,errorCB);

}
function renderEntries(tx,results){
 alert("res.rows.length: " + results.rows.length);
}
function errorCB(err) {
  alert("Error processing SQL : "+err.message);
}
an-rahulpandey commented 10 years ago

You have to use SQLite Plugin - https://github.com/brodysoft/Cordova-SQLitePlugin

sangariv commented 10 years ago

yes i have used it alerady but it says no table found

an-rahulpandey commented 10 years ago

Run the code in simulator and then copy the db from the data directory. Open the downloaded db in Sqlitebrowser and check if everything is proper or not.

sangariv commented 10 years ago

HI, if i give the path like this db = window.sqlitePlugin.openDatabase('/data/data/com.qr.app/databases/qrapp.db',"1.0", "qr", 1000000); it opens correctly.

an-rahulpandey commented 10 years ago

var db = window.sqlitePlugin.openDatabase("Databases.db", "1.0", "Test DB", -1);

In your previous code there was no .db extension.

blattmann commented 8 years ago

I have also the problem that I am not able to talk to my sqlite db on an iphone. In xcode I have this warning:

warning: no rule to process file '/Library/WebServer/Documents/rcs/dev/platforms/ios/Myapp/Plugins/me.rahul.plugins.sqlDB/sqlDB.h' of type sourcecode.c.h for architecture arm64

In the debug console I receive this:

I have no problems on Android!

I created also an issue on Stackoverflow with more info regarding my code: http://stackoverflow.com/q/36705044/2425177

Any ideas?

an-rahulpandey commented 8 years ago

See #25

IoTFusion commented 8 years ago

Can you help me? I added the sqlDB plugin using cordova, but still having call to unknown plugin: sqlDB error.

an-rahulpandey commented 8 years ago

@IoTFusion Try building your project with Cordova CLI.

milanifour commented 7 years ago

when db copy it crash app.

an-rahulpandey commented 7 years ago

Hi,

Make sure db file is present inside the www folder.

milanifour commented 7 years ago

my db present in www folder of cordova-plugin-dbcopy basically my database copied but not whole database. my database size is 25 MB and when copy just start and reach to just 12 KB my app crashed. it's says like "unfortunatley , your app closed".

i am using Telerik app builder and my code as below my code:

window.plugins.sqlDB.copy("mydb",null, function (error) { alert(JSON.stringify(error)); console.log(JSON.stringify(error));

    });

also i tried

window.plugins.sqlDB.copy("mydb",0,null, function (error) { alert(JSON.stringify(error)); console.log(JSON.stringify(error));

    });
an-rahulpandey commented 7 years ago

@milanifour Can you debug using Android Monitor located inside android sdk tools directory - https://developer.android.com/studio/profile/monitor.html