Issue encountered while attempting to access data from pre-loaded SQLite database within Ionic application

Whenever I attempt to access information from a pre-populated SQLite database, an error message pops up:

sqlite3_prepare_v2 failure: no such table 'plant'

As far as my knowledge goes, SQLite first searches for the mydb.db file in the /www directory by default. If it fails to locate the pre-populated mydb.db file, it generates an empty database. Consequently, the 'plant' table is not found because the newly created blank database does not include this table. Despite confirming that the database actually exists in the /www folder and contains the 'plant' table when checked using sqlite3 mydb.db followed by .tables in the terminal.

The reason behind its inability to read from the pre-populated mydb.db file remains a mystery to me.

Directory Structure (starting from root):

/src
-/app
--/app.component.ts
/www
-/mydb.db

app.component.ts:

  constructor(public platform: Platform, private sqlite: SQLite ) {
    platform.ready().then(() => {
      this.getData();
    });
  }

  getData() {
    this.sqlite.create({
      name: 'mydb.db',
      location: 'default'
    }).then((db: SQLiteObject) => {
      db.executeSql('SELECT * FROM plant ORDER BY id ASC', [])
      .then(res => {
        // Carry Out Desired Actions
      }).catch(e => console.log("FAIL executeSql:", e));
    })
  }

I've experimented with several suggested solutions from StackOverflow, like uninstalling the app from my device, initiating a new Ionic project, transferring app and configuration files over, and specifying a direct path in the database location. However, the issue persists where it continues attempting to access information from the empty database it creates.

Answer №1

The Cordova-sqlite-storage plugin does not currently support prepopulated databases, so it is recommended to use the Cordova-sqlite-ext plugin instead.

According to the README.md in the repository, there are plans for significant improvements in the upcoming release, including browser platform support using kripken/sql.js and combining cordova-sqlite-storage and cordova-sqlite-ext plugins to eliminate the need for separate versions for pre-populated databases.

It's important to note that these changes are still pending implementation.

For further information and discussions on this topic, there are related threads on the Ionic forum addressing the limitations of Cordova SQLite Storage and suggesting workarounds using the Cordova-sqlite-ext plugin.

Overall, it's advisable to explore alternatives and gather insights from other users who have successfully implemented the Cordova-sqlite-ext plugin in their applications. Additionally, careful consideration should be given to database creation and access issues to ensure smooth functionality of the app.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the proper way to return a Promise within a Javascript async function? Why does the Async function not automatically wrap the returned Promise?

Here is the code I have been working on. My goal is to initiate a task that involves multiple await calls before it actually starts. Once the task is initiated, I need to update the user interface to indicate that the task has begun and is awaiting the res ...

What is the optimal strategy to take when the latest iteration of my application is altering its file reading and writing capabilities?

One of the features in my android app allows users to save their projects, creating a file that stores all necessary variables and fields. I've recently developed an update with additional fields and variables to be saved. However, I realized there ...

Why does Angular throw a length-related error, while I am able to retrieve the length using console log if needed?

It appears that Angular is not receiving the correct data type it expects, yet the lack of errors in the terminal is puzzling. However, the console output states: https://i.stack.imgur.com/1xPsg.jpg If the length property can be detected (highlighted in ...

Extending Enums in Typescript: A Comprehensive Guide

How can you work with a list of constants or Enum? Here is an example: enum MyList { A, B } enum MyList2 { C } function process<T>(input:MyList | T):void { } process<MyList2>(123) // The compiler does not recognize that 123 ...

Utilizing various settings using `.env` files in NodeJs

As I work on building a backend in nodejs, one of the key considerations is how to incorporate an environment configuration into the project. I am envisioning a structure where there is a /config folder housing my envparser.ts (still brainstorming a catchi ...

The issue with compiling Android in Visual Studio Xamarin is due to the absence of packaged resources

I'm currently facing an issue with my Android project in Visual Studio Community Edition 2015 with Xamarin. It seems like the android objects are not being generated in the \obj folder, leading to an error about packaged_resources not existing. A ...

Leverage the TypeScript-generated controller within an Angular directive

I currently have an Angular controller that was generated using TypeScript: class FileManagerController { ... constructor($scope) { $scope.vm = this; ... } ...functions... } Can you guide me on how to integrate this controller i ...

Is it necessary to import the SQLite3 database in Node/Express if all values are null?

Within my server.js file, the code I am using is: const sqlite3 = require('sqlite3').verbose(); const dbfile = "./db/us-census.db"; const db = new sqlite3.Database(dbfile); db.serialize(function () { db.each("SELECT * FROM census_learn_sql LI ...

Is there a way for me to manually manipulate the advancement of the progress bar from @ngx-progressbar/core in Angular5/Ionic4?

I've been working on implementing a progress bar into my application using the @ngx-progressbar/core library. However, I'm facing an issue where I can't seem to control its progress effectively. Whenever I try to increase the progress increm ...

Vercel - Deploying without the need to promote the project

How can I deploy my Nextjs app to production in a way that allows me to run E2E tests on a "pre-prod" version before promoting it to prod, similar to using a preview URL without public traffic being directed there? I am looking for a process where I can v ...

Is the Glide Image request feature able to first check the cache before initiating the download process?

I have a request set up like this, but I am curious to know if the downloadOnly method first checks the cache for the image? FutureTarget<File> future = Glide.with(applicationContext) .load(yourUrl) .downloadOnly(500, 500); File cacheFile = ...

Tips for declaring an array of Mongoose ObjectIDs in TypeScript

I'm encountering an issue with typing in TypeScript when working with mongoose schemas. Here is the model I have for a user : export interface IUser extends mongoose.Document { firstname: string; lastname: string; email: string; passwo ...

ViewModelProvider - Fragment type not compatible

I recently encountered an issue with my Android program. I used Android Studio to create a Bottom Navigation View Activity, which was working fine in the IDE. However, when I tried running it on an actual mobile device, it stopped working and displayed the ...

The lowermost button is missing from my layout, causing the entire design to be incomplete

Using a relative layout, I aimed to create a design resembling image one. However, on certain phones (see image 2), the bottom button gets cropped and the entire layout isn't visible. Shouldn't a relative layout adjust itself based on the device ...

Deactivate button function upon clicking embedded material icon

Within a button in my Angular application, I have a mat-icon with its own defined event. The issue is that when I click on the mat-icon, both its event and the button's event are fired because the mat-icon is nested inside the button tag. I want to pr ...

Angular: Trigger service call upon onBlur event of input changes

In Angular, I am looking to detect any changes in the text input during the onBlur event and then take specific actions accordingly: Criteria for processing during the onBlur event: Only proceed if there has been a change in the text input. If the input ...

Here is a unique version: "Dealing with Node.js ES6 (ESM) Modules in TypeScript can be tricky, especially when the TypeScript Compiler (TSC) fails to emit the

I am facing an issue while transpiling my TypeScript project to JavaScript. I have set the project to resolve as an ES6 Module (ESM) by using the "module":"ES6" configuration, but the problem persists. This is the current setup in my ...

Next.js is refusing to render an array of HTML elements

Consider this scenario where I have a block of code in TypeScript that attempts to create and display a list of elements. Here is a sample implementation: const MenuList = ():ReactElement => { const router = useRouter(), liElements:any = []; con ...

Optimal method for accessing params and queryParams in Angular 2

Seeking insights on how to craft a route with information stored in its URL parameters. Here's an example of my route (app.routes.ts): {path: 'results/:id', component: MyResultsComponent}, How I navigate to the route : goToResultsPage(qu ...

Error encountered when using object literals in React with Typescript

I am facing an issue with a component that is supposed to render a row of data with a delete button for each row. When the delete button is clicked, it should update the state by filtering out the clicked row. However, I am encountering an error despite ge ...