aboutsummaryrefslogtreecommitdiffstats
path: root/Plugins/SqlEnterpriseFormatter/formatcreateindex.cpp
blob: 7a984bd6619e21d35c3ba5b93eb9cd0080ae6642 (plain) (blame)
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
#include "formatcreateindex.h"
#include "parser/ast/sqlitecreateindex.h"
#include "parser/ast/sqliteindexedcolumn.h"

FormatCreateIndex::FormatCreateIndex(SqliteCreateIndex* createIndex) :
    createIndex(createIndex)
{
}

void FormatCreateIndex::formatInternal()
{
    handleExplainQuery(createIndex);
    withKeyword("CREATE");
    if (createIndex->uniqueKw)
        withKeyword("UNIQUE");

    withKeyword("INDEX");

    if (createIndex->ifNotExistsKw)
        withKeyword("IF").withKeyword("NOT").withKeyword("EXISTS");

    if (!createIndex->database.isNull())
        withId(createIndex->database).withIdDot();

    withId(createIndex->index).withKeyword("ON").withId(createIndex->table).withParDefLeft().withStatementList(createIndex->indexedColumns).withParDefRight();

    if (createIndex->where)
        withKeyword("WHERE").withStatement(createIndex->where);

    withSemicolon();
}