aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/parser/ast/sqlitedropview.cpp
blob: 423b1da82fa32ee00d3439c7c624faabcef9920c (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
79
#include "sqlitedropview.h"
#include "sqlitequerytype.h"

#include <parser/statementtokenbuilder.h>

SqliteDropView::SqliteDropView()
{
    queryType = SqliteQueryType::DropView;
}

SqliteDropView::SqliteDropView(const SqliteDropView& other) :
    SqliteQuery(other), ifExistsKw(other.ifExistsKw), database(other.database), view(other.view)
{
}

SqliteDropView::SqliteDropView(bool ifExists, const QString &name1, const QString &name2)
    : SqliteDropView()
{
    this->ifExistsKw = ifExists;

    if (name2.isNull())
        view = name1;
    else
    {
        database = name1;
        view = name2;
    }
}

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

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

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

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

    // Table object
    FullObject fullObj = getFullObjectFromFullname(FullObject::VIEW);

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

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

    return result;
}


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

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

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

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

    return builder.build();
}