From 064383eba647c2729e283f68db2394cb6a8df0c3 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Wed, 4 Nov 2009 13:23:58 +1000 Subject: Fixed lastError() for QTDS driver. Previously, no lastError was available on syntax errors, bad column names, etc. Merge-request: 1987 Reviewed-by: Bill King --- src/sql/drivers/tds/qsql_tds.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/sql/drivers/tds/qsql_tds.cpp b/src/sql/drivers/tds/qsql_tds.cpp index 2508833..ca1502c 100644 --- a/src/sql/drivers/tds/qsql_tds.cpp +++ b/src/sql/drivers/tds/qsql_tds.cpp @@ -164,13 +164,13 @@ Q_GLOBAL_STATIC(QTDSErrorHash, errs) extern "C" { static int CS_PUBLIC qTdsMsgHandler (DBPROCESS* dbproc, - DBINT /*msgno*/, + DBINT msgno, int msgstate, int severity, char* msgtext, - char* /*srvname*/, + char* srvname, char* /*procname*/, - int /*line*/) + int line) { QTDSResultPrivate* p = errs()->value(dbproc); @@ -181,9 +181,20 @@ static int CS_PUBLIC qTdsMsgHandler (DBPROCESS* dbproc, } if (severity > 0) { - QString errMsg = QString::fromLatin1("%1 (%2)").arg(QString::fromAscii(msgtext)).arg( - msgstate); + QString errMsg = QString::fromLatin1("%1 (Msg %2, Level %3, State %4, Server %5, Line %6)") + .arg(QString::fromAscii(msgtext)) + .arg(msgno) + .arg(severity) + .arg(msgstate) + .arg(QString::fromAscii(srvname)) + .arg(line); p->addErrorMsg(errMsg); + if (severity > 10) { + // Severe messages are really errors in the sense of lastError + errMsg = p->getErrorMsgs(); + p->lastError = qMakeError(errMsg, QSqlError::UnknownError, msgno); + p->clearErrorMsgs(); + } } return INT_CANCEL; -- cgit v0.12