Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions addon/hint/sql-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,21 @@
if (name.charAt(0) == ".") {
name = name.substr(1);
}
return name.replace(new RegExp(identifierQuote,"g"), "");
// replace doublicated identifierQuotes with single identifierQuotes
// and remove single identifierQuotes
var nameParts = name.split(identifierQuote+identifierQuote);
for (var i = 0; i < nameParts.length; i++)
nameParts[i] = nameParts[i].replace(new RegExp(identifierQuote,"g"), "");
return nameParts.join(identifierQuote);
}

function insertIdentifierQuotes(name) {
var nameParts = getText(name).split(".");
for (var i = 0; i < nameParts.length; i++)
nameParts[i] = identifierQuote + nameParts[i] + identifierQuote;
nameParts[i] = identifierQuote +
// doublicate identifierQuotes
nameParts[i].replace(new RegExp(identifierQuote,"g"), identifierQuote+identifierQuote) +
identifierQuote;
var escaped = nameParts.join(".");
if (typeof name == "string") return escaped;
name = shallowClone(name);
Expand Down
65 changes: 64 additions & 1 deletion test/sql-hint-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
{text: "name", displayText: "name | The name"}]
}];

namespace = "sql-hint_";
var problemTables = {
"backtick`table": ["backtick`col"],
"doublequote\"table": ["doublequote\"col"],
"space table": ["space column"]
};

namespace = "sql-hint_";

function test(name, spec) {
testCM(name, function(cm) {
Expand Down Expand Up @@ -220,6 +226,63 @@
to: Pos(0, 9)
})

test("backticktable", {
value: "SELECT `backtick",
cursor: Pos(0, 16),
tables: problemTables,
list: ["`backtick``table`"],
from: Pos(0, 7),
to: Pos(0, 16)
});

test("backticktable2", {
value: "SELECT `backtick``ta",
cursor: Pos(0, 20),
tables: problemTables,
list: ["`backtick``table`"],
from: Pos(0, 7),
to: Pos(0, 20)
});

test("backtickcolumn", {
value: "SELECT `backtick``table`.`back",
cursor: Pos(0, 29),
tables: problemTables,
list: ["`backtick``table`.`backtick``col`"],
from: Pos(0, 7),
to: Pos(0, 29)
});

test("doublequotetable", {
value: "SELECT \"doublequ",
cursor: Pos(0, 16),
tables: problemTables,
list: ["\"doublequote\"\"table\""],
from: Pos(0, 7),
to: Pos(0, 16),
mode: "text/x-sqlite"
});

test("doublequotecolumn", {
value: "SELECT \"doublequote\"\"table\".\"doubl",
cursor: Pos(0, 33),
tables: problemTables,
list: ["\"doublequote\"\"table\".\"doublequote\"\"col\""],
from: Pos(0, 7),
to: Pos(0, 33),
mode: "text/x-sqlite"
});

test("spacetable", {
value: "SELECT `space ta",
cursor: Pos(0, 16),
tables: problemTables,
list: ["`space table`"],
from: Pos(0, 7),
to: Pos(0, 16)
});


function deepCompare(a, b) {
if (a === b) return true
if (!(a && typeof a == "object") ||
Expand Down