Unable to add data to sqlite database

Currently in the process of learning Ionic and programming in general. Recently came across a resource online that helped me create a table with the required data, but struggling to insert new data into it. Any assistance would be greatly appreciated!

Following this tutorial: ionic-sqlite

My code:

getRegiao() {                  // Regions // 
return new Promise<Regiao[]>((resolve, reject) => {
  let sql = "SELECT NOM_REGIAO, ID " +
    "FROM TB_REGIAO  "


  this.executeQuery(sql).then(data => {
    let regioes = [];
    if (data != undefined)
      data.forEach(function (row) {
        let regiao: Regiao = { nom_regiao: row[0], id: row[1] }
        regioes.push(regiao);
      });
    resolve(regioes);

  }).catch(error => {
    console.log(error);
  });

});

}

 addUser() {

let sql = "INSERT INTO TB_USUARIO (EMAIL) VALUES ('<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="41030d08150213000f0a01090e150c00080d6f020e0c">[email protected]</a>')";
// let sql = "SELECT EMAIL FROM TB_USUARIO";
this.executeQuery(sql);
}

executeQuery(sql: string) {
let db: any;
return new Promise<any>((resolve, reject) => {
  let xhr = new XMLHttpRequest();
  xhr.open('GET', this.dbName, true);
  xhr.responseType = 'arraybuffer';

  xhr.onload = (e) => {
    let uInt8Array = new Uint8Array(xhr.response);
    db = new SQL.Database(uInt8Array);
    let contents = db.exec(sql);
    console.log(contents);
    if (contents.length > 0)
      resolve(contents[0].values);
    else 
      resolve("query executed successfully without return")
  };
  xhr.send();

});
}

Answer №1

Make sure to utilize this specific plugin, which is the one I am currently utilizing.

Remember to execute SQL commands in this manner:

db.executeSql('create table danceMoves(name VARCHAR(32))', {})

Instead of using an object '{}', consider using an array '[]' like this:

db.executeSql('create table danceMoves(name VARCHAR(32))', [])

I am confused as to why they switched from using objects to arrays; it seems like there may have been a mistake in updating the documentation.

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

Using Selenium WebDriver with JavaScript: Handling Mouse Events (mouseover, click, keyup) in Selenium WebDriver

I am currently working on integrating Selenium testing for mouse events with dynamically generated elements. Specifically, I am attempting to trigger a "mouseover" event on an element and then interact with some icons within it. However, I have encountere ...

Utilizing Angular to Transform an Array of Dates

I have an array of dates which returns: [Mon Aug 03 2020 00:00:00 GMT+0100 (British Summer Time), Wed Aug 05 2020 00:00:00 GMT+0100 (British Summer Time)] I am looking to convert these into the following format: ["2020-02-13T02:39:51.054", &quo ...

What is the difference between a Typescript object containing generic keys and regular keys?

My current TypeScript type definition is as follows: type MyKeys = 'foo' | 'bar' | 'baz' I am looking to create a custom type that includes keys from MyKeys, but also additional keys, like so: type CustomType = { [key in ...

The specific function type 'number' cannot be assigned to type 'U'

When I encounter this issue, U is defined as a number and should be returning the number as well. The error message reads: Type 'number' is not assignable to type 'U'. function foo<T extends string, U extends number>(a: T): U { ...

Encountering a fatal error while trying to load a skin from a .json file in LibGdx

Recently I encountered an issue while using Intellij. Previously, everything was running smoothly, and the APK deployed on my Android device without any problems. However, now it seems to get stuck on a black screen and then returns to the home screen with ...

When the screen is rotated, the onSaveInstanceState() function may not function as expected

I seem to have encountered an issue with my code. It appears to be correct, however, the onSaveInstanceState() method is not functioning as expected when the screen is rotated. The data does not save after the activity is destroyed (onDestroy() worked fi ...

Creating a jar file for a project that relies on another project: A step-by-step guide

I have been working on a project using C# (Unity) to call a java function in a jar file. Here is the structure of my class: Class A{ auth(){ } share(){ StatusesAPI mStatusesAPI; mStatusesAPI.upload("hey", bitmap, null, null, mListener); ...

Encountering "Invalid hook call" error with React Router while integrating Higher Order Components for authentication

Dealing with an error: React Router shows "Invalid hook call" with higher-order components for authentication Dilemma I have developed two distinct approaches for authentication wrappers in my React components with React Router. The first method functions ...

Signal a refusal when the body structure does not meet the anticipated criteria

As I develop a node server using express, my goal is to ensure that the types received in the body are enforced. An example of what I am aiming for is: interface User { uid: string, email?: string, active: boolean, } app.put('/user', (req ...

Struggling to accurately import JSON with TypeScript typings

I am facing a challenge with the file test.json that I want to import in a typed form. { "items": [ { "kind": "youtube#video", "thumbnails": { "default": { "url" ...

Variable arguments, multi-array dimensions

When I pass two 1-dimensional arrays as arguments to a 2-dimensional var-arg method, everything works smoothly. However, when I try to pass the same two 1-d arrays to a method with a simple 2-dimensional argument, I encounter an error - The method m1(int[] ...

Controlling a generic interface's acceptance of certain data types in typescript: a guide

Is there a way to restrict a generic interface from accepting specific data types in TypeScript? I understand that I can define acceptable data types for a generic interface in TypeScript. interface exampleInterface<T = void | any>; But what if I w ...

Unable to locate and interact with a concealed item in a dropdown menu using Selenium WebDriver

Snippet: <select class="select2 ddl visible select2-hidden-accessible" data-allow-clear="true" id="Step1Model_CampaignAdditionalDataTypeId" multiple="" name="Step1Model.CampaignAdditionalDataTypeId" tabindex="-1" aria-hidden="true"> <option value ...

Deactivating Bootstrap Modal in Angular

Looking for advice on managing a Bootstrap Modal in Angular 7 I have a Form inside a Bootstrap Modal that I need to reset when the modal is closed (by clicking outside of it). Despite searching on Google, I haven't been able to find a solution. Any ...

TypeScript erroneously defines data type

Here is a snippet of code that I am working with: interface Ev<K extends keyof WindowEventMap> { readonly name: K; readonly once?: boolean; readonly callback: (ev: WindowEventMap[K]) => void; } function createEventListener<K extends keyo ...

Unable to save the file using the .json format

Whenever I attempt to save my file as .txt or .xml, the file is successfully created on my device. However, when I try to save it as .json, the file is never generated. Here is how I call my method: String test = "test"; String fileName = "kyriakos. ...

Learning to establish a connection between JavaScript and an SQL database

As I'm setting up a registration form for a website, I need to ensure that the username being entered by the user is not already in use. The code will check this against the database. ...

I am encountering a CORS error in Nest.js despite having CORS enabled

I'm currently working on a project using next.js for the frontend and nest.js for the backend. Despite having CORS enabled in my main.ts file of nest.js, I keep encountering CORS errors. Below is an excerpt from my main.ts file: import { NestFac ...

Having trouble accessing numerical data from a Microsoft Excel file using Selenium WebDriver in Java

Could someone assist with the error message "cannot get text value from numeric cell" in my Java code below. Additionally, I am having trouble aligning my output properly. The desired output should be: Username Password john 123 rambo 456 However, ...

Enhance the step implementation in Cucumber-js

Background In my TypeScript project, I am utilizing https://github.com/cucumber/cucumber-js. The code snippet below showcases a typical cucumber implementation: import { Given, Then, When } from 'cucumber' Given(`Page is up and run ...