void OcCombinedModelFilter::setOrderBy(const QString &nOrderBy)
{
    if (nOrderBy != m_orderBy) {
        m_orderBy = nOrderBy;
        QLOG_DEBUG() << "Combined model filter: Changed order by to " << orderBy();
        setSorting();
        emit orderByChanged(orderBy());
    }
}
Esempio n. 2
0
/*!
    Returns the SQL \c SELECT statement used internally to populate
    the model. The statement includes the filter and the \c{ORDER BY}
    clause.

    \sa filter(), orderByClause()
*/
QString QSqlTableModel::selectStatement() const
{
    Q_D(const QSqlTableModel);
    QString query;
    if (d->tableName.isEmpty()) {
        d->error = QSqlError(QLatin1String("No table name given"), QString(),
                             QSqlError::StatementError);
        return query;
    }
    if (d->rec.isEmpty()) {
        d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(),
                             QSqlError::StatementError);
        return query;
    }

    query = d->db.driver()->sqlStatement(QSqlDriver::SelectStatement,
                                         d->tableName,
                                         d->rec,
                                         false);
    if (query.isEmpty()) {
        d->error = QSqlError(QLatin1String("Unable to select fields from table ") + d->tableName,
                             QString(), QSqlError::StatementError);
        return query;
    }
    if (!d->filter.isEmpty())
        query.append(QLatin1String(" WHERE ")).append(d->filter);
    QString orderBy(orderByClause());
    if (!orderBy.isEmpty())
        query.append(QLatin1Char(' ')).append(orderBy);

    return query;
}
void frmMainStateTable::sortIndexChanged(int index_)
{
    int columnID = ui->toolbarSortCmb->itemData(index_).toInt();
    switch(columnID)
    {
    case -1:
        m_settings.setViewableColumnsSorting(columnEnumValue(), QList<orderBy>());
        break;
    case -2:
        {
            frmSort f(m_settings.viewableColumnsSorting(columnEnumValue()), tableColumns(), static_cast<QWidget*>(this->parent()));
            if (f.exec())
                 m_settings.setViewableColumnsSorting(columnEnumValue(), f.getReturnValues());
            else
            {
                setSortDropDown();
                return;
            }
        }
        break;
    default:
        m_settings.setViewableColumnsSorting(columnEnumValue(), QList<orderBy>() << orderBy(columnID, orderBy::order_ascending));
        break;
    }
    setSortDropDown();
    static_cast<mpiViewModelBase*>(ui->table->model())->setColumnSort(m_settings.viewableColumnsSorting(columnEnumValue()));
}
Esempio n. 4
0
Query<IShow> Show::search( MediaLibraryPtr ml, const std::string& pattern,
                           const QueryParameters* params )
{
    std::string req = "FROM " + Show::Table::Name + " WHERE id_show IN"
            "(SELECT rowid FROM " + Show::Table::Name + "Fts WHERE " +
            Show::Table::Name + "Fts MATCH '*' || ? || '*')";
    return make_query<Show, IShow>( ml, "*", std::move( req ),
                                    orderBy( params ), pattern );
}
Esempio n. 5
0
void MainTest::selectPosts()
{
//    auto q = FROM(db.posts())
//        JOIN(Comment)
//        WHERE(Post::idField() == postId);
    auto q = db.posts()->createQuery();
    q->join(Post::commentsTable());
    q->orderBy(!Post::saveDateField() & Post::bodyField());
    q->setWhere(Post::idField() == postId);

    auto posts = q->toList();

    post = posts.at(0);
    post->setBody("");

    QTEST_ASSERT(posts.length() == 1);
    QTEST_ASSERT(posts.at(0)->comments()->length() == 3);
    QTEST_ASSERT(posts.at(0)->title() == "post title");

    QTEST_ASSERT(posts.at(0)->comments()->at(0)->message() == "comment #0");
    QTEST_ASSERT(posts.at(0)->comments()->at(1)->message() == "comment #1");
    QTEST_ASSERT(posts.at(0)->comments()->at(2)->message() == "comment #2");
    db.cleanUp();
}
#include "mainCorrelationModel.h"
#include <QColor>
#include <QVector>
#include <QPalette>
#include "functions.h"

const QList<orderBy> correlationRow::correlationOrder = QList<orderBy>()
                                                        << orderBy(correlationRow::row_ObjectType, orderBy::order_ascending)
                                                        << orderBy(correlationRow::row_Description, orderBy::order_ascending);

//enum {
//    row_ObjectType,
//    row_ID,
//    row_Description
//};

const QVariantList correlationRow::columnsType = QVariantList()
                                                 << QVariant(QVariant::Int)
                                                 << QVariant(QVariant::Int)
                                                 << QVariant(QVariant::String);

correlationRow::correlationRow(int type_, int id_, const QString &description_):
    baseRow(correlationOrder)
{
    //    row_ObjectType,
    values.append(type_);
    //    row_ID,
    values.append(id_);
    //    row_Description
    values.append(description_);
}
Esempio n. 7
0
void MainTest::select10NewstPosts()
{
    auto q = db.posts()->createQuery();
    q->orderBy(!Post::saveDateField());
    q->toList(10);
}
Esempio n. 8
0
void ASTSelectQuery::formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const
{
    frame.current_select = this;
    frame.need_parens = false;
    std::string indent_str = s.one_line ? "" : std::string(4 * frame.indent, ' ');

    if (with())
    {
        s.ostr << (s.hilite ? hilite_keyword : "") << indent_str << "WITH " << (s.hilite ? hilite_none : "");
        s.one_line
            ? with()->formatImpl(s, state, frame)
            : with()->as<ASTExpressionList &>().formatImplMultiline(s, state, frame);
        s.ostr << s.nl_or_ws;
    }

    s.ostr << (s.hilite ? hilite_keyword : "") << indent_str << "SELECT " << (distinct ? "DISTINCT " : "") << (s.hilite ? hilite_none : "");

    s.one_line
        ? select()->formatImpl(s, state, frame)
        : select()->as<ASTExpressionList &>().formatImplMultiline(s, state, frame);

    if (tables())
    {
        s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "FROM " << (s.hilite ? hilite_none : "");
        tables()->formatImpl(s, state, frame);
    }

    if (prewhere())
    {
        s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "PREWHERE " << (s.hilite ? hilite_none : "");
        prewhere()->formatImpl(s, state, frame);
    }

    if (where())
    {
        s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "WHERE " << (s.hilite ? hilite_none : "");
        where()->formatImpl(s, state, frame);
    }

    if (groupBy())
    {
        s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "GROUP BY " << (s.hilite ? hilite_none : "");
        s.one_line
            ? groupBy()->formatImpl(s, state, frame)
            : groupBy()->as<ASTExpressionList &>().formatImplMultiline(s, state, frame);
    }

    if (group_by_with_rollup)
        s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << (s.one_line ? "" : "    ") << "WITH ROLLUP" << (s.hilite ? hilite_none : "");

    if (group_by_with_cube)
        s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << (s.one_line ? "" : "    ") << "WITH CUBE" << (s.hilite ? hilite_none : "");

    if (group_by_with_totals)
        s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << (s.one_line ? "" : "    ") << "WITH TOTALS" << (s.hilite ? hilite_none : "");

    if (having())
    {
        s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "HAVING " << (s.hilite ? hilite_none : "");
        having()->formatImpl(s, state, frame);
    }

    if (orderBy())
    {
        s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "ORDER BY " << (s.hilite ? hilite_none : "");
        s.one_line
            ? orderBy()->formatImpl(s, state, frame)
            : orderBy()->as<ASTExpressionList &>().formatImplMultiline(s, state, frame);
    }

    if (limitByValue())
    {
        s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "LIMIT " << (s.hilite ? hilite_none : "");
        limitByValue()->formatImpl(s, state, frame);
        s.ostr << (s.hilite ? hilite_keyword : "") << " BY " << (s.hilite ? hilite_none : "");
        s.one_line
            ? limitBy()->formatImpl(s, state, frame)
            : limitBy()->as<ASTExpressionList &>().formatImplMultiline(s, state, frame);
    }

    if (limitLength())
    {
        s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "LIMIT " << (s.hilite ? hilite_none : "");
        if (limitOffset())
        {
            limitOffset()->formatImpl(s, state, frame);
            s.ostr << ", ";
        }
        limitLength()->formatImpl(s, state, frame);
    }

    if (settings())
    {
        s.ostr << (s.hilite ? hilite_keyword : "") << s.nl_or_ws << indent_str << "SETTINGS " << (s.hilite ? hilite_none : "");
        settings()->formatImpl(s, state, frame);
    }
}
Esempio n. 9
0
Query<IShow> Show::listAll( MediaLibraryPtr ml, const QueryParameters* params )
{
    std::string req = "FROM " + Show::Table::Name;
    return make_query<Show, IShow>( ml, "*", std::move( req ), orderBy( params ) );
}