Git Product home page Git Product logo

Comments (22)

jepiqueau avatar jepiqueau commented on June 12, 2024

@GuillaumeUnice On Android in which location were the cordova databases. Can you share the part of the code where you do the database conversion

from sqlite.

GuillaumeUnice avatar GuillaumeUnice commented on June 12, 2024

So the location paths is correctly inside 'databases/' directory
More accuratly: "/data/data/myappname.app/databases/MYDATABASENAMESQLite.db"

I basically copy past the example of your ionic7-angular-sqlite part 1 here and here tutorial great one by the way.

And to test the database copy I just add inside the SQLiteService initializePlugin method the execution of moveDatabasesAndAddSuffix or addSQLiteSuffix

The code becoming

  async initializePlugin(): Promise<boolean> {
    console.log("initializePlugin");
    Capacitor.Plugins.
    this.platform = Capacitor.getPlatform();
    if (this.platform === "ios" || this.platform === "android") this.native = true;
    this.sqlitePlugin = CapacitorSQLite;
    this.sqliteConnection = new SQLiteConnection(this.sqlitePlugin);
    await this.sqliteConnection.moveDatabasesAndAddSuffix();
    this.isService = true;
    return true;
  }

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@GuillaumeUnice Have you read the doc MigratingCordovaDatabases.

from sqlite.

GuillaumeUnice avatar GuillaumeUnice commented on June 12, 2024

Yes sure of course why? does it make no sense to call the function here?

Because the database with suffix is correctly create but not hydratate.
And again if I copy paste manually by adding the suffix and extension everything work.

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@GuillaumeUnice the doc said addSQLiteSuffix and not moveDatabasesAndAddSuffix

from sqlite.

GuillaumeUnice avatar GuillaumeUnice commented on June 12, 2024

Yes yes I start first with addSQLiteSuffix and no parameter inside because the cordova plugin was default as mentionned into the documentation you forward

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@GuillaumeUnice I got the issue identified so i do some more testing and it will be fixed in the next release. Sorry for the inconvenience

from sqlite.

GuillaumeUnice avatar GuillaumeUnice commented on June 12, 2024

Oh great! Let me know whether you need further information or any help around it ;)

You can't ever know how helpful such feature will help on my project.

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@GuillaumeUnice this may take some time as after installing the latest release of Android Studio and the API 34, i cannot make a build and i could not find the reason nothing to do with my code so be patient

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@GuillaumeUnice an you test the new release and tell me if it works as i still cannot test it myself

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@GuillaumeUnice i finally succeed to test it so i close the issue

from sqlite.

GuillaumeUnice avatar GuillaumeUnice commented on June 12, 2024

Sorry I test it only now and it still doesn't copy the data from the original database to the new one.

I check your code you just modify the case whether no "default" was pass down. But it wasn't the problem I encounter because it already was able to create the database with SQLite.db extension but not data was copy from the original one.

I do not have great knowledge in Java but I found the call of addSQLiteSuffix in fine execute copyFileFromFile and I guess it's somewhere here that it doesnt copy it properly.

But I guess you are not able to reproduce?

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@GuillaumeUnice i test this:

export class TestIssue497 implements OnInit {
  log: string = "";
  platform: string;
  handlerPermissions: any;
  initPlugin: boolean = false;

  constructor(private _sqlite: SQLiteService) {
    this.platform = this._sqlite.platform;
  }

  async ngOnInit() {
    const showAlert = async (message: string) => {
      await Dialog.alert({
        title: 'Error Dialog',
        message: message,
      });
    };
    try {
      await this.runTest();
      document.querySelector('.sql-allsuccess').classList
        .remove('display');
      console.log("$$$ runTest was successful");
    } catch (err) {
      document.querySelector('.sql-allfailure').classList
        .remove('display');
      console.log(`$$$ runTest failed ${err.message}`);
      await showAlert(err.message);
    }
  }


  async runTest(): Promise<void> {
    this.log += "* Starting testissue497 *\n";

    // test get the Database List in the
    let result = await this._sqlite.getDatabaseList();
    console.log(`test get Database List: ${JSON.stringify(result)}`)
    const nInitDbs = result.values.length;
    console.log(`$$$ nInitDbs: ${nInitDbs}`);
    
    // Cordova databases in the default folder
    const dbMigratableList = await this._sqlite.getMigratableDbList();
    console.log(`dbMigratableList ${JSON.stringify(dbMigratableList)}`)
    const nInitMgDbs = dbMigratableList.values.length;
    if(nInitMgDbs !== 1) {
      return Promise.reject(new Error("GetMigratableDbList from default failed"));
    }
    await this._sqlite.addSQLiteSuffix();
    result = await this._sqlite.getDatabaseList();
    console.log(`$$$ result.values.length: ${result.values.length}`);
    console.log(`$$$ nInitDbs + 1 : ${(nInitDbs + 1)}`);

    if( result.values.length !== (nInitDbs + 1)){
      return Promise.reject(new Error("AddSQLite from default failed"));
    }

    // Cordova databases in another folder
    const directory: string = this.platform === "ios" ? "Applications/Files/Databases" : "files/databases" ;
    const dbMigratableList1 = await this._sqlite.getMigratableDbList(directory);
    console.log(`dbMigratableList1 ${JSON.stringify(dbMigratableList1)}`)
    const nMgDbs = dbMigratableList1.values.length;
    if(nMgDbs !== 3) {
      return Promise.reject(new Error("GetMigratableDbList failed"));
    }
    await this._sqlite.addSQLiteSuffix(directory, dbMigratableList1.values);
    result = await this._sqlite.getDatabaseList();
    if( result.values.length !== (nInitDbs + 4)){
      return Promise.reject(new Error("AddSQLite final failed"));
    }
    if (this.platform === "ios") {
      // test with folder Library/CapacitorDatabase
      const lcdir = "Library/CapacitorDatabase";
      const dbMigratableList2 = await this._sqlite.getMigratableDbList(lcdir);
      console.log(`dbMigratableList2 ${JSON.stringify(dbMigratableList2)}`)
      const nLCMgDbs = dbMigratableList2.values.length;
      if(nLCMgDbs !== 1) {
        return Promise.reject(new Error("GetMigratableDbList2 failed"));
      }
      await this._sqlite.addSQLiteSuffix(lcdir, dbMigratableList2.values);
      result = await this._sqlite.getDatabaseList();
      if( result.values.length !== (nInitDbs + 5)){
        return Promise.reject(new Error("AddSQLite final ios failed"));
      }
      }
    this.log += "* Ending testissue497 *\n";
  }


}

i had initially
image

so i want to migrate testcopy.db from the default folder and keep1.db, testfromfile.db,WOP_DATABASE.db from the files/databases folder

and after running the code

image

this is why i said it is fixed
You may still have to delete the cordova databases

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@GuillaumeUnice you can see that the size of the db are correct
image

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@GuillaumeUnice Do your file got an extension .db ?

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@GuillaumeUnice I also made a test by removing the extension of the keep1 database and it still work

image

So i do not know what to do more. May be you can debug your app and but some break points

  • in UtilsFile line 255 copyFileFromFile(fromFile, toFile);
  • in UtilsFile line 379 if (!destFile.getParentFile().exists()) {

and then Run -> Debug 'app' and do step by step and tell me what is going on

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@GuillaumeUnice i thought it may be due to the size of the database so i created a 20Mb database and make the test and it is still running
image

So now i am waiting the result of your debug

from sqlite.

GuillaumeUnice avatar GuillaumeUnice commented on June 12, 2024

Wow thank you so much for all the tests.
So the problem is related to the .db extension as you mentionned.

But it's when it's located on /databases directory not /files one and that where it cordova plugin create the database.
When I add manually the extension all the data are correctly copy when I remove it doesn't work anymore

Could you test that on your side by doing exactly what you do on your last test but instead of keep1 database doing it on large.db without .db extension?

from sqlite.

GuillaumeUnice avatar GuillaumeUnice commented on June 12, 2024

@jepiqueau Could you be able to retest the scenario on large.db? Or you are not in capacity to perform it anymore?

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@GuillaumeUnice i did it and it works too.

Initial State

Test_issue#497_init

Final State

Test_issue#497_final

Sorry for the lateness
So there is nothing i can do more

from sqlite.

jepiqueau avatar jepiqueau commented on June 12, 2024

@GuillaumeUnice As you do not comment i assume it is fixed so i close the issue

from sqlite.

GuillaumeUnice avatar GuillaumeUnice commented on June 12, 2024

Hi @jepiqueau thanks for your help!

I got something working now and perhaps I wasn't understand properly last time. Because I take your test in consideration and when miming the directory path I obtain an error not found throw:

    const directory: string = this.platform === "ios" ? "Applications/Files/Databases" : "files/databases" ;

Nevertheless without specifying the path it works so with the following code:

const dbMigratableList1 = await this.sqliteConnection.getMigratableDbList();
console.log(`dbMigratableList1 ${JSON.stringify(dbMigratableList1)}`);

await this.sqliteConnection.addSQLiteSuffix(null, dbMigratableList1.values); // here null pass down

So I found a bit strange the lib doesnt work whether I do not pass down dbNameList but perhaps it's logical after all. And it create the empty database only.

So thanks for your help the ticket can be closed now indeed ;)

from sqlite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.