#include "sqliterelease.h"
#include "sqlitequerytype.h"

#include <parser/statementtokenbuilder.h>

SqliteRelease::SqliteRelease()
{
    queryType = SqliteQueryType::Release;
}

SqliteRelease::SqliteRelease(const SqliteRelease& other) :
    SqliteQuery(other), name(other.name), savepointKw(other.savepointKw)
{
}

SqliteRelease::SqliteRelease(bool savepointKw, const QString& name)
    : SqliteRelease()
{
    this->name = name;
    this->savepointKw = savepointKw;
}

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

TokenList SqliteRelease::rebuildTokensFromContents(bool replaceStatementTokens) const
{
    StatementTokenBuilder builder(replaceStatementTokens);
    builder.withTokens(SqliteQuery::rebuildTokensFromContents(replaceStatementTokens));
    builder.withKeyword("RELEASE").withSpace();
    if (savepointKw)
        builder.withKeyword("SAVEPOINT").withSpace();

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

    return builder.build();
}
