15#include "private/qsqlnulldriver_p.h"
33 static QSqlQueryPrivate* shared_null();
40QSqlQueryPrivate* QSqlQueryPrivate::shared_null()
42 QSqlQueryPrivate *null = nullQueryPrivate();
54 sqlResult = nullResult();
57QSqlQueryPrivate::~QSqlQueryPrivate()
60 if (!nr || sqlResult == nr)
206 d =
new QSqlQueryPrivate(
result);
215 if (
d && !
d->ref.deref())
219#if QT_DEPRECATED_SINCE(6, 2)
283 if (!
query.isEmpty())
297 d = QSqlQueryPrivate::shared_null();
310 d = QSqlQueryPrivate::shared_null();
326 return !
d->sqlResult->isActive()
327 || !
d->sqlResult->isValid()
328 ||
d->sqlResult->isNull(field);
351 return isNull(
index);
388 qCWarning(lcSqlQuery,
"QSqlQuery::exec: called before driver has been set up");
391 if (
d->ref.loadRelaxed() != 1) {
392 bool fo = isForwardOnly();
393 *
this =
QSqlQuery(driver()->createResult());
394 d->sqlResult->setNumericalPrecisionPolicy(
d->sqlResult->numericalPrecisionPolicy());
397 d->sqlResult->clear();
398 d->sqlResult->setActive(
false);
401 d->sqlResult->setNumericalPrecisionPolicy(
d->sqlResult->numericalPrecisionPolicy());
403 d->sqlResult->setQuery(
query.trimmed());
404 if (!driver()->isOpen() || driver()->isOpenError()) {
405 qCWarning(lcSqlQuery,
"QSqlQuery::exec: database not open");
408 if (
query.isEmpty()) {
409 qCWarning(lcSqlQuery,
"QSqlQuery::exec: empty query");
413 bool retval =
d->sqlResult->reset(
query);
415 qCDebug(lcSqlQuery()).nospace() <<
"Executed query (" <<
t.elapsed() <<
"ms, "
416 <<
d->sqlResult->size()
417 <<
" results, " <<
d->sqlResult->numRowsAffected()
418 <<
" affected): " <<
d->sqlResult->lastQuery();
446 qCWarning(lcSqlQuery,
"QSqlQuery::value: not positioned on a valid record");
486 return d->sqlResult->at();
498 return d->sqlResult->lastQuery();
507 return d->sqlResult->driver();
593 actualIdx =
index - 1;
600 d->sqlResult->fetchLast();
616 if (isForwardOnly() && actualIdx <
at()) {
617 qCWarning(lcSqlQuery,
"QSqlQuery::seek: cannot seek backwards in a forward only query");
621 if (!
d->sqlResult->fetchNext()) {
627 if (actualIdx == (
at() - 1)) {
628 if (!
d->sqlResult->fetchPrevious()) {
634 if (!
d->sqlResult->fetch(actualIdx)) {
677 return d->sqlResult->fetchFirst();
681 if (!
d->sqlResult->fetchNext()) {
722 if (isForwardOnly()) {
723 qCWarning(lcSqlQuery,
"QSqlQuery::seek: cannot seek backwards in a forward only query");
731 return d->sqlResult->fetchLast();
733 if (!
d->sqlResult->fetchPrevious()) {
756 qCWarning(lcSqlQuery,
"QSqlQuery::seek: cannot seek backwards in a forward only query");
759 return d->sqlResult->fetchFirst();
778 return d->sqlResult->fetchLast();
796 return d->sqlResult->size();
812 return d->sqlResult->numRowsAffected();
825 return d->sqlResult->lastError();
857 return d->sqlResult->isActive();
867 return d->sqlResult->isSelect();
877 return d->sqlResult->isForwardOnly();
921 d->sqlResult->setForwardOnly(forward);
960 *
this =
QSqlQuery(driver()->createResult());
991 if (
d->ref.loadRelaxed() != 1) {
992 bool fo = isForwardOnly();
993 *
this =
QSqlQuery(driver()->createResult());
995 d->sqlResult->setNumericalPrecisionPolicy(
d->sqlResult->numericalPrecisionPolicy());
997 d->sqlResult->setActive(
false);
1000 d->sqlResult->setNumericalPrecisionPolicy(
d->sqlResult->numericalPrecisionPolicy());
1003 qCWarning(lcSqlQuery,
"QSqlQuery::prepare: no driver");
1006 if (!driver()->isOpen() || driver()->isOpenError()) {
1007 qCWarning(lcSqlQuery,
"QSqlQuery::prepare: database not open");
1010 if (
query.isEmpty()) {
1011 qCWarning(lcSqlQuery,
"QSqlQuery::prepare: empty query");
1017 return d->sqlResult->savePrepare(
query);
1035 d->sqlResult->resetBindCount();
1037 if (
d->sqlResult->lastError().isValid())
1040 bool retval =
d->sqlResult->exec();
1042 qCDebug(lcSqlQuery).nospace() <<
"Executed prepared query (" <<
t.elapsed() <<
"ms, "
1043 <<
d->sqlResult->size() <<
" results, " <<
d->sqlResult->numRowsAffected()
1044 <<
" affected): " <<
d->sqlResult->lastQuery();
1098 d->sqlResult->resetBindCount();
1099 return d->sqlResult->execBatch(
mode == ValuesAsColumns);
1117 QSql::ParamType paramType
1120 d->sqlResult->bindValue(placeholder,
val, paramType);
1131 d->sqlResult->bindValue(
pos,
val, paramType);
1148 d->sqlResult->addBindValue(
val, paramType);
1158 return d->sqlResult->boundValue(placeholder);
1167 return d->sqlResult->boundValue(
pos);
1203 return d->sqlResult->boundValueNames();
1218 return d->sqlResult->boundValueName(
pos);
1235 return d->sqlResult->executedQuery();
1255 return d->sqlResult->lastInsertId();
1287 d->sqlResult->setNumericalPrecisionPolicy(precisionPolicy);
1295 return d->sqlResult->numericalPrecisionPolicy();
1319 d->sqlResult->setPositionalBindingEnabled(
enable);
1329 return d->sqlResult->isPositionalBindingEnabled();
1349 d->sqlResult->detachFromResultSet();
1350 d->sqlResult->setActive(
false);
1386 return d->sqlResult->nextResult();
1392#include "moc_qsqlquery.cpp"
void start() noexcept
\typealias QElapsedTimer::Duration Synonym for std::chrono::nanoseconds.
The QSqlDatabase class handles a connection to a database.
bool isValid() const
Returns true if the QSqlDatabase has a valid driver.
QSqlDriver * driver() const
Returns the database driver used to access the database connection.
static const char * defaultConnection
static QSqlDatabase database(const QString &connectionName=QLatin1StringView(defaultConnection), bool open=true)
\threadsafe
The QSqlDriver class is an abstract base class for accessing specific SQL databases.
virtual QSqlResult * createResult() const =0
Creates an empty SQL result on the database.
The QSqlError class provides SQL database error information.
bool isValid() const
Returns true if an error is set, otherwise false.
The QSqlQuery class provides a means of executing and manipulating SQL statements.
QSqlQuery & operator=(const QSqlQuery &other)=delete
bool next()
Retrieves the next record in the result, if available, and positions the query on the retrieved recor...
bool last()
Retrieves the last record in the result, if available, and positions the query on the retrieved recor...
const QSqlDriver * driver() const
Returns the database driver associated with the query.
bool previous()
Retrieves the previous record in the result, if available, and positions the query on the retrieved r...
QStringList boundValueNames() const
void finish()
Instruct the database driver that no more data will be fetched from this query until it is re-execute...
bool prepare(const QString &query)
Prepares the SQL query query for execution.
QVariant value(int i) const
Returns the value of field index in the current record.
int size() const
Returns the size of the result (number of rows returned), or -1 if the size cannot be determined or i...
int numRowsAffected() const
Returns the number of rows affected by the result's SQL statement, or -1 if it cannot be determined.
const QSqlResult * result() const
Returns the result associated with the query.
bool nextResult()
Discards the current result set and navigates to the next if available.
bool first()
Retrieves the first record in the result, if available, and positions the query on the retrieved reco...
QVariant boundValue(const QString &placeholder) const
Returns the value for the placeholder.
void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy)
Sets \l numericalPrecisionPolicy to precisionPolicy.
bool isForwardOnly() const
Returns \l forwardOnly.
QString boundValueName(int pos) const
void clear()
Clears the result set and releases any resources held by the query.
QSqlError lastError() const
Returns error information about the last error (if any) that occurred with this query.
BatchExecutionMode
\value ValuesAsRows - Updates multiple rows.
QSqlRecord record() const
Returns a QSqlRecord containing the field information for the current query.
QString lastQuery() const
Returns the text of the current query being used, or an empty string if there is no current query tex...
bool isActive() const
Returns true if the query is {active}.
QVariant lastInsertId() const
Returns the object ID of the most recent inserted row if the database supports it.
void setForwardOnly(bool forward)
Sets \l forwardOnly to forward.
bool isPositionalBindingEnabled() const
Returns \l positionalBindingEnabled.
int at() const
Returns the current internal position of the query.
void setPositionalBindingEnabled(bool enable)
Sets \l positionalBindingEnabled to enable.
bool exec()
Executes a previously prepared SQL query.
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.
QVariantList boundValues() const
bool isSelect() const
Returns true if the current query is a SELECT statement; otherwise returns false.
QSqlQuery(QSqlResult *r)
Constructs a QSqlQuery object which uses the QSqlResult result to communicate with a database.
void addBindValue(const QVariant &val, QSql::ParamType type=QSql::In)
Adds the value val to the list of values when using positional value binding.
bool isNull(int field) const
Returns true if the query is not \l{isActive()}{active}, the query is not positioned on a valid recor...
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy
~QSqlQuery()
Destroys the object and frees any allocated resources.
bool isValid() const
Returns true if the query is currently positioned on a valid record; otherwise returns false.
bool execBatch(BatchExecutionMode mode=ValuesAsRows)
Executes a previously prepared SQL query in a batch.
bool seek(int i, bool relative=false)
Retrieves the record at position index, if available, and positions the query on the retrieved record...
QString executedQuery() const
Returns the last query that was successfully executed.
The QSqlRecord class encapsulates a database record.
int count() const
Returns the number of fields in the record.
void setValue(int i, const QVariant &val)
Sets the value of the field at position index to val.
The QSqlResult class provides an abstract interface for accessing data from specific SQL databases.
virtual void setAt(int at)
This function is provided for derived classes to set the internal (zero-based) row position to index.
\macro QT_RESTRICTED_CAST_FROM_ASCII
void * data()
Returns a pointer to the contained object as a generic void* that can be written to.
query setForwardOnly(true)
Combined button and popup list for selecting options.
QT_WARNING_POP void qAtomicAssign(T *&d, T *x)
This is a helper for the assignment operators of implicitly shared classes.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
#define qCDebug(category,...)
GLenum GLsizei GLsizei GLint * values
[15]
GLdouble GLdouble GLdouble GLdouble q
static void qInit(QSqlQuery *q, const QString &query, const QSqlDatabase &db)
#define qUtf16Printable(string)