本文整理汇总了C++中QSqlError::number方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlError::number方法的具体用法?C++ QSqlError::number怎么用?C++ QSqlError::number使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlError
的用法示例。
在下文中一共展示了QSqlError::number方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handle
SErrorPackage PostgresErrorHandler::handle(const QSqlError &error)
{
// new row for relation "doms_persons" violates check constraint doms_persons_email_check
// insert or update on table "doms_pacients" violates foreign key constraint "doms_pacients_iddocument_fkey"
QString text = error.databaseText().toLower();
if ( text.contains("duplicate key") )
{
SErrorPackage package(error.number(), QObject::tr("Seems like pacients already exists"));
return package;
}
else if ( text.contains("syntax error") )
{
SErrorPackage package(error.number(), QObject::tr("You're trying to do an invalid action"));
return package;
}
SErrorPackage package(error.number(), QObject::tr("PostgresErrorHandler %1").arg(error.databaseText()));
// TODO: Analizar los textos!
return package;
}
示例2: openDatabaseOrDie
void DbFunc::openDatabaseOrDie(QSqlDatabase& db, const QString& filename)
{
// Opens a database.
QString dir = QStandardPaths::standardLocations(
QStandardPaths::AppDataLocation).first();
// Under Linux: ~/.local/share/camcops/
if (!QDir(dir).exists()) {
if (QDir().mkdir(dir)) {
qDebug() << "Made directory:" << dir;
} else {
UiFunc::stopApp("DbFunc::openDatabaseOrDie: Failed to make "
"directory: " + dir);
}
}
// http://stackoverflow.com/questions/3541529/is-there-qpathcombine-in-qt4
QString fullpath = QDir::cleanPath(dir + "/" + filename);
db.setDatabaseName(fullpath);
if (db.open()) {
qInfo() << "Opened database:" << fullpath;
} else {
QSqlError error = db.lastError();
qCritical() << "Last database error:" << error;
qCritical() << "Database:" << db;
QString errmsg = QString(
"DbFunc::openDatabaseOrDie: Error: connection to database failed. "
"Database = %1; error number = %2; error text = %3"
).arg(fullpath, QString::number(error.number()), error.text());
UiFunc::stopApp(errmsg);
}
}
示例3: logqmsg
bool DatabaseLogger::logqmsg(MSqlQuery &query, LoggingItem *item)
{
char timestamp[TIMESTAMP_MAX];
char *threadName = getThreadName(item);
strftime( timestamp, TIMESTAMP_MAX-8, "%Y-%m-%d %H:%M:%S",
(const struct tm *)&item->tm );
query.bindValue(":THREAD", threadName);
query.bindValue(":MSGTIME", timestamp);
query.bindValue(":LEVEL", item->level);
query.bindValue(":MESSAGE", item->message);
if (!query.exec())
{
// Suppress Driver not loaded errors that occur at startup.
// and suppress additional errors for one second after the
// previous error (to avoid spamming the log).
QSqlError err = query.lastError();
if ((err.type() != 1 || err.number() != -1) &&
(!m_errorLoggingTime.isValid() ||
(m_errorLoggingTime.elapsed() > 1000)))
{
MythDB::DBError("DBLogging", query);
m_errorLoggingTime.start();
}
return false;
}
deleteItem(item);
return true;
}
示例4:
QT_BEGIN_NAMESPACE
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const QSqlError &s)
{
dbg.nospace() << "QSqlError(" << s.number() << ", " << s.driverText() <<
", " << s.databaseText() << ')';
return dbg.space();
}
示例5: checkMySQLError
void checkMySQLError(QSqlQuery& q) {
QSqlError e = q.lastError();
if(!e.isValid())
return;//no error
qDebug()<<"got MySQL-Error"<<e.number()<<e.text()<<"/"<<e.databaseText()<<"/"<<e.driverText();
qDebug()<<"on query"<<q.lastQuery();
qDebug()<<"Terminating Application";
QCoreApplication::quit();
}
示例6: handleError
/**
* @brief Handle a SQL error if possible
* @param err error object to be handled
* @return true if the error was successfully handled, false if not
*/
bool dbcontroller::handleError(QSqlError err) {
switch (err.number()) {
case CR_SERVER_GONE_ERROR:
case CR_SERVER_LOST:
db.close();
db.open();
BOOSTER_INFO("scoreboard") << "Reopening connection to database.";
return true;
case -1:
BOOSTER_ERROR("scoreboard") << "Unknown DB error";
return false;
default:
BOOSTER_ERROR("scoreboard") << "Error from database: " << err.number() << " - " << err.text().toStdString();
return false;
}
}
示例7: checkDatabaseError
void checkDatabaseError(const QSqlDatabase &db) {
QSqlError lastError = db.lastError();
if (lastError.type() != QSqlError::NoError) {
#if QT_VERSION >= 0x050300
throw Exception { lastError.nativeErrorCode().toInt(), lastError.text().toStdString() };
#else
throw Exception { lastError.number(), lastError.text().toStdString() };
#endif
}
}
示例8: DBErrorMessage
QString MythDB::DBErrorMessage(const QSqlError& err)
{
if (!err.type())
return "No error type from QSqlError? Strange...";
return QString("Driver error was [%1/%2]:\n"
"%3\n"
"Database error was:\n"
"%4\n")
.arg(err.type())
.arg(err.number())
.arg(err.driverText())
.arg(err.databaseText());
}
示例9: createResearch
//------------------------------------------------------------------------------
bool ResearchCreationDialog::createResearch()
{
mResearchModel->insertRow(mResearchModel->rowCount());
qint32 row = mResearchModel->rowCount() - 1;
if (!mResearchModel->setData(mResearchModel->index(row, 1),
mUi->nameLineEdit->text())) {
QSqlError lastError = mResearchModel->lastError();
QString text(tr("Cannot insert the values in the model!\nError code: %1\nError text: %2")
.arg(QString::number(lastError.number()), lastError.text()));
QMessageBox::warning(this, tr("Error"), text);
return false;
}
mResearchModel->submitAll();
return true;
}
示例10: lastError
QVariantMap XSqlQueryProto::lastError()
{
QVariantMap m;
XSqlQuery *item = qscriptvalue_cast<XSqlQuery*>(thisObject());
if (item)
{
QSqlError err = item->lastError();
m.insert("databaseText", err.databaseText());
m.insert("driverText", err.driverText());
m.insert("text", err.text());
m.insert("number", err.number());
m.insert("type", err.type());
m.insert("isValid", QVariant(err.isValid()));
}
return m;
}
示例11: logqmsg
/// \brief Actually insert a log message from the queue into the database
/// \param query The database insert query to use
/// \param item LoggingItem containing the log message to insert
bool DatabaseLogger::logqmsg(MSqlQuery &query, LoggingItem *item)
{
char timestamp[TIMESTAMP_MAX];
time_t epoch = item->epoch();
struct tm tm;
localtime_r(&epoch, &tm);
strftime(timestamp, TIMESTAMP_MAX-8, "%Y-%m-%d %H:%M:%S",
(const struct tm *)&tm);
query.bindValue(":TID", item->tid());
query.bindValue(":THREAD", item->threadName());
query.bindValue(":FILENAME", item->file());
query.bindValue(":LINE", item->line());
query.bindValue(":FUNCTION", item->function());
query.bindValue(":MSGTIME", timestamp);
query.bindValue(":LEVEL", item->level());
query.bindValue(":MESSAGE", item->message());
query.bindValue(":APP", item->appName());
query.bindValue(":PID", item->pid());
if (!query.exec())
{
// Suppress Driver not loaded errors that occur at startup.
// and suppress additional errors for one second after the
// previous error (to avoid spamming the log).
QSqlError err = query.lastError();
if ((err.type() != 1 || err.number() != -1) &&
(!m_errorLoggingTime.isValid() ||
(m_errorLoggingTime.elapsed() > 1000)))
{
MythDB::DBError("DBLogging", query);
m_errorLoggingTime.start();
}
return false;
}
return true;
}
示例12: handle
//.........这里部分代码省略.........
//
// if("ERROR: llave duplicada viola restricción unique \"adscheduleav_pkey\""==error.databaseText())
// {
// mensaje = "El horario que usted ha intentado ingresar ya existe";
// }
//
//
// if("ERROR: el nuevo registro para la relación \"adscheduleav\" viola la restricción check \"$1\""==error.databaseText())
// {
// mensaje = "La fecha no es congruente";
// }
//
//
//
// if("ERROR: inserción o actualización en la tabla \"adschedulespace\" viola la llave foránea \"$2\""==error.databaseText())
// {
// mensaje = "El espacio no existe";
// }
//
//
// if("ERROR: llave duplicada viola restricción unique \"adschedulespace_pkey\""==error.databaseText())
// {
// mensaje = "El horario que usted ha intentado ingresar ya existe";
// }
//
//
// if("ERROR: el nuevo registro para la relación \"adschedulespace\" viola la restricción check \"$1\""==error.databaseText())
// {
// mensaje = "La fecha no es congruente";
// }
//
//
//
//
// if("ERROR: inserción o actualización en la tabla \"adspacereserve\" viola la llave foránea \"$1\""==error.databaseText())
// {
// mensaje = "El usuario no existe";
// }
//
// if("ERROR: inserción o actualización en la tabla \"adspacereserve\" viola la llave foránea \"$2\""==error.databaseText())
// {
// mensaje = "El espacio no existe";
// }
//
//
// if("ERROR: inserción o actualización en la tabla \"adspacereserve\" viola la llave foránea \"$3\""==error.databaseText())
// {
// mensaje = "El horario asociado al espacio no existe";
// }
//
//
// if("ERROR: llave duplicada viola restricción unique \"adspacereserve_pkey\""==error.databaseText())
// {
// mensaje = "La reserva ya existe";
// }
//
// if("ERROR: inserción o actualización en la tabla \"adavreserve\" viola la llave foránea \"$1\""==error.databaseText())
// {
// mensaje = "El usuario no existe";
// }
//
//
// if("ERROR: inserción o actualización en la tabla \"adavreserve\" viola la llave foránea \"$2\""==error.databaseText())
// {
// mensaje = "La ayuda audiovisual no existe";
// }
//
//
// if("ERROR: inserción o actualización en la tabla \"adavreserve\" viola la llave foránea \"$3\""==error.databaseText())
// {
// mensaje = "El horario asociado a la ayuda audiovisual no existe";
// }
//
//
// if("ERROR: llave duplicada viola restricción unique \"adavreserve_pkey\""==error.databaseText())
// {
// mensaje = "La reserva ya existe";
// }
//
// QRegExp rg;
//
//
// rg.setPattern ( "ERROR: la sintaxis de entrada no es válida para integer: \"*\"" );
// if(rg.exactMatch ( error.databaseText() ))
// {
// QStringList list = error.databaseText().split( '\"' );
// mensaje = "El valor "+list[1]+" debe ser numerico";
// }
//
// TODO: Analizar los textos!
SErrorPackage package(error.number(), QObject::tr("PostgresErrorHandler %1").arg(error.databaseText()));
// SErrorPackage package(error.number(), QObject::tr("PostgresErrorHandler %1").arg(mensaje));
return package;
}
示例13: logSQLError
static void logSQLError(const QSqlQuery &query) {
const QSqlError error(query.lastQuery());
qWarning() << "SQL Query failed" << query.lastQuery();
qWarning() << error.number() << query.lastError().text();
}
示例14:
void LeechCraft::Util::DBLock::DumpError (const QSqlError& lastError)
{
qWarning () << lastError.text () << "|"
<< lastError.type () << "|"
<< lastError.number ();
}
示例15: create
void IndexDialog::create()
{
if(!create_flag){
close();
return;
}
QString unique;
if(ckUnique->isChecked())
{
unique = QString("unique");
}
else
{
unique = QString();
}
QString iname = txtName->text();
QString collist;
int row_count = tbColumnList->rowCount();
int selected_count=0;
for(int i=0;i<row_count;i++){
QTableWidgetItem *item = tbColumnList->item(i,0);
bool isSelected = item->data(Qt::EditRole).toBool();
if(isSelected){
QString col;
if(tbColumnList->item(i,2)->text().isEmpty()){
col = QString("%1 %3")
.arg(tbColumnList->item(i,1)->text())
.arg(tbColumnList->item(i,3)->text());
}else{
col = QString("%1 Collate%2 %3")
.arg(tbColumnList->item(i,1)->text())
.arg(tbColumnList->item(i,2)->text())
.arg(tbColumnList->item(i,3)->text());
}
collist.append(col.trimmed());
collist.append(",");
selected_count ++;
}
}
if(selected_count>0){
collist = collist.left(collist.length()-1);
}
QString sql = QString("create %1 index if not exists %2 on %3(%4)")
.arg(unique).arg(iname).arg(tbname).arg(collist);
qDebug()<<sql;
QSqlDatabase db = QSqlDatabase::database(conname);
QSqlQuery q(db);
if(q.exec(sql)){
MainWindow *mw = qobject_cast<MainWindow*>(qApp->activeWindow());
if(mw!=0)mw->refresh(conname);
}else{
QSqlError se = q.lastError();
QString err = QString(
"database:%1\ndriver:%2\nerror number:%3"
"\nerror type:%4\nerror text:%5")
.arg(se.databaseText())
.arg(se.driverText())
.arg(se.number())
.arg(se.type()).arg(se.text());
QMessageBox::warning(this,QString("创建错误"),err);
}
close();
}