hollyberry
23rd April 2012, 19:56
I realize my problem would be solved by creating a view in the database that I could set to my QSqlQueryModel. Unfortunately, I do not have the permissions to create a view. I also realize my problem could be solved by simply creating a longer SELECT query; unfortunately, the database (disgustingly inefficient design) cannot handle the length of query I need to execute.
My solution is to create multiple queries that will run one at a time. Then I would like to use QSqlQueryModel to put all the information together and in a QTableView. Is this possible? Can I use more than one query in the QSqlQueryModel?
Here is the code for one query that I know works. I just have 8 more queries like it that need to be in the same table:
QSqlQueryModel *model = new QSqlQueryModel;
model->setData ("SELECT props.number, props.sample, props.top, props.bottom, AVG(ds.magn), MEDIAN(TO_NUMBER(ds.magn)) FROM ds JOIN props ON props.number = ds.number WHERE ds.cd BETWEEN props.top AND props.bottom GROUP BY props.number, props.cnumber, props.sample, props.top, props.bottom HAVING props.number = 11 ORDER BY TO_NUMBER(props.cnumber) desc, TO_NUMBER(props.sample) desc");
if (model->lastError().isValid())
qDebug() << model->lastError();
else qDebug() << "success!";
model->setHeaderData(0, Qt::Horizontal, QObject::tr("CNumber"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Sample"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Top"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("Bottom"));
model->setHeaderData(4, Qt::Horizontal, QObject::tr("Mean Magnectic"));
model->setHeaderData(5, Qt::Horizontal, QObject::tr("Median Magnectic"));
QTableView *view = new QTableView;
view->setModel(model);
view->show();
Thank you for any assistance!
My solution is to create multiple queries that will run one at a time. Then I would like to use QSqlQueryModel to put all the information together and in a QTableView. Is this possible? Can I use more than one query in the QSqlQueryModel?
Here is the code for one query that I know works. I just have 8 more queries like it that need to be in the same table:
QSqlQueryModel *model = new QSqlQueryModel;
model->setData ("SELECT props.number, props.sample, props.top, props.bottom, AVG(ds.magn), MEDIAN(TO_NUMBER(ds.magn)) FROM ds JOIN props ON props.number = ds.number WHERE ds.cd BETWEEN props.top AND props.bottom GROUP BY props.number, props.cnumber, props.sample, props.top, props.bottom HAVING props.number = 11 ORDER BY TO_NUMBER(props.cnumber) desc, TO_NUMBER(props.sample) desc");
if (model->lastError().isValid())
qDebug() << model->lastError();
else qDebug() << "success!";
model->setHeaderData(0, Qt::Horizontal, QObject::tr("CNumber"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Sample"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Top"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("Bottom"));
model->setHeaderData(4, Qt::Horizontal, QObject::tr("Mean Magnectic"));
model->setHeaderData(5, Qt::Horizontal, QObject::tr("Median Magnectic"));
QTableView *view = new QTableView;
view->setModel(model);
view->show();
Thank you for any assistance!