The WebSQL encountered an error stating `SQL execution is not permitted` while trying to chain promises

Despite the lengthy title, I couldn't think of a better one for my specific situation. If you have any suggestions, feel free to share! Essentially, I've outlined the issue I'm grappling with in a simplified version on this JSFiddle. In this case, I'm utilizing AngularJS's $q.all method to gather an array of promises that are dependent on query results:

db.transaction(function(tx) {
    $q.all(fn(tx)).then(function(a) {
        console.log("Result:", a);
    });
});

Here, the code operates smoothly as anticipated, and the resulting array of SQL query outcomes (which resolve the promises) is correctly displayed via console.log. However, if I encase $q.all within the then method of another deferred object like so:

db.transaction(function(tx) {
    fn2(tx).then(function(tx) {
        $q.all(fn(tx)).then(function(a) {
            console.log("Result:", a);
        });
    });
});

An error surfaces:

Error: Failed to execute 'executeSql' on 'SQLTransaction': SQL execution is disallowed.
(fn2 is simply a function that returns a promise resolving to the tx object itself). Could this be a common stumbling block? Despite my research efforts, I haven't come across any relevant information. Thanks.

Answer №1

The reason for this issue is because the transaction is already being closed when fn2 is resolved.

To resolve this, you can avoid using a transaction (or use a different one) in both fn2 and fn. Here's an example:

db.transaction(function(tx) {
    fn2(tx).then(function(tx) {
        // Create a new transaction as the old one is closed
        db.transaction(function(tx) {
            $q.all(fn(tx)).then(function(a) {
                console.log("Result:", a);
            });
        });
    });
}); 

You can also check out this example on JSFiddle.

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

Not another instance of the elusive 'Unrecognized provider' error in an AngularJS service

I hate to be the one asking for help, but I've been stuck on this issue for quite some time now. Within my AngularJS application, I have three files that just won't work together. Despite trying various solutions both online and within the projec ...

Troubleshooting issue: JSON.stringify function returning 'undefined'

Having some trouble with JSON in JavaScript. I've been using JSON.stringify without issue until now. But suddenly, when I try to use it in my application, I keep getting this error in the console (Google Chrome): Uncaught TypeError: undefined is not ...

Acquiring the parent object (a group) from the children in Three.js

In the scenario I have created, there are multiple groups of objects (Object3Ds) and I have established a mechanism for clicking or hovering over them to trigger specific actions. However, when using the raycaster to identify the objects under the cursor, ...

Attempting to employ the .reduce method on an object

Currently, I am faced with the task of summing a nested value for all objects within an object. The structure of my object is as follows: const json = [ { "other_sum": "1", "summary": { "calculations" ...

I require the ability to generate a fresh JSON file using Node.js

I'm encountering a problem while working on creating a new JSON file. Each time I attempt to use the writeFile function, it throws an error stating that the directory does not exist. Below is the code snippet that I have experimented with: fs.writeFil ...

The error message "TypeError: Unable to access the 'get' property of an undefined vue js object" appeared

Struggling to grasp the concept of vue.js, I am currently navigating my way through understanding how to fetch or call an API. Setting up my index.html and app.js, along with the required packages in the node_modules, has been relatively smooth. However, ...

removing breaks from a text field

Struggling to remove line breaks when copying from Word and pasting into a textarea. I thought it would be easy, but it's not working as expected. I must be missing something simple, but I can't seem to find the issue. The function below is suppo ...

What is the process for dynamically submitting the value of an input field?

Here are some categories: <div class="cbp-l-inline-title" style=" font-size: 18px;"> <span style="color: #0669b4">Generic Name:</span> <a><?php echo $category[0]['generic_name'];?></a> </div> W ...

Utilize the filter function to refine and sort through objects

I have an array of objects structured as follows: pages= [ { "id":1, "name":"name1", "languages":[ { "id":1, "lang":"en" }, { "id":2, "lang":"de" } ...

Warning: Neglecting to handle promise rejections is now considered outdated and discouraged

I encountered this issue with my code and I'm unsure how to resolve it. DeprecationWarning: Unhandled promise rejections are deprecated. In the future, unhandled promise rejections will terminate the Node.js process with a non-zero exit code. This ...

Having difficulty deciphering JWE Token using Python jwcrypt and NodeJS jose interaction

I am facing an issue with decrypting a JWE Token that was created using the jwcrypt library in Python and trying to decrypt it using the jose library in JavaScript. I have set up the A256KW and A256CBC-HS512 algorithms on both libraries and also provided ...

Problem encountered when closing a lightbox on ASP.net using C# during page load

Can you explain the events that are triggered when the ASP.NET page load event occurs? I am currently using a lightbox for some insertion tasks, and after the insertion is complete, I want the parent page to reload with the new value displayed in the gri ...

Safari Version 8.0.2 experiencing issues with fixed positioning

I am currently working on an angular application and I find myself inside a Twitter Bootstrap modal. My goal is to relocate a button that is located within the body of the modal to the footer of the modal using fixed positioning. This particular button tr ...

Different ways to conditionally set the expanded prop for the Material UI TreeView component

I am currently working on implementing a tree select feature similar to the one found in antd's tree-select using material ui components. Specifically, I have a TextField and TreeView components from Material-UI stacked vertically. Initially, I want t ...

Is it possible to utilize the react state dispatch within an effect before it has been defined?

The code below successfully displays the number 1: "use client"; import { useEffect, useState } from "react"; export function StateTest() { useEffect(() => { setX(1); }); const [x, setX] = useState(0); return <div ...

Does Eslint's no-restricted-imports rule only limit imports from the package's root directory?

For example, I'm looking to limit the usage of importing react-use, while still permitting react-use/lib/usePrevious. I attempted this: rules: { 'no-restricted-imports': [2, { patterns: [ 'react-use', ] }], }, As ...

Storing the created .wav file on the server using PHP

Is there another way to handle this? How can I manage streaming of a WAV file? I'm currently working on a platform that allows users to create their music compositions and the system outputs a .wav file for each creation. While I can play the mus ...

Saving extensive JSON pipelining requests for future use

I am facing the challenge of retrieving a large amount of data in my view using JavaScript from a server. The JSON data is approximately 30,000,000 characters long. To give you an idea, it looks something like this (just an example): [{x:1000,y:1000,t:15 ...

Using optional chaining on the left side in JavaScript is a convenient feature

Can the optional chaining operator be used on the left side of an assignment (=) in JavaScript? const building = {} building?.floor?.apartment?.number = 3; // Is this functionality supported? ...

Retrieving adjacent HTML elements in AngularJS without duplication

When an overlay element is clicked and the startCopying() method is triggered, the text from the copyTextTag should be copied into the pasteTextTag element. The text should be copied in HTML format and pasted as HTML format. Additionally, there are multip ...