6 Replies - 376 Views - Last Post: 10 April 2018 - 03:49 AM

#1 Pogaca   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 142
  • Joined: 24-August 13

Table insert does not work

Posted 10 April 2018 - 01:42 AM

Greetings everyone,

So, inside one function I have two queries, which is not a problem, I had other functions with over 7 queries. But, now I would like to insert JSON string inside SQLite database. It just does not work. I use this code so far:

function saveDataToDatabase() {
    
    saveFontValues();
    saveColors();
//    getCoordinatesOfBoxes();

    db.transaction(function(tx){
        tx.executeSql("CREATE TABLE IF NOT EXISTS template (id INTEGER NOT NULL PRIMARY KEY, colors TEXT, fonts TEXT)");
        
    });
    
    db.transaction(function(tx){
        tx.executeSql("INSERT INTO template VALUES(?,?,?)"[null, colors, fonts]);
    });
    
    }


Keep it in mind that colros and fonts are both JSON strings converted from Javascript object to string this way:
 colors = JSON.stringify(colorObj);


Is it wrong that I choose TEXT as expected value for JSON in table? What should i pick? After all. json string is a string. Problem is that when I use console.log, I see all values for colors, but when I try to insert them, nothing happens.

Is This A Good Question/Topic? 0
  • +

Replies To: Table insert does not work

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4244
  • View blog
  • Posts: 13,449
  • Joined: 08-June 10

Re: Table insert does not work

Posted 10 April 2018 - 01:54 AM

Is that IndexedDB?
Was This Post Helpful? 0
  • +
  • -

#3 Pogaca   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 142
  • Joined: 24-August 13

Re: Table insert does not work

Posted 10 April 2018 - 01:58 AM

No, it is not. This is what I use:
https://developer.ap...ptDatabase.html
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4244
  • View blog
  • Posts: 13,449
  • Joined: 08-June 10

Re: Table insert does not work

Posted 10 April 2018 - 02:14 AM

So this is not a browser script?
Was This Post Helpful? 0
  • +
  • -

#5 Pogaca   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 142
  • Joined: 24-August 13

Re: Table insert does not work

Posted 10 April 2018 - 02:30 AM

Yes it is. Database is stored on client side. Not like PHP on server side. I simply use javascript and jQuery to create, update, delete, select (any query) for table. It worked well for most thing I have done but now it just won't insert JSON string.
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4244
  • View blog
  • Posts: 13,449
  • Joined: 08-June 10

Re: Table insert does not work

Posted 10 April 2018 - 03:14 AM

Quote

tx.executeSql("INSERT INTO template VALUES(?,?,?)"[null, colors, fonts]);

Seems like there's a comma missing. but JS would complain about that.

This post has been edited by Dormilich: 10 April 2018 - 03:14 AM

Was This Post Helpful? 1
  • +
  • -

#7 Pogaca   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 142
  • Joined: 24-August 13

Re: Table insert does not work

Posted 10 April 2018 - 03:49 AM

Oh my, you are right. Than you so much!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1