From dce47b3404e25dbc2404cebdc1ff50037777226a Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Tue, 18 Aug 2015 22:54:16 +0200 Subject: [PATCH] grammar: Correctly parse double quotes as a means of escaping This should parse the table and column names correctly by removing any double quote characters and replacing them by a single one. See issue #387. --- src/sqlitetypes.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/sqlitetypes.cpp b/src/sqlitetypes.cpp index 855bb6c8..02725dff 100644 --- a/src/sqlitetypes.cpp +++ b/src/sqlitetypes.cpp @@ -256,9 +256,20 @@ QString identifier(antlr::RefAST ident) ident->getType() == Sqlite3Lexer::QUOTEDLITERAL || ident->getType() == sqlite3TokenTypes::STRINGLITERAL) { + // Remember the way the identifier is quoted + QChar quoteChar = sident.at(0); + + // Remove first and final character, i.e. the quotes sident.remove(0, 1); - sident.remove(sident.length() - 1, 1); + sident.chop(1); + + // Replace all remaining occurences of two succeeding quote characters and replace them + // by a single instance. This is done because two quotes can be used as a means of escaping + // the quote character, thus only the visual representation has its two quotes, the actual + // name contains only one. + sident.replace(QString(quoteChar) + quoteChar, quoteChar); } + return sident; }