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/formatinsert.cpp | |
Imported Upstream version 2.99.6upstream/2.99.6
Diffstat (limited to 'Plugins/SqlEnterpriseFormatter/formatinsert.cpp')
| -rw-r--r-- | Plugins/SqlEnterpriseFormatter/formatinsert.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Plugins/SqlEnterpriseFormatter/formatinsert.cpp b/Plugins/SqlEnterpriseFormatter/formatinsert.cpp new file mode 100644 index 0000000..1ff0535 --- /dev/null +++ b/Plugins/SqlEnterpriseFormatter/formatinsert.cpp @@ -0,0 +1,54 @@ +#include "formatinsert.h" +#include "parser/ast/sqliteselect.h" +#include "parser/ast/sqliteinsert.h" +#include "formatwith.h" + +FormatInsert::FormatInsert(SqliteInsert* insert) : + insert(insert) +{ +} + +void FormatInsert::formatInternal() +{ + if (insert->replaceKw) + { + withStatement(insert->with); + withKeyword("REPLACE"); + } + else + { + withStatement(insert->with); + withKeyword("INSERT"); + if (insert->onConflict != SqliteConflictAlgo::null) + withKeyword("OR").withKeyword(sqliteConflictAlgo(insert->onConflict)); + } + + withKeyword("INTO"); + + if (!insert->database.isNull()) + withId(insert->database); + + withId(insert->table); + + if (insert->defaultValuesKw) + { + withKeyword("DEFAULT").withKeyword("VALUES"); + } + else + { + markAndKeepIndent("insertCols"); + if (insert->columnNames.size() > 0) + withParDefLeft().withIdList(insert->columnNames).withParDefRight(); + + if (insert->select) + { + withStatement(insert->select); + } + else if (dialect == Dialect::Sqlite2) // Sqlite2 uses classic single row values + { + withKeyword("VALUES").withParDefLeft().withStatementList(insert->values).withParDefRight(); + } + withDecrIndent(); + } + withSemicolon(); +} |
