Exemplo n.º 1
0
void DatabaseQuery::runJoin() {
    qDebug() << "Run Join";
    if (m_results.count() == 2) {
        //qSort(m_results);
        DataStore firstBase = m_results.takeFirst();
        DataStore secondBase = m_results.takeFirst();

        if (firstBase.rowCount() > 0 && secondBase.rowCount() > 0) {
            // m_dataHeaders contains the imported salesforce IDs
            DataStore joinResult;
            joinResult.setHeader(firstBase.dataHeaders() + secondBase.dataHeaders().mid(1));
            joinResult.setTypes( firstBase.typeList() + secondBase.typeList().mid(1));
            QListIterator<QStringList> index(firstBase.dataList());
            for (int row = 0; index.hasNext(); row++) {
                QStringList list = index.next();
                if (! list.empty()) {
                    QStringList secondList = secondBase.dataHash()[list.first()].mid(1);
                    if (! secondList.isEmpty()) {
                        // m_dataHash will look up the imported salesforce IDs.
                        list += secondList;
                        joinResult.appendData(list);
                    }
                }
            }
            resultsReady(joinResult);
        }
    }
}