aboutsummaryrefslogtreecommitdiff
path: root/editor-instance.js
diff options
context:
space:
mode:
authorJames Barnett <noreply@jamesbarnett.xyz>2018-02-28 21:32:48 +0000
committerJames Barnett <noreply@jamesbarnett.xyz>2018-02-28 21:32:48 +0000
commit28ebae4525f35672acd6253b3022bdb8cdc1cbd1 (patch)
treef78cd401095f6405057d3e67509218483f789413 /editor-instance.js
parent46d3ba84ed407548d368dd146393e747cfb2d0af (diff)
downloadsql-plus-plus-28ebae4525f35672acd6253b3022bdb8cdc1cbd1.tar.xz
sql-plus-plus-28ebae4525f35672acd6253b3022bdb8cdc1cbd1.zip
Update readme. Fix result parsing bug. Rearrange files
- Prefix query result fields with an underscore to avoid clashing with JS builtin property/function names which causes issues with Tabulator - Move html files into their own dir
Diffstat (limited to 'editor-instance.js')
-rw-r--r--editor-instance.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/editor-instance.js b/editor-instance.js
index 8ed6674..6e2fd67 100644
--- a/editor-instance.js
+++ b/editor-instance.js
@@ -188,7 +188,7 @@ function handleResult(results) {
dataTable = $("#result-table").tabulator({
height: "100%",
columns: _mapColumnProperties(results),
- data: results.rows
+ data: _escapeRowFieldNames(results.rows)
});
_setExecutionStatusIndicator("OK");
@@ -198,12 +198,27 @@ function handleResult(results) {
function _mapColumnProperties(results) {
return results.fields.map((column) => {
return {
- field: column.name,
+ field: "_" + column.name, // "_" to match up to the output of _escapeRowFieldNames()
title: column.name
};
});
}
+/**
+ * Return the row object with all fields prefixed with an underscore.
+ * This avoids issues with Tabulator which doesn't like fields to have the same identifiers
+ * as built in JS properties/functions (e.g. 'length')
+ */
+function _escapeRowFieldNames(rows) {
+ return rows.map(row => {
+ let escapedRow = {}
+ Object.keys(row).forEach(key => {
+ escapedRow["_" + key] = row[key];
+ });
+ return escapedRow;
+ });
+}
+
function _resultTable() {
return $("#result-table");
}