SQL Insert-Anweisung funktioniert nicht in Javascript

Ich versuche, meine WebSQL-Datenbank mithilfe eines JSON-Arrays zum Popup zu bringen (Object heißtmyJSONObjectArray wird aufgerufencostcodes).

Die Funktion wird beim Klicken ausgeführt, die Datenbank wird erfolgreich erstellt, die Daten werden jedoch nicht in die Datenbank eingefügt. Es wirft nicht einmal und irrt nicht, es macht einfach nichts.

Mein erster Gedanke war, dass die Daten nicht richtig entkommen, aber ich weiß nicht genau, wo / wie ich sie entkommen soll. Also bin ich ratlos.

<code>    localDB = null;

    function initDB()
    {
        if (localDB==null)
        {
            var shortName = 'Costcode';
            var version = '1.0';
            var displayName = 'Costcode';
            var maxSize = 217802; // in bytes
            localDB = window.openDatabase(shortName, version, displayName, maxSize);
        }

    }
            function buildTable()
    {
       var sQuery = 'CREATE TABLE IF NOT EXISTS Costcode ('+
                    'id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,' +
                    'cost_code_no VARCHAR NULL,' +
                    'row_unique_no VARCHAR NULL,' +
                    'cost_class_no VARCHAR NULL,' +
                    'Table_Version VARCHAR DEFAULT "1.0");';
        try
        {
            initDB();
            localDB.transaction(function(transaction)
            {
                transaction.executeSql(sQuery, []);
                console.log('sucess');
            });
        }
        catch (e)
        {
           alert("Error: Unable to create table 'x" + "' " + e + ".");
           return;
       }    
    }


 function exeSQLFast()
    {

                initDB();
                localDB.transaction(function(transaction)
                {
                    for (var x = 0; x <myJSONObject.costcodes.length; x++)
                    {

                        var costcodeno = myJSONObject.costcodes[x].cost_code_no;
                        var rowuniqueid = myJSONObject.costcodes[x].row_unique_id;
                        var costclassno = myJSONObject.costcodes[x].cost_class_no;
                        console.log(costcodeno);
                        console.log(rowuniqueid); 
                        console.log(costclassno);
                    transaction.executeSql('INSERT INTO Costcode (cost_code_no, row_unique_id, cost_class_no) VALUES (? , ? , ?)',
                     [costcodeno,
                     rowuniqueid,
                     costclassno]
                     , function(transaction, results)
                        {
                            console.log(costcodeno);
                            console.log('hooray');
                        }

                    )};
                    }
            )}

</script>
</head>

<body onLoad="buildTable();">
<input type="button" onClick="exeSQLFast();" value='button'>
</body>
</html>
</code>

Das Konsolenprotokoll zeigt an, dass alle Variablen ordnungsgemäß definiert sind, die insert-Anweisung jedoch nicht ausgeführt wird. Irgendwelche Ideen?

Hier ist ein Beispiel fürmyJSONObject.costcodes[2]

<code>cost_class_no: "    3"
cost_code_no: "      1000"
row_unique_id: 335
</code>

Das sieht nach einem Problem aus, nicht wahr?

Antworten auf die Frage(1)

Ihre Antwort auf die Frage