I am using a pre-populated database and on beta11 was working flawlessly, i would put it on /www folder and it worked with cordova-sqlite-ext plugin.
Now on RC0 i don’t know where i should put the database since /www folder is overriden everytime we run (ionic run android). I already tried to put it on /src folder or /src/assets folder but with no luck.
So does anyone know where to put a sqlite database?
I created an issue and got some replies: https://github.com/driftyco/ionic/issues/8583
See if it helps, i don’t have time to test it this week.
If it works let me know how you did it.
Ok, I think I’ve got some results, I don’t know if everything is ok, but at least I can can connect to a prepopulated database and select some data from a table.
I installed the cordova-sqlite-ext plugin
In app.component.ts I imported “import { SQLite } from 'ionic-native';”
In the platform.ready() I inserted:
let db = new SQLite();
db.openDatabase({
name: “data.db”,
location: “default”,
createFromLocation: 1
}).then(() => {
db.executeSql(“SELECT * from config”, []).then((data) => {
console.log("Data received: ", data);
}, (error) => {
console.error(“Unable to execute sql”, error);
})
}, (error) => {
console.error(“Unable to open database”, error);
});
I create a file called copy.config.js at the same path of package.json and I inserted:
before the last line "description": "SqlProject: An Ionic project".
That’s all for the moment. From the console I can see that it can open the database and receive the data from the config table inside the data.db database that I placed in the src folder.
Of course, all suggestions, improvements and test results are appreciated!
I believe I’ve followed the thread and all of the directions correctly - but I’m still having issues accessing a pre-populated SQLite database. Please let me know if I’ve made a mistake or missed any steps. I have a running Ionic2 application.
Using the SQLite CLI, I opened a database and issued SQL commands to create and populate a table.
I copied the resulting file (OLA.db) to the /www directory off the root of my Ionic2 application.
I added a button the main page of the application and on the click event, I call a function callDatabase(). I included the alert function to avoid ambiguity.
The database loads successfully, but it when I execute the SQL statement, it can’t find the table. I’ve double checked my SQL and it works correctly from the SQLite3 CLI.
When I replaced the SQL select statement with a table creation statement and then an SQL select statement, it works correctly, suggesting that the code is creating a database, populating and accessing it correctly. This rules out issues with the imported classes and libraries. I realize that I by-passed the platform ready check for the purpose of simplicity (by using a button and waiting) but have ruled that out since the create table and select statements work while in the same code structure.
I moved my function into a platform.ready.then method. The result was the same.
I checked the plugins. I noticed I didn’t have the “cordova-plugin-ext 0.10.x” - I had a “cordova-sqlite-storage”, so I attempted to install the missing plug-in and an error occurred - some of the files already existed. To be safe, I uninstalled both of the plug-ins and reinstalled the “cordova-plugin-ext”
I copied a database from another example into my /www directory and was able to return the number of tables in that database successfully.
Can anyone point me to documentation on how to create an SQLite database for mobile use? Is it different than creating a regular SQLite database.
I’ve tried issuing the .open command in the SQLite CLI and also entering sqlite3 from the command line and copying the resulting file over. In both cases, I noticed that the CLI didn’t append the .db onto the file name.
Hi iam getting error my table name is abcd
Unable to execute sql Objectcode: 5message: "sqlite3_prepare_v2 failure: no such table: abcd"proto: Object(anonymous function) @ main.js:93486
error in console build dev failed: Each glob entry must be a string
after that i can able to open db cant able to fetch data from table
getin errr unable to execute sql
message: “sqlite3_prepare_v2 failure: no such table: empdetails”