QSqlError SQLconnector::initDb() { db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName( QDir::currentPath() + "/Data.sqlite" ); if (!db.open()) return db.lastError(); QStringList tables = db.tables(); if (tables.contains("Article", Qt::CaseInsensitive) && tables.contains("Magazine", Qt::CaseInsensitive) && tables.contains("LienTheme", Qt::CaseInsensitive)){ db.close(); return QSqlError(); } QSqlQuery q; if (!q.exec(QLatin1String("create table Article(id integer primary key, name varchar, description varchar,page integer, magazine integer)"))) return q.lastError(); if (!q.exec(QLatin1String("create table Magazine(id integer primary key, name varchar, numero integer)"))) return q.lastError(); if (!q.exec(QLatin1String("create table Theme(id integer primary key, name varchar, dependance integer)"))) return q.lastError(); if (!q.exec(QLatin1String("create table LienTheme(idArticle integer NOT NULL, idTheme integer NOT NULL, PRIMARY KEY ( idArticle, idTheme))"))) return q.lastError(); db.close(); return QSqlError(); }
/*! Returns the SQL \c SELECT statement used internally to populate the model. The statement includes the filter and the \c{ORDER BY} clause. \sa filter(), orderByClause() */ QString QSqlTableModel::selectStatement() const { Q_D(const QSqlTableModel); QString query; if (d->tableName.isEmpty()) { d->error = QSqlError(QLatin1String("No table name given"), QString(), QSqlError::StatementError); return query; } if (d->rec.isEmpty()) { d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), QSqlError::StatementError); return query; } query = d->db.driver()->sqlStatement(QSqlDriver::SelectStatement, d->tableName, d->rec, false); if (query.isEmpty()) { d->error = QSqlError(QLatin1String("Unable to select fields from table ") + d->tableName, QString(), QSqlError::StatementError); return query; } if (!d->filter.isEmpty()) query.append(QLatin1String(" WHERE ")).append(d->filter); QString orderBy(orderByClause()); if (!orderBy.isEmpty()) query.append(QLatin1Char(' ')).append(orderBy); return query; }
/*! Returns the SQL \c SELECT statement used internally to populate the model. The statement includes the filter and the \c{ORDER BY} clause. \sa filter(), orderByClause() */ QString QSqlTableModel::selectStatement() const { Q_D(const QSqlTableModel); if (d->tableName.isEmpty()) { d->error = QSqlError(QLatin1String("No table name given"), QString(), QSqlError::StatementError); return QString(); } if (d->rec.isEmpty()) { d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), QSqlError::StatementError); return QString(); } const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::SelectStatement, d->tableName, d->rec, false); if (stmt.isEmpty()) { d->error = QSqlError(QLatin1String("Unable to select fields from table ") + d->tableName, QString(), QSqlError::StatementError); return stmt; } return Sql::concat(Sql::concat(stmt, Sql::where(d->filter)), orderByClause()); }
bool AbstractDocument::isValidDocumentFromProvod() { if (lastError().isValid()) return false; if (_isProvod) { _error = QSqlError("transactDocument",tr("Документ уже проведен! ") ,QSqlError::UnknownError,100); return false; } QSqlQuery sql; sql.exec(QString("SELECT COUNT(*) FROM document_detail WHERE dd_doc = %1") .arg(_id)); if (!sql.next()) { _error = sql.lastError(); return false; } if (sql.value(0).toInt() == 0) { _error = QSqlError("transactDocument", tr("Нет позиций для проводки! "), QSqlError::UnknownError,100); return false; } return true; }
bool TSqlObject::remove() { syncToSqlRecord(); QString del = TActionContext::currentDatabase().driver()->sqlStatement(QSqlDriver::DeleteStatement, tableName(), *static_cast<QSqlRecord *>(this), false); if (del.isEmpty()) { sqlError = QSqlError(QLatin1String("Unable to delete row"), QString(), QSqlError::StatementError); return false; } del.append(" WHERE "); int revIndex = metaObject()->indexOfProperty(REVISION_PROPERTY_NAME); if (revIndex >= 0) { bool ok; int revsion = property(REVISION_PROPERTY_NAME).toInt(&ok); if (!ok || revsion <= 0) { sqlError = QSqlError(QLatin1String("Unable to convert the 'revision' property to an int"), QString(), QSqlError::UnknownError); tError("Unable to convert the 'revsion' property to an int, %s", qPrintable(objectName())); return false; } del.append(TSqlQuery::escapeIdentifier(REVISION_PROPERTY_NAME)); del.append("=").append(TSqlQuery::formatValue(revsion)); del.append(" AND "); } const char *pkName = metaObject()->property(metaObject()->propertyOffset() + primaryKeyIndex()).name(); if (primaryKeyIndex() < 0 || !pkName) { QString msg = QString("Not found the primary key for table ") + tableName(); sqlError = QSqlError(msg, QString(), QSqlError::StatementError); tError("%s", qPrintable(msg)); return false; } del.append(TSqlQuery::escapeIdentifier(pkName)); del.append("=").append(TSqlQuery::formatValue(property(pkName))); tSystemDebug("SQL statement: %s", qPrintable(del)); QSqlQuery query(TActionContext::currentDatabase()); bool res = query.exec(del); sqlError = query.lastError(); if (!res) { tSystemError("SQL delete error: %s", qPrintable(sqlError.text())); return false; } // Optimistic lock check if (query.numRowsAffected() != 1) { if (revIndex >= 0) { QString msg = QString("Row was updated or deleted from table ") + tableName() + QLatin1String(" by another transaction"); sqlError = QSqlError(msg, QString(), QSqlError::UnknownError); throw SqlException(msg, __FILE__, __LINE__); } tWarn("Row was deleted by another transaction, %s", qPrintable(tableName())); } clear(); return true; }
/*! Resets the model and sets the data provider to be the given \a query. Note that the query must be active and must not be isForwardOnly(). lastError() can be used to retrieve verbose information if there was an error setting the query. \sa query(), QSqlQuery::isActive(), QSqlQuery::setForwardOnly(), lastError() */ void QSqlQueryModel::setQuery(const QSqlQuery &query) { Q_D(QSqlQueryModel); QSqlRecord newRec = query.record(); bool columnsChanged = (newRec != d->rec); bool hasQuerySize = query.driver()->hasFeature(QSqlDriver::QuerySize); bool hasNewData = (newRec != QSqlRecord()) || !query.lastError().isValid(); if (d->colOffsets.size() != newRec.count() || columnsChanged) d->initColOffsets(newRec.count()); bool mustClearModel = d->bottom.isValid(); if (mustClearModel) { d->atEnd = true; beginRemoveRows(QModelIndex(), 0, qMax(d->bottom.row(), 0)); d->bottom = QModelIndex(); } d->error = QSqlError(); d->query = query; d->rec = newRec; if (mustClearModel) endRemoveRows(); d->atEnd = false; if (columnsChanged && hasNewData) reset(); if (!query.isActive() || query.isForwardOnly()) { d->atEnd = true; d->bottom = QModelIndex(); if (query.isForwardOnly()) d->error = QSqlError(QLatin1String("Forward-only queries " "cannot be used in a data model"), QString(), QSqlError::ConnectionError); else d->error = query.lastError(); return; } QModelIndex newBottom; if (hasQuerySize && d->query.size() > 0) { newBottom = createIndex(d->query.size() - 1, d->rec.count() - 1); beginInsertRows(QModelIndex(), 0, qMax(0, newBottom.row())); d->bottom = createIndex(d->query.size() - 1, columnsChanged ? 0 : d->rec.count() - 1); d->atEnd = true; endInsertRows(); } else { newBottom = createIndex(-1, d->rec.count() - 1); } d->bottom = newBottom; queryChange(); // fetchMore does the rowsInserted stuff for incremental models fetchMore(); }
QSqlError user_manager::update(user_ptr p) { if (! p) { return QSqlError("cannot update user : invalid user (null pointer)", "", QSqlError::UnknownError); } if (p->id == 0) { return QSqlError("cannot update user : '******' is required", "", QSqlError::UnknownError); } if (p->first_name.trimmed().isEmpty()) { return QSqlError("cannot update user : '******' is required", "", QSqlError::UnknownError); } if (p->last_name.trimmed().isEmpty()) { return QSqlError("cannot update user : '******' is required", "", QSqlError::UnknownError); } if (! qx::dao::exist(p)) { return QSqlError("cannot update user : user doesn't exist in database", "", QSqlError::UnknownError); } return qx::dao::update(p); }
bool DataLayer::createnettable() { QSqlQuery query; query.exec(" CREATE TABLE network(selfId integer primary key, parentId integer, name varchar, type int)"); qDebug() << selfdb.databaseName() << selfdb.tables(); if(QSqlError().isValid()) { qDebug() << QSqlError(); return false; } return true; }
/** \fn DatabaseManager::insertDirToCollection(const QString& dir) * \brief Inserts the directory \var dir into the Collection table. */ QSqlError DatabaseManager::insertDirToCollection(const QString& dir) { QSqlQuery q; q.prepare("INSERT INTO Collection (directory) VALUES (?)"); q.bindValue(0, dir); if (!q.exec()) { if(q.lastError().type()==1 && q.lastError().text()=="constraint failed Unable to fetch row") return QSqlError(); throw(q.lastError()); // TODO handle this! } return QSqlError(); }
QSqlError DbConnection::connect(DbList &dblist) { assert(!dbuuid.isNull()); if (!QSqlDatabase::isDriverAvailable(dbparam.driver)) { QSqlError e = QSqlError("Could not connect to database", QString("Database driver %1 is not available.").arg(dbparam.driver), QSqlError::ConnectionError); dblist.tablelist_seterror(*this, e); return e; } db = QSqlDatabase::addDatabase(dbparam.driver, dbuuid); db.setHostName(dbparam.hostname); if (dbparam.port > 0) db.setPort(dbparam.port); db.setDatabaseName(dbparam.database); db.setUserName(dbparam.username); if (dbparam.askpassword) { bool ok; QString passwd = QInputDialog::getText(NULL, "QtSqlView Password Prompt", QString("Enter password for '%1':").arg(dbparam.label), QLineEdit::Password, QString::null, &ok); if (!ok) { QSqlError e = QSqlError("Could not connect to database", "Password prompt failed.", QSqlError::ConnectionError); dblist.tablelist_seterror(*this, e); return e; } } else { db.setPassword(dbparam.password); } if (!db.open()) { QSqlError e = db.lastError(); db = QSqlDatabase(); QSqlDatabase::removeDatabase(dbuuid); dblist.tablelist_seterror(*this, e); return e; } dblist.tablelist_load(*this); return QSqlError(); }
QSqlDatabase QrSqlDatabase::createDatabase(QSqlError &dbError) { QString connectionName_ = connectionName(); dbError = QSqlError(); dbFileIsCreated = false; qDebug() << "create database:" << getDatabasePath () << "," << connectionName_; if (! QrFiler::fileExists (getDatabasePath ())) { // qDebug() << "database path is not exist:" << getDatabasePath (); // dbError = QSqlError("'database file is not exist!'", "", QSqlError::ConnectionError); // Q_ASSERT(false); // return QrSqlDatabase::null; dbFileIsCreated = true; qDebug() << "database file is not exist, ready to creating..."; } const QrSqlDatabaseParams ¶ms = getParams (); Q_ASSERT(!params.driverName.isEmpty () && !params.databaseName.isEmpty ()); QSqlDatabase db = QSqlDatabase::addDatabase (params.driverName, connectionName_); db.setConnectOptions (params.connectOptions); db.setDatabaseName (getDatabasePath ()); db.setUserName (params.username); db.setPassword (params.password); db.setHostName (params.hostname); if (-1 != params.port){ db.setPort (params.port); } if (! db.open ()) { qDebug() << "fail to open database"; QrSqlDatabaseError::displayLastError (db, "unable to open connection to database"); dbError = db.lastError (); if (!dbError.isValid ()) { dbError = QSqlError("'unable to open connection to database'", "", QSqlError::UnknownError); } QSqlDatabase::removeDatabase (connectionName_); return QrSqlDatabase::null; } Qt::HANDLE curThreadIdHandle = QThread::currentThreadId (); listDbByThread.insert (curThreadIdHandle, connectionName_); QString curThreadId = QrStringCvter<Qt::HANDLE, QrIsPointer<Qt::HANDLE>::value>::toString (curThreadIdHandle); qDebug() << "create new database connection of " << params.databaseName << "in thread " << curThreadId << " with key " << connectionName_; return QSqlDatabase::database(connectionName_); }
/*! Deletes the given \a row from the currently active database table. This is a low-level method that operates directly on the database and should not be called directly. Use removeRow() or removeRows() to delete values. The model will decide depending on its edit strategy when to modify the database. Returns true if the row was deleted; otherwise returns false. \sa removeRow(), removeRows() */ bool QSqlTableModel::deleteRowFromTable(int row) { Q_D(QSqlTableModel); emit beforeDelete(row); const QSqlRecord whereValues = d->strategy == OnManualSubmit ? d->cache[row].primaryValues : d->primaryValues(row); bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); QString stmt = d->db.driver()->sqlStatement(QSqlDriver::DeleteStatement, d->tableName, QSqlRecord(), prepStatement); QString where = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement, d->tableName, whereValues, prepStatement); if (stmt.isEmpty() || where.isEmpty()) { d->error = QSqlError(QLatin1String("Unable to delete row"), QString(), QSqlError::StatementError); return false; } stmt.append(QLatin1Char(' ')).append(where); return d->exec(stmt, prepStatement, QSqlRecord() /* no new values */, whereValues); }
static QSqlError qMakeError(sqlite3 *access, const QString &descr, QSqlError::ErrorType type, int errorCode = -1) { return QSqlError(descr, QString::fromUtf16( (const ushort *) sqlite3_errmsg16(access) ), type, errorCode); }
QSqlError QrSqlHelper::call_query(QrSqlQuery &query, QSqlDatabase *database /* = nullptr */) { QSqlError dbError; if (dbError.isValid()) { return dbError; } QSqlQuery qQuery = QSqlQuery(*database); qQuery.setForwardOnly(true); QTime timeQuery; timeQuery.start (); qQuery.prepare (query.query ()); query.resolve(qQuery); if (! qQuery.exec ()) { qDebug() << "query exec fail, " << query.query (); return qQuery.lastError (); } query.resolveOutput(qQuery, true); int ms = timeQuery.elapsed (); // set is print sql query statement or not if (QrSqlConfig::getInstance ()->getTraceSqlQuery ()) { qDebug() << "custom sql query "<< "(" <<ms << " ms) : " << query.query () << " by " << database; } return QSqlError(); }
static QSqlError qMakeError(sqlite3 *access, const QString &descr, QSqlError::ErrorType type, int errorCode = -1) { return QSqlError(descr, stringFromUnicode(reinterpret_cast<const QChar *>(sqlite3_errmsg16(access))), type, errorCode); }
/*! Inserts new record into the database, based on the current properties of the object. */ bool TSqlObject::create() { // Sets the values of 'created_at', 'updated_at' or 'modified_at' properties for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); ++i) { const char *propName = metaObject()->property(i).name(); QByteArray prop = QByteArray(propName).toLower(); if (prop == CreatedAt || prop == UpdatedAt || prop == ModifiedAt) { setProperty(propName, QDateTime::currentDateTime()); } else if (prop == LockRevision) { // Sets the default value of 'revision' property setProperty(propName, 1); // 1 : default value } else { // do nothing } } syncToSqlRecord(); QString autoValName; QSqlRecord record = *this; if (autoValueIndex() >= 0) { autoValName = field(autoValueIndex()).name(); record.remove(autoValueIndex()); // not insert the value of auto-value field } QSqlDatabase &database = Tf::currentSqlDatabase(databaseId()); QString ins = database.driver()->sqlStatement(QSqlDriver::InsertStatement, tableName(), record, false); if (Q_UNLIKELY(ins.isEmpty())) { sqlError = QSqlError(QLatin1String("No fields to insert"), QString(), QSqlError::StatementError); tWarn("SQL statement error, no fields to insert"); return false; } TSqlQuery query(database); bool ret = query.exec(ins); sqlError = query.lastError(); if (Q_LIKELY(ret)) { // Gets the last inserted value of auto-value field if (autoValueIndex() >= 0) { QVariant lastid = query.lastInsertId(); if (!lastid.isValid() && database.driverName().toUpper() == QLatin1String("QPSQL")) { // For PostgreSQL without OIDS ret = query.exec("SELECT LASTVAL()"); sqlError = query.lastError(); if (Q_LIKELY(ret)) { lastid = query.getNextValue(); } } if (lastid.isValid()) { QObject::setProperty(autoValName.toLatin1().constData(), lastid); QSqlRecord::setValue(autoValueIndex(), lastid); } } } return ret; }
bool TSqlObject::create() { // Sets the default value of 'revision' property int index = metaObject()->indexOfProperty(REVISION_PROPERTY_NAME); if (index >= 0) { setProperty(REVISION_PROPERTY_NAME, 1); // 1 : default value } // Sets the values of 'created_at' and 'updated_at' properties for (int i = metaObject()->propertyOffset(); i < metaObject()->propertyCount(); ++i) { const char *propName = metaObject()->property(i).name(); if (QLatin1String("created_at") == propName || QLatin1String("updated_at") == propName) { setProperty(propName, QDateTime::currentDateTime()); } } syncToSqlRecord(); QString ins = TActionContext::currentDatabase().driver()->sqlStatement(QSqlDriver::InsertStatement, tableName(), *static_cast<QSqlRecord *>(this), false); if (ins.isEmpty()) { sqlError = QSqlError(QLatin1String("No fields to insert"), QString(), QSqlError::StatementError); tWarn("SQL statement error, no fields to insert"); return false; } tSystemDebug("SQL statement: %s", qPrintable(ins)); QSqlQuery query(TActionContext::currentDatabase()); bool res = query.exec(ins); sqlError = query.lastError(); if (!res) { tSystemError("SQL insert error: %s", qPrintable(sqlError.text())); } return res; }
/** \fn DatabaseManager::removeDirToCollection(const QString& dir) * \brief Removes the directory \var dir from the Collection table and all its content from the Media table. */ QSqlError DatabaseManager::removeDirToCollection(const QString& dir) { QSqlQuery q; // delete the info from imdb q.prepare("DELETE FROM ImdbInfo WHERE mediaId in (SELECT id FROM Media WHERE Media.fileName LIKE ?)"); q.bindValue(0, dir + '%'); if (!q.exec()) throw(q.lastError()); // TODO handle this! // delete the info media q.prepare("DELETE FROM Media WHERE fileName LIKE ?"); q.bindValue(0, dir + '%'); if (!q.exec()) throw(q.lastError()); // TODO handle this! // delete the directory q.prepare("DELETE FROM Collection WHERE directory = ?"); q.bindValue(0, dir); if (!q.exec()) throw(q.lastError()); // TODO handle this! return QSqlError(); }
bool XSqlQuery::exec() { qApp->setOverrideCursor(Qt::WaitCursor); bool returnValue = false; if(_data && _data->_emulatePrepare) { // In 4.4.1 Qt started supporting true prepared queries on the PostgreSQL driver and this // caused several problems with all our code and the way it worked so this is a modified copy // of their code to use the implemented prepare if we have that option set so we can use the method // that works best in the case we are using it for. if (lastError().isValid()) ((XSqlResultHelper*)result())->setLastError(QSqlError()); returnValue = ((XSqlResultHelper*)result())->XSqlResultHelper::exec(); } else returnValue = QSqlQuery::exec(); qApp->restoreOverrideCursor(); if (_data) _data->_currRecord = record(); if(false == returnValue) notifyErrorListeners(this); return returnValue; }
bool XSqlQuery::prepare(const QString &pSql) { bool ret; if(_data && _data->_emulatePrepare) { // In 4.4.1 Qt started supporting true prepared queries on the PostgreSQL driver and this // caused several problems with all our code and the way it worked so this is a modified copy // of their code to use the implemented prepare if we have that option set so we can use the method // that works best in the case we are using it for. ((XSqlResultHelper*)result())->setActive(false); ((XSqlResultHelper*)result())->setLastError(QSqlError()); ((XSqlResultHelper*)result())->setAt(QSql::BeforeFirstRow); if (!driver()) { qWarning("XSqlQuery::prepare: no driver"); return false; } if (!driver()->isOpen() || driver()->isOpenError()) { qWarning("XSqlQuery::prepare: database not open"); return false; } if (pSql.isEmpty()) { qWarning("XSqlQuery::prepare: empty query"); return false; } #ifdef QT_DEBUG_SQL qDebug("\n XSqlQuery::prepare: %s", query.toLocal8Bit().constData()); #endif ret = ((XSqlResultHelper*)result())->XSqlResultHelper::savePrepare(pSql); } else ret = QSqlQuery::prepare(pSql); if(ret && ((driver() && !driver()->hasFeature(QSqlDriver::PreparedQueries)) || (_data && _data->_emulatePrepare))) bindValue(":firstnullfix", QVariant()); return ret; }
QSqlError QSqlDatabaseProto::lastError() const { QSqlDatabase *item = qscriptvalue_cast<QSqlDatabase*>(thisObject()); if (item) return item->lastError(); return QSqlError(); }
static QSqlError qMakeError(sqlite3 *access, const QString &descr, QSqlError::ErrorType type, int errorCode = -1) { return QSqlError(descr, QString(reinterpret_cast<const QChar *>(sqlite3_errmsg16(access))), type, QString::number(errorCode)); }
/*! Deletes the given \a row from the currently active database table. This is a low-level method that operates directly on the database and should not be called directly. Use removeRow() or removeRows() to delete values. The model will decide depending on its edit strategy when to modify the database. Returns true if the row was deleted; otherwise returns false. \sa removeRow(), removeRows() */ bool QSqlTableModel::deleteRowFromTable(int row) { Q_D(QSqlTableModel); emit beforeDelete(row); QSqlRecord rec = d->primaryValues(row); bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); QString stmt = d->db.driver()->sqlStatement(QSqlDriver::DeleteStatement, d->tableName, QSqlRecord(), prepStatement); QString where = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement, d->tableName, rec, prepStatement); if (stmt.isEmpty() || where.isEmpty()) { d->error = QSqlError(QLatin1String("Unable to delete row"), QString(), QSqlError::StatementError); return false; } stmt.append(QLatin1Char(' ')).append(where); return d->exec(stmt, prepStatement, rec); }
/* SQLite dbs have no user name, passwords, hosts or ports. just file names. */ bool QSQLite2Driver::open(const QString & db, const QString &, const QString &, const QString &, int, const QString &) { if (isOpen()) close(); if (db.isEmpty()) return false; char* err = 0; d->access = sqlite_open(QFile::encodeName(db), 0, &err); if (err) { setLastError(QSqlError(tr("Error opening database"), QString::fromAscii(err), QSqlError::ConnectionError)); sqlite_freemem(err); err = 0; } if (d->access) { setOpen(true); setOpenError(false); return true; } setOpenError(true); return false; }
int database::queryProvider::select(abstractQuery* q,QList<int> order,Qt::SortOrder sortOrder ) { resultsList.clear(); _lastError=QSqlError(); return doSelect(q,order,sortOrder); }
/*! Prepares the SQL query \a query for execution. Returns true if the query is prepared successfully; otherwise returns false. The query may contain placeholders for binding values. Both Oracle style colon-name (e.g., \c{:surname}), and ODBC style (\c{?}) placeholders are supported; but they cannot be mixed in the same query. See the \l{QSqlQuery examples}{Detailed Description} for examples. Portability note: Some databases choose to delay preparing a query until it is executed the first time. In this case, preparing a syntactically wrong query succeeds, but every consecutive exec() will fail. For SQLite, the query string can contain only one statement at a time. If more than one statement is given, the function returns false. Example: \snippet sqldatabase/sqldatabase.cpp 9 \sa exec(), bindValue(), addBindValue() */ bool QSqlQuery::prepare(const QString& query) { if (d->ref.load() != 1) { bool fo = isForwardOnly(); *this = QSqlQuery(driver()->createResult()); setForwardOnly(fo); d->sqlResult->setNumericalPrecisionPolicy(d->sqlResult->numericalPrecisionPolicy()); } else { d->sqlResult->setActive(false); d->sqlResult->setLastError(QSqlError()); d->sqlResult->setAt(QSql::BeforeFirstRow); d->sqlResult->setNumericalPrecisionPolicy(d->sqlResult->numericalPrecisionPolicy()); } if (!driver()) { qWarning("QSqlQuery::prepare: no driver"); return false; } if (!driver()->isOpen() || driver()->isOpenError()) { qWarning("QSqlQuery::prepare: database not open"); return false; } if (query.isEmpty()) { qWarning("QSqlQuery::prepare: empty query"); return false; } #ifdef QT_DEBUG_SQL qDebug("\n QSqlQuery::prepare: %s", query.toLocal8Bit().constData()); #endif return d->sqlResult->savePrepare(query); }
static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type, const QPSQLDriverPrivate *p) { const char *s = PQerrorMessage(p->connection); QString msg = p->isUtf8 ? QString::fromUtf8(s) : QString::fromLocal8Bit(s); return QSqlError(QLatin1String("QPSQL: ") + err, msg, type); }
QSqlError XSqlTableModelProto::lastError() const { XSqlTableModel *item = qscriptvalue_cast<XSqlTableModel*>(thisObject()); if (item) return item->lastError(); return QSqlError(); }
static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type, const embeddedDriverPrivate* p) { const char *cerr = p->mysql ? mysql_error(p->mysql) : 0; return QSqlError(QLatin1String("embedded: ") + err, p->tc ? toUnicode(p->tc, cerr) : QString::fromLatin1(cerr), type, mysql_errno(p->mysql)); }
static QSqlError qMakeStmtError(const QString& err, QSqlError::ErrorType type, MYSQL_STMT* stmt) { const char *cerr = mysql_stmt_error(stmt); return QSqlError(QLatin1String("embedded3: ") + err, QString::fromLatin1(cerr), type, mysql_stmt_errno(stmt)); }