diff options
| author | 2014-12-06 17:33:25 -0500 | |
|---|---|---|
| committer | 2014-12-06 17:33:25 -0500 | |
| commit | 7167ce41b61d2ba2cdb526777a4233eb84a3b66a (patch) | |
| tree | a35c14143716e1f2c98f808c81f89426045a946f /Plugins/SqlEnterpriseFormatter/formatcreatevirtualtable.cpp | |
Imported Upstream version 2.99.6upstream/2.99.6
Diffstat (limited to 'Plugins/SqlEnterpriseFormatter/formatcreatevirtualtable.cpp')
| -rw-r--r-- | Plugins/SqlEnterpriseFormatter/formatcreatevirtualtable.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/Plugins/SqlEnterpriseFormatter/formatcreatevirtualtable.cpp b/Plugins/SqlEnterpriseFormatter/formatcreatevirtualtable.cpp new file mode 100644 index 0000000..d291eda --- /dev/null +++ b/Plugins/SqlEnterpriseFormatter/formatcreatevirtualtable.cpp @@ -0,0 +1,106 @@ +#include "formatcreatevirtualtable.h" +#include "parser/ast/sqlitecreatevirtualtable.h" +#include "parser/lexer.h" + +FormatCreateVirtualTable::FormatCreateVirtualTable(SqliteCreateVirtualTable* cvt) : + cvt(cvt) +{ +} + +void FormatCreateVirtualTable::formatInternal() +{ + withKeyword("CREATE").withKeyword("VIRTUAL").withKeyword("TABLE"); + if (cvt->ifNotExistsKw) + withKeyword("IF").withKeyword("NOT").withKeyword("EXISTS"); + + if (!cvt->database.isNull()) + withId(cvt->database).withIdDot(); + + withId(cvt->table).withKeyword("USING").withId(cvt->module); + if (!cvt->args.isEmpty()) + { + withParDefLeft(); + int i = 0; + for (const QString& arg : cvt->args) + { + if (i > 0) + withListComma(); + + for (const TokenPtr& tk : Lexer::tokenize(arg, Dialect::Sqlite3)) + handleToken(tk); + + i++; + } + withParDefRight(); + } + + withSemicolon(); +} + +void FormatCreateVirtualTable::handleToken(const TokenPtr& token) +{ + switch (token->type) + { + case Token::OTHER: + withId(token->value); + break; + case Token::STRING: + withString(token->value); + break; + case Token::COMMENT: + // TODO Format comment here + break; + case Token::FLOAT: + withFloat(token->value.toDouble()); + break; + case Token::INTEGER: + withInteger(token->value.toInt()); + break; + case Token::BIND_PARAM: + withBindParam(token->value); + break; + case Token::OPERATOR: + withOperator(token->value); + break; + case Token::PAR_LEFT: + withParDefLeft(); + break; + case Token::PAR_RIGHT: + withParDefRight(); + break; + case Token::BLOB: + withBlob(token->value); + break; + case Token::KEYWORD: + withKeyword(token->value); + break; + case Token::SPACE: + case Token::INVALID: + case Token::CTX_COLUMN: + case Token::CTX_TABLE: + case Token::CTX_DATABASE: + case Token::CTX_FUNCTION: + case Token::CTX_COLLATION: + case Token::CTX_INDEX: + case Token::CTX_TRIGGER: + case Token::CTX_VIEW: + case Token::CTX_JOIN_OPTS: + case Token::CTX_TABLE_NEW: + case Token::CTX_INDEX_NEW: + case Token::CTX_VIEW_NEW: + case Token::CTX_TRIGGER_NEW: + case Token::CTX_ALIAS: + case Token::CTX_TRANSACTION: + case Token::CTX_COLUMN_NEW: + case Token::CTX_COLUMN_TYPE: + case Token::CTX_CONSTRAINT: + case Token::CTX_FK_MATCH: + case Token::CTX_PRAGMA: + case Token::CTX_ROWID_KW: + case Token::CTX_NEW_KW: + case Token::CTX_OLD_KW: + case Token::CTX_ERROR_MESSAGE: + break; + } +} + |
