aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitedropindex.cpp
blob: 8d5f878d67c264f97864726c0aca3ba81eae5088 (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
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
74
75
76
77
78
#include "sqlitedropindex.h"
#include "sqlitequerytype.h"

#include <parser/statementtokenbuilder.h>

SqliteDropIndex::SqliteDropIndex()
{
    queryType = SqliteQueryType::DropIndex;
}

SqliteDropIndex::SqliteDropIndex(const SqliteDropIndex& other) :
    SqliteQuery(other), ifExistsKw(other.ifExistsKw), database(other.database), index(other.index)
{
}

SqliteDropIndex::SqliteDropIndex(bool ifExists, const QString &name1, const QString &name2)
    : SqliteDropIndex()
{
    this->ifExistsKw = ifExists;
    if (!name2.isNull())
    {
        database = name1;
        index = name2;
    }
    else
        index = name1;
}

SqliteStatement*SqliteDropIndex::clone()
{
    return new SqliteDropIndex(*this);
}

QStringList SqliteDropIndex::getDatabasesInStatement()
{
    return getStrListFromValue(database);
}

TokenList SqliteDropIndex::getDatabaseTokensInStatement()
{
    return getDbTokenListFromFullname();
}

QList<SqliteStatement::FullObject> SqliteDropIndex::getFullObjectsInStatement()
{
    QList<FullObject> result;

    // Index object
    FullObject fullObj = getFullObjectFromFullname(FullObject::INDEX);

    if (fullObj.isValid())
        result << fullObj;

    // Db object
    fullObj = getFirstDbFullObject();
    if (fullObj.isValid())
        result << fullObj;

    return result;
}


TokenList SqliteDropIndex::rebuildTokensFromContents()
{
    StatementTokenBuilder builder;
    builder.withTokens(SqliteQuery::rebuildTokensFromContents());
    builder.withKeyword("DROP").withSpace().withKeyword("INDEX").withSpace();

    if (ifExistsKw)
        builder.withKeyword("IF").withSpace().withKeyword("EXISTS").withSpace();

    if (!database.isNull())
        builder.withOther(database).withOperator(".");

    builder.withOther(index).withOperator(";");

    return builder.build();
}