Generate DML
by Harm Zeinstra
HTML
<textarea id='sql'>
</textarea>
JavaScript
var area = document.getElementById('sql');
/* var nTypeTrees = Math.floor((Math.random() * 4) + 1);
var nTrees = Math.floor((Math.random() * 30) + 30);
for (var forest = 1; forest <= 10; forest++) {
for (var j = 0; j < nTypeTrees; j++) {
var type = Math.floor((Math.random() * 20) + 1);
var age = Math.floor((Math.random() * 4));
for (var i = 0; i < nTrees; i++) {
area.value += `INSERT INTO treecare.tree (typeId, age, forestId) VALUES (${type}, ${age}, ${forest});\r`;
}
}
} */
var profitByForest = [];
for (var forest = 1; forest <= 10; forest++) profitByForest[forest] = 0;
for (var forest = 1; forest <= 10; forest++) {
var nTypeTrees = Math.floor((Math.random() * 4) + 1);
for (var j = 0; j < nTypeTrees; j++) {
var profit = Math.floor((Math.random() * 9999) + 250);
profitByForest[forest] += profit;
var type = Math.floor((Math.random() * 20) + 1);
var treeLogs = Math.floor((Math.random() * profit / 120) + 1);
area.value += `INSERT INTO treecare.tree_logs_by_forest (forestId, treeTypeId, treeLogs, profit) VALUES (${forest}, ${type}, ${treeLogs}, ${profit});\r`;
}
}
for (var i = 1; i <= 10; i++) {
area.value += `UPDATE forest SET profit = ${profitByForest[i]} WHERE id = ${i};\r`;
}
area.addEventListener('click', function() {
this.select();
this.setSelectionRange(0, 99999999); /*For mobile devices*/
/* Copy the text inside the text field */
document.execCommand("copy");
})