ajg85
6th April 2010, 19:29
EDIT: The skinny version is I need to know if this is supported with freeTDS ODBC drivers. If not I'd appreciate any open source unix ODBC driver recommendation that will play nice with QT :cool:
First I'm using QT 4.6.2 on Ubuntu. My test app connects through freeTDS odbc to a SQL Server Express instance running on a Windows 7 machine. Now I can connect and run queries just fine with this setup under normal circumstances using QT.
I recently decided to play with using QSqlTableModel to display the results of a query in a QTableView however I ran into some odd behavior. It appears the select() method is failing because the query syntax is incorrect. The query appears to be missing the column names which means the setTable method failed to retrieve the field information correctly although it does seem to know there are 3 columns in the table judging by the commas generated despite the empty strings.
Code Snippet:
void MainWindow::on_pbFetch_clicked()
{
//ZDataTable* results = new ZDataTable(myDB->FetchSQL(ui->txtQuery->toPlainText()));
// TEST CASE
QSqlTableModel* results = new QSqlTableModel(this, *myDB);
results->setTable("SystemConfig"); // fails to get fields correctly
results->setEditStrategy(QSqlTableModel::OnManualSubmit);
if (!results->select())
{
QMessageBox::critical(this, "Error", results->lastError().text());
QMessageBox::information(this, "Query", results->query().lastQuery());
}
results->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
results->setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
results->setHeaderData(2, Qt::Horizontal, QObject::tr("Value"));
QTableView* view = InitDBView(results);
view->show();
// END TEST CASE
}
QTableView* MainWindow::InitDBView(QSqlTableModel* model)
{
QTableView* view = new QTableView;
view->setModel(model);
view->setWindowTitle("Result Table");
return view;
}
Here is the screen cap of the message boxes from above showing the error and the attempted query:
http://img210.imageshack.us/img210/5465/captureerror.png
http://img541.imageshack.us/img541/3275/capturequery.png
My question is this a limitation because I'm using SQL Server Express through ODBC, a bug with QT, or something I'm doing wrong in my code?
First I'm using QT 4.6.2 on Ubuntu. My test app connects through freeTDS odbc to a SQL Server Express instance running on a Windows 7 machine. Now I can connect and run queries just fine with this setup under normal circumstances using QT.
I recently decided to play with using QSqlTableModel to display the results of a query in a QTableView however I ran into some odd behavior. It appears the select() method is failing because the query syntax is incorrect. The query appears to be missing the column names which means the setTable method failed to retrieve the field information correctly although it does seem to know there are 3 columns in the table judging by the commas generated despite the empty strings.
Code Snippet:
void MainWindow::on_pbFetch_clicked()
{
//ZDataTable* results = new ZDataTable(myDB->FetchSQL(ui->txtQuery->toPlainText()));
// TEST CASE
QSqlTableModel* results = new QSqlTableModel(this, *myDB);
results->setTable("SystemConfig"); // fails to get fields correctly
results->setEditStrategy(QSqlTableModel::OnManualSubmit);
if (!results->select())
{
QMessageBox::critical(this, "Error", results->lastError().text());
QMessageBox::information(this, "Query", results->query().lastQuery());
}
results->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
results->setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
results->setHeaderData(2, Qt::Horizontal, QObject::tr("Value"));
QTableView* view = InitDBView(results);
view->show();
// END TEST CASE
}
QTableView* MainWindow::InitDBView(QSqlTableModel* model)
{
QTableView* view = new QTableView;
view->setModel(model);
view->setWindowTitle("Result Table");
return view;
}
Here is the screen cap of the message boxes from above showing the error and the attempted query:
http://img210.imageshack.us/img210/5465/captureerror.png
http://img541.imageshack.us/img541/3275/capturequery.png
My question is this a limitation because I'm using SQL Server Express through ODBC, a bug with QT, or something I'm doing wrong in my code?