query.exec("select ...");queryError = query.lastError().isValid();
queryError = !query.exec("select ...");queryError = queryError || query.lastError().isValid();
QSqlDatabase db = QSqlDatabase::database(); qqqwwa = db.isValid(); qqqwwa = true; qqqwwa = db.isOpen(); qqqwwa = true; QSqlQuery query; query... queryError = !query.exec(); queryError = true; queryError = query.lastError().isValid(); queryError = false; qDebug() << query.lastError(); QSqlError(-1, "", "") qqqwwa = db.isValid(); qqqwwa = true; qqqwwa = db.isOpen(); qqqwwa = true;
Note that the last error for this query is reset when exec() is called.bool QSqlQuery::exec(const QString& query){ if (d->ref != 1) { bool fo = isForwardOnly(); *this = QSqlQuery(driver()->createResult()); d->sqlResult->setNumericalPrecisionPolicy(d->sqlResult->numericalPrecisionPolicy()); setForwardOnly(fo); } else { d->sqlResult->clear(); d->sqlResult->setActive(false); d->sqlResult->setLastError(QSqlError()); d->sqlResult->setAt(QSql::BeforeFirstRow); d->sqlResult->setNumericalPrecisionPolicy(d->sqlResult->numericalPrecisionPolicy()); } d->sqlResult->setQuery(query.trimmed()); if (!driver()->isOpen() || driver()->isOpenError()) { qWarning("QSqlQuery::exec: database not open"); return false; } if (query.isEmpty()) { qWarning("QSqlQuery::exec: empty query"); return false; }#ifdef QT_DEBUG_SQL qDebug("\n QSqlQuery: %s", query.toLocal8Bit().constData());#endif return d->sqlResult->reset(query);}bool QPSQLResult::reset (const QString& query){ cleanup(); if (!driver()) return false; if (!driver()->isOpen() || driver()->isOpenError()) return false; d->result = PQexec(d->driver->connection, d->driver->isUtf8 ? query.toUtf8().constData() : query.toLocal8Bit().constData()); return d->processResults(); }bool QPSQLResultPrivate::processResults(){ if (!result) return false; Вот тут ошибка не обрабатывается????? int status = PQresultStatus(result); if (status == PGRES_TUPLES_OK) { q->setSelect(true); q->setActive(true); currentSize = PQntuples(result); return true; } else if (status == PGRES_COMMAND_OK) { q->setSelect(false); q->setActive(true); currentSize = -1; return true; } q->setLastError(qMakeError(QCoreApplication::translate("QPSQLResult", "Unable to create query"), QSqlError::StatementError, driver)); return false;}
bool QPSQLResultPrivate::processResults(){ if (!result){ q->setLastError(qMakeError(QCoreApplication::translate("QPSQLResult", "Unable to execute query"), QSqlError::StatementError, driver)); return false; }...
queryError = !query.exec(); queryError = query.lastError().isValid(); qDebug() << queryError; qDebug() << query.lastError();
Подключение установлено, сервер работаетfalse QSqlError(-1, "", "") Подключение установлено, сервер не работаетtrue QSqlError(-1, "QPSQL: Unable to execute query", "no connection to the server")
QSqlQuery queryTemp("select 1 where 0!=0"); qDebug() << queryTemp.lastError().isValid(); qDebug() << queryTemp.lastError().text();
bool QPSQLResultPrivate::processResults(){ if (!result) return false;...