All pastes #174299 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-09-17 20:06 UTC
rendered paste body
void
QueryBuilder::buildQuery()
{
    if ( m_query.isEmpty() )
    {
        linkTables( m_linkTables );
        m_query = "SELECT " + m_values + " FROM " + m_tables + ' ' + m_join + " WHERE " + CollectionDB::instance()->boolT() + ' ' + m_where;
        if ( !m_showAll && ( m_linkTables & QueryBuilder::tabSong || m_linkTables & QueryBuilder::tabStats ) )
        {
            IdList list = MountPointManager::instance()->getMountedDeviceIds();
            QString deviceIds = "";
            //debug() << "number of device ids " << list.count() << endl;
            foreachType( IdList, list )
            {
                if ( it != list.begin() ) deviceIds += ',';
                deviceIds += QString::number( *it );
            }
            QString sql = " AND %1.deviceid IN (" + deviceIds + ")";
            if ( m_linkTables & QueryBuilder::tabSong )
                sql.arg( "tags" );
            else
                sql.arg( "statistics" );
            m_query += sql;
        }
        // GROUP BY must be before ORDER BY for sqlite
        // HAVING must be between GROUP BY and ORDER BY
        if ( !m_group.isEmpty() )  m_query += " GROUP BY " + m_group;
        if ( !m_having.isEmpty() ) m_query += " HAVING " + m_having;
        if ( !m_sort.isEmpty() )   m_query += " ORDER BY " + m_sort;
        m_query += m_limit;
        m_query += ";";
    }
}