The challenge of storing GeoJSON data within SQLite database using Cordova

Below is a snippet of code that I am working with:

var json_data = document.getElementById("json_data").value;
console.log(json_data);

 tx.executeSql('INSERT INTO floodmaps VALUES (?,?,?)', [1, flodMapName, json_data], function(tx, res) {
     //console.log(res);
     console.log("rowsAffected: " + res.rowsAffected + " -- should be 1");
     //console.log(res.rows.item(0).flood_name);
   },
   function(tx, error) {
     console.log('INSERT error: ' + error.message);
   });

 tx.executeSql('SELECT *FROM floodmaps', [], function(tx, res) {
     //console.log(res);
     console.log(res.rows.item(0).id);
     console.log(res.rows.item(0).flood_name);
     console.log(res.rows.item(0).json_data);
   },
   function(tx, error) {
     console.log('error: ' + error.message);
   });

The purpose of this code is to retrieve the value from an input element and then store that value in the database. However, I am encountering an issue as the value is not being saved. The debug console displays the following message:

rowsAffected: 1 -- should be 1
main.js:208 null
main.js:209 null
main.js:210 null
main.js:241 Transaction Successful

Interestingly, when I tried using sample data such as plain text or a single word, the data was successfully saved. What could potentially be causing this problem?

Feel free to access the data referenced in the code.

Answer №1

var jsonData = document.getElementById("jsonData").value;
console.log(jsonData);
var strJsonData = JSON.stringify(jsonData);  // my modifications
tx.executeSql('INSERT INTO floodmaps VALUES (?,?,?)', [1, flodMapName, strJsonData], function(tx, res) {
     //console.log(res);
     console.log("rowsAffected: " + res.rowsAffected + " -- should be 1");
     //console.log(res.rows.item(0).flood_name);

    if(res.rowsAffected>0){
     tx.executeSql('SELECT * FROM floodmaps', [], function(tx, res) {
     //console.log(res);
       var length = res.rows.length, index;

            for (index = 0; index < length; index++) {
                console.log(res.rows.item(index));
            }
   },
   function(tx, error) {
     console.log('error: ' + error.message);
   });

      }
   },
   function(tx, error) {
     console.log('INSERT error: ' + error.message);
   });

Remember to convert the JSON object to a string before insertion

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

Python error: The PostgreSQL relation does not exist

After creating a database in psql, I made a table named "tweet" within it. CREATE TABLE tweet ( tid CHARACTER VARYING NOT NULL, DATA json, CONSTRAINT tid_pkey PRIMARY KEY (tid) ); When running SELECT * FROM tweet; in the psql window, an empty ta ...

Highcharts displays data with the fourth y axis but doesn't include labels for it

I'm facing an issue with displaying all the labels on my chart. I have 4 series plotted and decided to add two y-axes on each side of the graph, but the labels for the last series named "Stuff Data" are not showing up correctly. Instead, it seems to b ...

The ng-change event in AngularJS is not being activated by IE 11

Hello everyone, I am currently working with the angularjs framework and implementing a datepicker functionality. Unfortunately, the input type date is not functioning correctly on Internet Explorer. As a workaround, I have utilized jquery and css to create ...

Leveraging webpack2 for code splitting with the CommonsChunkPlugin

I encountered an issue while using code splitting and the CommonsChunkPlugin. My previous experience with require.js involved files being automatically cached. Additionally, I have configured my webpack with libraryTarget: 'amd'. When looking at ...

Error message displayed: "Unexpected token 'H' when attempting to render Markdown

I've been working with the react markdown library and wanted to share my code: import Markdown from 'react-markdown'; import PreClass from './PreClass'; type MarkdownFormatTextProps = { markdown: string; tagName?: string; ...

Is it possible to observe the website functionalities and execute them directly from the console?

Question about JavaScript: Is it safe for a script tag to be visible in the body of the developer console and for functions to be run directly on the website? It raises security concerns, and there should be measures in place to prevent this kind of displa ...

What is the best way to adjust the width of floating divs to completely fill the space they occupy?

On the first picture, there are six equal divs displayed. As the screen size increases, the width of the divs also grows to fill up their space, like a table cell or another div. If there is enough space in the first row to accommodate the fourth div, it s ...

What Occurs to Processed Messages in Azure Functions if Result is Not Output?

I have created an Azure function that is connected to the messaging endpoint of an IoT Hub in order to trigger the function for all incoming messages. The main purpose of this function is to decompress previously compressed messages using GZIP before they ...

Transferring Data from Controller to HTML in AngularJS Version 1

Recently, I started working with angularjs on a new project that involves three main HTML files. The first file is index.html, which contains the ng-view directive. The second file is home.html, where various products are displayed from a database. Each pr ...

The functionality of sending POST parameters with a Volley JsonObjectRequest has been disabled

I'm attempting to send POST parameters in a Volley JsonObjectRequest. Initially, I had success by passing a JSONObject containing the parameters in the constructor of the JsonObjectRequest as advised in the official documentation. However, suddenly it ...

Having trouble with jQuery's 'OR' not functioning properly when iterating through mandatory input elements

In the process of creating a fallback for required HTML5 attributes for different input types, I encountered an issue with checking the ':checked' status of radio buttons and using the 'OR' || operator within the loop: if (self.val() = ...

fetch data in json format from httpbin

I am trying to send my html form data as JSON by using an AJAX call to httpbin.org, but unfortunately, I'm not receiving the desired output. $("#contact").submit( $.ajax({ url: "http://httpbin.org/post", type:'POS ...

Pricing determined by location on a website created with HTML

We are looking to customize our HTML5/CSS3 website by displaying different pricing tables based on the location of each visitor. Our goal is to have a fixed price for users from Singapore while showing a different price for visitors from other parts of th ...

Creating a search-enabled multi-select feature in a Tabulator.js column

Currently, I am working on a project involving Tabulator.js and attempting to incorporate a column with a multi-select feature that includes a search option. My approach has been to utilize the Select2 library, but I have run into some challenges. Here is ...

What is the best way to retrieve widget options when inside an event?

Creating a custom jQuery widget: jQuery.widget("ui.test",{ _init: function(){ $(this.element).click(this.showPoint); }, showPoint: function(E){ E.stopPropagation(); alert(this.options.dir); } } Initializing the cu ...

Crafting dynamic objects with THREE.JS

I am working with a JSON configuration that looks like this: { shape:[ 'SphereGeometry', [7, 16, 16] ] } My goal is to load a model using the following code: new THREE[shape[0]].apply( this, shape[1] ) However, it seems that using "new" and " ...

Discrepancy in Timestamp Deviation for Older Dates Between Java and Javascript (1 Hour)

When I try to convert a string date representation to numeric values, I noticed a discrepancy between Java/Groovy/PHP and Javascript. Specifically, for certain dates before 1970, the JS timestamp is exactly 3600 seconds behind the Java timestamp. This issu ...

Attempting to create a JavaScript class within an HTML document

Having an issue with instantiating a JavaScript class in a separate HTML file. The JavaScript class looks like this: class Puzzle { constructor(fenStart, pgnEnd) { this.fenStart = fenStart; this.pgnEnd = pgnEnd; } } module.exports = Puzzle; ...

Error: jQuery is unable to access the property 'xxx' because it is undefined

While attempting to make a post request from the site to the server with user input data, I encountered an error message saying TypeError: Cannot read property 'vehicle' of undefined as the response. Here is the HTML and script data: <!DOCTY ...

Attempted to utilize zipstatic but received no feedback

I attempted to utilize the Zipstatic API with jQuery in my code, as shown below. However, I am not receiving any response. Could there be something missing? jQuery(function() { jQuery("#form").hide(); jQuery("#postcode").keyup(function() { var c ...