1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include "formatupdate.h"
#include "parser/ast/sqliteupdate.h"
#include "parser/ast/sqliteexpr.h"
#include "formatwith.h"
FormatUpdate::FormatUpdate(SqliteUpdate* upd) :
upd(upd)
{
}
void FormatUpdate::formatInternal()
{
handleExplainQuery(upd);
if (upd->with)
withStatement(upd->with);
markKeywordLineUp("UPDATE");
withKeyword("UPDATE");
if (upd->onConflict != SqliteConflictAlgo::null)
withKeyword("OR").withKeyword(sqliteConflictAlgo(upd->onConflict));
if (!upd->database.isNull())
withId(upd->database).withIdDot();
withId(upd->table);
if (!upd->tableAlias.isNull())
withKeyword("AS").withId(upd->tableAlias);
if (upd->indexedByKw)
withKeyword("INDEXED").withKeyword("BY").withId(upd->indexedBy);
else if (upd->notIndexedKw)
withKeyword("NOT").withKeyword("INDEXED");
withNewLine().withLinedUpKeyword("SET");
markAndKeepIndent("updateColumns");
bool first = true;
for (const SqliteUpdate::ColumnAndValue& keyVal : upd->keyValueMap)
{
if (!first)
withListComma();
if (keyVal.first.type() == QVariant::StringList)
withParDefLeft().withIdList(keyVal.first.toStringList()).withParDefRight().withOperator("=").withStatement(keyVal.second);
else
withId(keyVal.first.toString()).withOperator("=").withStatement(keyVal.second);
first = false;
}
withDecrIndent();
if (upd->from)
withNewLine().withLinedUpKeyword("FROM").withStatement(upd->from, "updateColumns");
if (upd->where)
withNewLine().withLinedUpKeyword("WHERE").withStatement(upd->where);
if (!upd->returning.isEmpty())
{
withNewLine().withLinedUpKeyword("RETURNING");
withStatementList(upd->returning, "returningColumns");
}
if (upd->orderBy.size() > 0)
withNewLine().withLinedUpKeyword("ORDER").withKeyword("BY").withStatementList(upd->orderBy, "order");
if (upd->limit)
withNewLine().withLinedUpKeyword("LIMIT").withStatement(upd->limit, "limit");
withSemicolon();
}
|