I'm connecting to an MS SQL table (from Linux) using the Microsoft ODBC driver. Note that if "MyTable" points to a table with no spaces in the columns, everything is fine. For the other table (the one I need to be reading from) things go pear-shaped, around the time it gets to the first column with a space. The error I get out of lastError().text() is something like:
ERROR: [Microsoft][ODBC Driver 11 for SQL Server][SQL "U Max", "U Max_Inst", "U [Microsoft][ODBC Driver 11 for SQL Serve][SQL "U Max_I2", "U Max_I3 QODBC3: Unable to execute statement
I've definitely been given better errors in my life, but it's a least a hint.
Code:
SqlTableModel::SqlTableModel( QObject* parent, QSqlDatabase db ) : QSqlTableModel( parent, db )
{
}
auto SqlTableModel::initialize() -> void
{
if ( !database().open() ) {
QSqlError error = database().lastError();
std::cout << "ERROR: Couldn't open database: " << error.text().toStdString() << std::endl;
return;
}
getRows();
}
auto SqlTableModel::getRows() -> void
{
setTable( "MyTable" );
if ( select() ) {
std::cout << "selected returned true." << std::endl;
} else {
std::cout << "failed to select" << std::endl;
std::cout << "ERROR: " << lastError().text().toStdString() << std::endl;
}
}
If I wanted to try to work around this and manually select only certain columns from the table (IE, with a query) do I need to do so with a QSqlQueryModel and then call setData() for each adjacent record?