96 QString positionalToNamedBinding();
97 QString namedToPositionalBinding();
126 return indexes.key(index);
132 ushort arr[] = {
':',
'f', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
136 *(++
ptr) =
'a' + i % 16;
140 return QString(reinterpret_cast<const QChar *>(arr),
int(ptr - arr) + 1);
147 return u -
'a' < 26 || u -
'A' < 26 || u -
'0' < 10 || u ==
'_';
156 bool inQuote =
false;
159 for (
int i = 0; i < n; ++i) {
160 QChar ch = sql.at(i);
179 bool inQuote =
false;
184 QChar ch = sql.at(i);
187 && (i + 1 < n &&
qIsAlnum(sql.at(i + 1)))) {
189 while (pos < n &&
qIsAlnum(sql.at(pos)))
191 indexes[sql.mid(i, pos - i)] = count++;
404 if (active &&
d->executedQuery.isEmpty())
405 d->executedQuery =
d->sql;
557 return fetch(
at() + 1);
573 return fetch(
at() - 1);
584 return d->forwardOnly;
605 d->forwardOnly = forward;
622 return prepare(query);
626 d->namedToPositionalBinding();
627 d->executedQuery =
d->positionalToNamedBinding();
629 d->executedQuery =
d->namedToPositionalBinding();
631 return prepare(
d->executedQuery);
643 int n = query.
size();
645 bool inQuote =
false;
652 && (i + 1 < n &&
qIsAlnum(query.
at(i + 1)))) {
657 d->holders.append(
QHolder(query.
mid(i, pos - i), i));
680 if (
d->binds == NamedBinding) {
684 for (i =
d->holders.count() - 1; i >= 0; --i) {
685 holder =
d->holders.at(i).holderName;
686 val =
d->values.value(
d->indexes.value(holder));
689 query = query.
replace(
d->holders.at(i).holderPos,
690 holder.
length(), driver()->formatValue(f));
696 for (idx = 0; idx <
d->values.count(); ++idx) {
706 val = driver()->formatValue(f);
707 query = query.
replace(i, 1, driver()->formatValue(f));
715 d->executedQuery = query;
729 d->binds = PositionalBinding;
731 if (
d->values.count() <=
index)
732 d->values.resize(index + 1);
734 if (paramType !=
QSql::In || !
d->types.isEmpty())
735 d->types[index] = paramType;
760 d->binds = NamedBinding;
763 int idx =
d->indexes.value(placeholder, -1);
765 if (
d->values.count() <= idx)
766 d->values.resize(idx + 1);
767 d->values[idx] = val;
769 d->values.append(val);
770 idx =
d->values.count() - 1;
771 d->indexes[placeholder] = idx;
774 if (paramType !=
QSql::In || !
d->types.isEmpty())
775 d->types[idx] = paramType;
786 d->binds = PositionalBinding;
787 bindValue(
d->bindCount, val, paramType);
799 return d->values.value(index);
815 int idx =
d->indexes.value(placeholder, -1);
816 return d->values.value(idx);
840 return d->types.value(
d->indexes.value(placeholder, -1),
QSql::In);
850 return d->values.count();
891 return d->executedQuery;
907 return d->holderAt(index);
918 if (
d->types.isEmpty())
921 for (it =
d->types.constBegin(); it !=
d->types.constEnd(); ++
it) {
1000 virtual_hook(BatchOperation, &arrayBind);
1001 d->resetBindCount();
1005 if (values.
count() == 0)
1008 for (
int j = 0; j < values.
count(); ++j)
1024 virtual_hook(DetachFromResultSet, 0);
1031 d->precisionPolicy = policy;
1032 virtual_hook(SetNumericalPrecision, &policy);
1039 return d->precisionPolicy;
1047 bool result =
false;
1048 virtual_hook(NextResult, &result);
The QVariant class acts like a union for the most common Qt data types.
The QSqlError class provides SQL database error information.
QSqlResult::BindingSyntax binds
QHolder(const QString &hldr=QString(), int index=-1)
const QSqlDriver * driver() const
Returns the driver associated with the result.
bool isActive() const
Returns true if the result has records to be retrieved; otherwise returns false.
#define QT_END_NAMESPACE
This macro expands to.
bool isForwardOnly() const
Returns true if you can only scroll forward through the result set; otherwise returns false...
const QChar at(int i) const
Returns the character at the given index position in the string.
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
#define it(className, varName)
int count(const T &t) const
Returns the number of occurrences of value in the vector.
QString & replace(int i, int len, QChar after)
#define at(className, varName)
Q_CORE_EXPORT QTextStream & reset(QTextStream &s)
int length() const
Returns the number of characters in this string.
QVector< QHolder > QHolderVector
bool operator==(const QHolder &h) const
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
static QString qFieldSerial(int i)
bool execBatch(bool arrayBind=false)
Executes a prepared query in batch mode if the driver supports it, otherwise emulates a batch executi...
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
The QSqlRecord class encapsulates a database record.
virtual void bindValue(int pos, const QVariant &val, QSql::ParamType type)
Binds the value val of parameter type paramType to position index in the current record (row)...
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const
virtual QSqlRecord record() const
Returns the current record if the query is active; otherwise returns an empty QSqlRecord.
The QSqlDriver class is an abstract base class for accessing specific SQL databases.
The QString class provides a Unicode character string.
int at() const
Returns the current (zero-based) row position of the result.
QVector< QVariant > values
QString lastQuery() const
Returns the current SQL query text, or an empty string if there isn't one.
The QChar class provides a 16-bit Unicode character.
QSqlResult(const QSqlDriver *db)
Creates a QSqlResult using database driver db.
const T value(const Key &key) const
Returns the value associated with the key.
virtual QVariant lastInsertId() const
Returns the object ID of the most recent inserted row if the database supports it.
virtual void setAt(int at)
This function is provided for derived classes to set the internal (zero-based) row position to index...
virtual void setLastError(const QSqlError &e)
This function is provided for derived classes to set the last error to error.
void setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy policy)
void reserve(int size)
Attempts to allocate memory for at least size characters.
QString boundValueName(int pos) const
Returns the name of the bound value at position index in the current record (row).
#define QT_BEGIN_NAMESPACE
This macro expands to.
QVariant boundValue(const QString &placeholder) const
Returns the value bound by the given placeholder name in the current record (row).
virtual void setSelect(bool s)
This function is provided for derived classes to indicate whether or not the current statement is a S...
virtual bool savePrepare(const QString &sqlquery)
Prepares the given query, using the underlying database functionality where possible.
int size() const
Returns the number of characters in this string.
virtual QVariant handle() const
Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVarian...
virtual bool fetchNext()
Positions the result to the next available record (row) in the result.
const T & at(int i) const
Returns the item at index position i in the list.
void clear()
Clears the value of the field and sets it to NULL.
bool hasOutValues() const
Returns true if at least one of the query's bound values is a QSql::Out or a QSql::InOut; otherwise r...
QSql::ParamType bindValueType(const QString &placeholder) const
Returns the parameter type for the value bound with the given placeholder name.
bool operator!=(const QHolder &h) const
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QString holderAt(int index) const
int boundValueCount() const
Returns the number of bound values in the result.
QHash< QString, int > IndexMap
const T * ptr(const T &t)
static bool qIsAlnum(QChar ch)
virtual bool exec()
Executes the query, returning true if successful; otherwise returns false.
virtual bool prepare(const QString &query)
Prepares the given query for execution; the query will normally use placeholders so that it can be ex...
virtual void setForwardOnly(bool forward)
Sets forward only mode to forward.
QString executedQuery() const
Returns the query that was actually executed.
void squeeze()
Releases any memory not required to store the character data.
virtual void virtual_hook(int id, void *data)
const T & at(int i) const
Returns the item at index position i in the vector.
BindingSyntax bindingSyntax() const
Returns the binding syntax used by prepared queries.
void detachFromResultSet()
virtual ~QSqlResult()
Destroys the object and frees any allocated resources.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
QSql::NumericalPrecisionPolicy precisionPolicy
QHash< int, QSql::ParamType > types
void addBindValue(const QVariant &val, QSql::ParamType type)
Binds the value val of parameter type paramType to the next available position in the current record ...
static QByteArray paramType(const QByteArray &ptype, bool *out)
Type type() const
Returns the storage type of the value stored in the variant.
BindingSyntax
This enum type specifies the different syntaxes for specifying placeholders in prepared queries...
QString positionalToNamedBinding()
QSqlResultPrivate(QSqlResult *d)
void clear()
Clears the entire result set and releases any associated resources.
QSqlError lastError() const
Returns the last error associated with the result.
bool isSelect() const
Returns true if the current result is from a SELECT statement; otherwise returns false.
virtual void setActive(bool a)
This function is provided for derived classes to set the internal active state to active...
virtual bool fetchPrevious()
Positions the result to the previous record (row) in the result.
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const
Returns the current default precision policy for the database connection.
bool isValid() const
Returns true if the result is positioned on a valid record (that is, the result is not positioned bef...
The QSqlField class manipulates the fields in SQL database tables and views.
QVector< QVariant > & boundValues() const
Returns a vector of the result's bound values for the current record (row).
QString namedToPositionalBinding()
The QSqlResult class provides an abstract interface for accessing data from specific SQL databases...
QPointer< QSqlDriver > sqldriver
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
virtual void setQuery(const QString &query)
Sets the current query for the result to query.
void setValue(const QVariant &value)
Sets the value of the field to value.