Home>

Although it is a basic question, I would like to use a variable when executing "insert" by bringing "SqlChipher" in monaca plug-in. How should I write it? ?

tx.executeSql ('INSERT INTO TestTable (id, data) VALUES (1, "Aiueo")');


Well, there is a sample and it is possible as a matter of course,
I don't know how to make the variable "quote" here variable.
For example,

var dToday = new Date ();
var hour = dToday.getHours ();
var minute = dToday.getMinutes ();
var second = dToday.getSeconds ();
var hhmmss = hour * 3600 + minute * 60 + second;
 ...
 ...
tx.executeSql ('INSERT INTO TestTable (id, data) VALUES (1, hhmmss)');


I don't know how to put variables in the insert statement.

I think this is quite rudimentary, but please give me somebody professor.

  • Answer # 1

    tx.executeSql (`INSERT INTO TestTable (id, data) VALUES (1, ${hhmmss})`);
    // INSERT INTO TestTable (id, data) VALUES (1,4689)
    //tx.executeSql('INSERT INTO TestTable (id, data) VALUES (1, hhmmss) ');
    //tx.executeSql(`INSERT INTO TestTable (id, data) VALUES (1, ${hhmmss}) `);

    That template string like this-JavaScript | Why not embed with MDN?

  • Answer # 2

    Thank you for your comments.
    I investigated it and solved it by the following methods. Sorry for the inconvenience.

    tx.executeSql ('INSERT INTO TestTable (1, data) VALUES (1,?)', [hhmmss]);