0

I have a big problem with the command VACUUM to free the memory from delete´s SQL sentences.

Im making a Cordova Android APP, and i know when i use a DELETE SQL sentence the space of the app don't down,... the space persist like a fragment HardDisk.

Then, i see that VACUUM can compact my DB, but i have a problem!

I use SQLite3, and VACUUM in all sites say that can´t execute in a transaction, like this:

var db = window.sqlitePlugin.openDatabase({name:"maintenance", location:'default'});
db.transaction(function (tx) {
   tx.executeSql('VACUUM', [], function (tx, results) {
      alert('done');
 }, function (tx, error) {
      alert('error');
      alert(error.message);
   });
});

Ok, well, then, if i can't do in a transaction, could u tell me how can i execute a vacuum or auto-vacuum or something similar to compact the BD without write a line command? (remember that its a mobile app)

Armando
  • 43
  • 6

1 Answers1

1

According to the GitHub Page, you should be able to execute SQL outside of a transaction with db.executeSql:

db.executeSql("VACUUM", [], function(rs) {
    // ok
}, function(err) {
    // handle error
});
Colonel Thirty Two
  • 23,953
  • 8
  • 45
  • 85
  • Hello, Thanks for the help, i use that out of a transaction. The message "VACUUM DONE" in the ok block is show, but no result. The size of the data of the app its the same after and before of the vacuum. – Armando May 10 '17 at 06:29
  • @Armando How much data are you deleting? SQLite allocates space in multiples of its page size, so if you're deleting only a few rows, it won't free enough space to free a page. – Colonel Thirty Two May 10 '17 at 19:35
  • That's right! I inserted 40000 rows to a bbdd table, my app data size on install is 484KB and with 40k rows is 2.18MB. Then with vacuum low my data size to 500KB. THX Colonel for your help :) – Armando May 11 '17 at 11:40