51 #include "private/qsqlnulldriver_p.h" 287 qInit(
this, query, db);
325 if (
d->sqlResult->isActive() &&
d->sqlResult->isValid())
326 return d->sqlResult->isNull(field);
358 bool fo = isForwardOnly();
359 *
this =
QSqlQuery(driver()->createResult());
360 d->sqlResult->setNumericalPrecisionPolicy(
d->sqlResult->numericalPrecisionPolicy());
363 d->sqlResult->clear();
364 d->sqlResult->setActive(
false);
367 d->sqlResult->setNumericalPrecisionPolicy(
d->sqlResult->numericalPrecisionPolicy());
369 d->sqlResult->setQuery(query.
trimmed());
370 if (!driver()->isOpen() || driver()->isOpenError()) {
371 qWarning(
"QSqlQuery::exec: database not open");
375 qWarning(
"QSqlQuery::exec: empty query");
381 return d->sqlResult->reset(query);
406 return d->sqlResult->data(index);
407 qWarning(
"QSqlQuery::value: not positioned on a valid record");
422 return d->sqlResult->at();
434 return d->sqlResult->lastQuery();
443 return d->sqlResult->driver();
504 if (!isSelect() || !isActive())
524 d->sqlResult->fetchLast();
531 if ((
at() + index) < 0) {
540 if (isForwardOnly() && actualIdx <
at()) {
541 qWarning(
"QSqlQuery::seek: cannot seek backwards in a forward only query");
545 if (!
d->sqlResult->fetchNext()) {
551 if (actualIdx == (
at() - 1)) {
552 if (!
d->sqlResult->fetchPrevious()) {
558 if (!
d->sqlResult->fetch(actualIdx)) {
596 if (!isSelect() || !isActive())
601 b =
d->sqlResult->fetchFirst();
606 if (!
d->sqlResult->fetchNext()) {
645 if (!isSelect() || !isActive())
647 if (isForwardOnly()) {
648 qWarning(
"QSqlQuery::seek: cannot seek backwards in a forward only query");
657 b =
d->sqlResult->fetchLast();
660 if (!
d->sqlResult->fetchPrevious()) {
680 if (!isSelect() || !isActive())
683 qWarning(
"QSqlQuery::seek: cannot seek backwards in a forward only query");
687 b =
d->sqlResult->fetchFirst();
705 if (!isSelect() || !isActive())
708 b =
d->sqlResult->fetchLast();
727 return d->sqlResult->size();
743 return d->sqlResult->numRowsAffected();
756 return d->sqlResult->lastError();
766 return d->sqlResult->isValid();
787 return d->sqlResult->isActive();
797 return d->sqlResult->isSelect();
808 return d->sqlResult->isForwardOnly();
837 d->sqlResult->setForwardOnly(forward);
863 for (
int i = 0; i < rec.
count(); ++i)
876 *
this =
QSqlQuery(driver()->createResult());
906 bool fo = isForwardOnly();
907 *
this =
QSqlQuery(driver()->createResult());
909 d->sqlResult->setNumericalPrecisionPolicy(
d->sqlResult->numericalPrecisionPolicy());
911 d->sqlResult->setActive(
false);
914 d->sqlResult->setNumericalPrecisionPolicy(
d->sqlResult->numericalPrecisionPolicy());
917 qWarning(
"QSqlQuery::prepare: no driver");
920 if (!driver()->isOpen() || driver()->isOpenError()) {
921 qWarning(
"QSqlQuery::prepare: database not open");
925 qWarning(
"QSqlQuery::prepare: empty query");
931 return d->sqlResult->savePrepare(query);
945 d->sqlResult->resetBindCount();
947 if (
d->sqlResult->lastError().isValid())
950 return d->sqlResult->exec();
1007 return d->sqlResult->execBatch(mode == ValuesAsColumns);
1034 d->sqlResult->bindValue(placeholder, val, paramType);
1045 d->sqlResult->bindValue(pos, val, paramType);
1062 d->sqlResult->addBindValue(val, paramType);
1072 return d->sqlResult->boundValue(placeholder);
1080 return d->sqlResult->boundValue(pos);
1102 for (
int i = 0; i <
values.count(); ++i)
1103 map[
d->sqlResult->boundValueName(i)] =
values.at(i);
1121 return d->sqlResult->executedQuery();
1150 return d->sqlResult->lastInsertId();
1176 d->sqlResult->setNumericalPrecisionPolicy(precisionPolicy);
1186 return d->sqlResult->numericalPrecisionPolicy();
1210 d->sqlResult->detachFromResultSet();
1211 d->sqlResult->setActive(
false);
1251 return d->sqlResult->nextResult();
The QVariant class acts like a union for the most common Qt data types.
The QSqlError class provides SQL database error information.
const QSqlDriver * driver() const
Returns the database driver associated with the query.
#define QT_END_NAMESPACE
This macro expands to.
bool first()
Retrieves the first record in the result, if available, and positions the query on the retrieved reco...
bool prepare(const QString &query)
Prepares the SQL query query for execution.
int numRowsAffected() const
Returns the number of rows affected by the result's SQL statement, or -1 if it cannot be determined...
The QAtomicInt class provides platform-independent atomic operations on integers. ...
~QSqlQuery()
Destroys the object and frees any allocated resources.
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const
Returns the current precision policy.
#define at(className, varName)
QSqlRecord record() const
Returns a QSqlRecord containing the field information for the current query.
void finish()
Instruct the database driver that no more data will be fetched from this query until it is re-execute...
bool isValid() const
Returns true if the QSqlDatabase has a valid driver.
The QSqlQuery class provides a means of executing and manipulating SQL statements.
bool previous()
Retrieves the previous record in the result, if available, and positions the query on the retrieved r...
QSqlQuery(QSqlResult *r)
Constructs a QSqlQuery object which uses the QSqlResult result to communicate with a database...
The QSqlDatabase class represents a connection to a database.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QSqlRecord class encapsulates a database record.
bool ref()
Atomically increments the value of this QAtomicInt.
The QSqlDriver class is an abstract base class for accessing specific SQL databases.
The QString class provides a Unicode character string.
Q_GLOBAL_STATIC_WITH_ARGS(QSqlNullResult, nullResult,(nullDriver())) QSqlQueryPrivate *QSqlQueryPrivate
bool isActive() const
Returns true if the query is active.
const QSqlResult * result() const
Returns the result associated with the query.
QSqlDriver * driver() const
Returns the database driver used to access the database connection.
QString lastQuery() const
Returns the text of the current query being used, or an empty string if there is no current query tex...
bool isSelect() const
Returns true if the current query is a SELECT statement; otherwise returns false. ...
Q_CORE_EXPORT void qDebug(const char *,...)
bool execBatch(BatchExecutionMode mode=ValuesAsRows)
Executes a previously prepared SQL query in a batch.
void clear()
Clears the result set and releases any resources held by the query.
QFuture< void > map(Sequence &sequence, MapFunction function)
#define QT_BEGIN_NAMESPACE
This macro expands to.
QVariant boundValue(const QString &placeholder) const
Returns the value for the placeholder.
QString trimmed() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QSqlDatabase database(const QString &connectionName=QLatin1String(defaultConnection), bool open=true)
Returns the database connection called connectionName.
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Q_CORE_EXPORT void qWarning(const char *,...)
bool last()
Retrieves the last record in the result, if available, and positions the query on the retrieved recor...
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
QString executedQuery() const
Returns the last query that was successfully executed.
void setForwardOnly(bool forward)
Sets forward only mode to forward.
virtual QSqlResult * createResult() const =0
Creates an empty SQL result on the database.
const char * constData() const
Returns a pointer to the data stored in the byte array.
bool exec()
Executes a previously prepared SQL query.
int count() const
Returns the number of fields in the record.
void addBindValue(const QVariant &val, QSql::ParamType type=QSql::In)
Adds the value val to the list of values when using positional value binding.
QSqlError lastError() const
Returns error information about the last error (if any) that occurred with this query.
QT_STATIC_CONST char * defaultConnection
void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy)
Instruct the database driver to return numerical values with a precision specified by precisionPolicy...
static QByteArray paramType(const QByteArray &ptype, bool *out)
static void qInit(QSqlQuery *q, const QString &query, QSqlDatabase db)
bool nextResult()
Discards the current result set and navigates to the next if available.
void qAtomicAssign(T *&d, T *x)
This is a helper for the assignment operators of implicitly shared classes.
QSqlQueryPrivate(QSqlResult *result)
static QSqlQueryPrivate * shared_null()
bool isForwardOnly() const
Returns true if you can only scroll forward through a result set; otherwise returns false...
void bindValue(const QString &placeholder, const QVariant &val, QSql::ParamType type=QSql::In)
Set the placeholder placeholder to be bound to value val in the prepared statement.
bool seek(int i, bool relative=false)
Retrieves the record at position index, if available, and positions the query on the retrieved record...
int size() const
Returns the size of the result (number of rows returned), or -1 if the size cannot be determined or i...
void setValue(int i, const QVariant &val)
Sets the value of the field at position index to val.
bool exec(const QString &query)
Executes the SQL in query.
QSqlQuery & operator=(const QSqlQuery &other)
Assigns other to this object.
bool isNull(int field) const
Returns true if the query is active and positioned on a valid record and the field is NULL; otherwise...
int at() const
Returns the current internal position of the query.
QVariant value(int i) const
Returns the value of field index in the current record.
bool next()
Retrieves the next record in the result, if available, and positions the query on the retrieved recor...
The QSqlResult class provides an abstract interface for accessing data from specific SQL databases...
QMap< QString, QVariant > boundValues() const
Returns a map of the bound values.
QVariant lastInsertId() const
Returns the object ID of the most recent inserted row if the database supports it.
bool isValid() const
Returns true if the query is currently positioned on a valid record; otherwise returns false...