How to use variables in SQL Lite transaction (web kit browser local database)?
<p>So I have an array with variables with values from textfields</p>

<pre><code>var data = [name, address, city, country];
</code></pre>

<p>then the command </p>

<pre><code>transaction.executeSql("INSERT INTO Customer(name, address, city, country) VALUES (?, ?, ?, ?)", [data[0], data[1], data[2], data[3]]);
</code></pre>

<p>It works fine but in the real database I have about 50 fields and if I need to add for example three more I have to add three question marks, three data[n] and so on and it's quite error prone so I thought I would create it in a loop instead.</p>

<p>I have the array:</p>

<pre><code>var data = [name, address, city, country];
</code></pre>

<p>The loop:</p>

<pre><code>var columns = "";
var questionMarks = "";
for (var i = 0; i &lt; data.length; i++) {
    columns += "data[" + i + "], ";
    questionMarks += "?, ";
}

columns = columns.slice(0, -2);
questionMarks = questionMarks.slice(0, -2);
columns = "[" + columns + "]";
</code></pre>

<p>I can use questionMarks in the command like:</p>

<pre><code>transaction.executeSql("INSERT INTO Customer(name, address, city, country) VALUES (" + questionMarks + ")", [data[0], data[1], data[2], data[3]]);
</code></pre>

<p>But when I try to use columns as well it doesn't work</p>

<pre><code>transaction.executeSql("INSERT INTO Customer(name, address, city, country) VALUES (" + questionMarks + ")", columns);
</code></pre>

<p>also tried</p>

<pre><code>transaction.executeSql("INSERT INTO Customer(name, address, city, country) VALUES (" + questionMarks + ")", + columns);
</code></pre>

<p>I did document.write(columns) and it looks exactly the same as </p>

<pre><code>[data[0], data[1], data[2], data[3]]
</code></pre>

<p>What am I doing wrong with columns?</p>

<p>Thanks in advance</p>

<p>I guess questionMarks works becasue it is a string but the data[n] values are not a part of that.</p>
