19 #ifndef QDJANGO_QUERYSET_H
20 #define QDJANGO_QUERYSET_H
23 #include "QDjangoWhere.h"
24 #include "QDjangoQuerySet_p.h"
50 typedef int size_type;
52 typedef value_type *pointer;
53 typedef const value_type *const_pointer;
54 typedef value_type &reference;
55 typedef const value_type &const_reference;
56 typedef qptrdiff difference_type;
89 typedef qptrdiff difference_type;
112 : m_querySet(other.m_querySet)
114 , m_offset(other.m_offset)
120 : m_querySet(querySet)
147 return m_querySet == other.m_querySet && m_offset == other.m_offset;
157 return m_querySet != other.m_querySet || m_offset != other.m_offset;
165 return (m_querySet == other.m_querySet && m_offset < other.m_offset)
166 || m_querySet < other.m_querySet;
174 return (m_querySet == other.m_querySet && m_offset <= other.m_offset)
175 || m_querySet < other.m_querySet;
183 return (m_querySet == other.m_querySet && m_offset > other.m_offset)
184 || m_querySet > other.m_querySet;
192 return (m_querySet == other.m_querySet && m_offset >= other.m_offset)
193 || m_querySet > other.m_querySet;
269 if (m_fetched != m_offset && m_querySet) {
271 m_fetched = m_offset;
275 return m_fetched == m_offset ? &m_object : 0;
280 mutable int m_fetched;
302 QVariant
aggregate(
const QDjangoWhere::AggregateType func,
const QString& field)
const;
307 int update(
const QVariantMap &fields);
308 QList<QVariantMap>
values(
const QStringList &fields = QStringList());
309 QList<QVariantList>
valuesList(
const QStringList &fields = QStringList());
312 T *
at(
int index, T *target = 0);
323 QDjangoQuerySetPrivate *d;
331 d =
new QDjangoQuerySetPrivate(T::staticMetaObject.className());
341 other.d->counter.ref();
350 if (!d->counter.deref())
367 T *entry = target ? target :
new T;
368 if (!d->sqlLoad(entry, index))
425 other.d->lowMark = d->lowMark;
426 other.d->highMark = d->highMark;
427 other.d->orderBy = d->orderBy;
428 other.d->selectRelated = d->selectRelated;
429 other.d->relatedFields = d->relatedFields;
430 other.d->whereClause = d->whereClause;
447 return d->properties.size();
461 QDjangoQuery query(d->aggregateQuery(func, field));
462 if (!query.exec() || !query.next())
464 return query.value(0);
481 other.d->addFilter(!
where);
499 other.d->addFilter(
where);
518 return qs.
size() == 1 ? qs.
at(0, target) : 0;
537 Q_ASSERT(length >= -1);
540 other.d->lowMark += pos;
544 other.d->highMark = other.d->lowMark + length;
546 if (d->highMark > 0 && other.d->highMark > d->highMark)
547 other.d->highMark = d->highMark;
573 Q_ASSERT(!d->lowMark && !d->highMark);
576 other.d->orderBy << keys;
587 return d->sqlDelete();
604 other.d->selectRelated =
true;
605 other.d->relatedFields = relatedFields;
620 return d->properties.size();
629 return d->sqlUpdate(fields);
640 return d->sqlValues(fields);
652 return d->sqlValuesList(fields);
671 other.d->counter.ref();
672 if (!d->counter.deref())
const_iterator constEnd() const
Definition: QDjangoQuerySet.h:403
std::bidirectional_iterator_tag iterator_category
Definition: QDjangoQuerySet.h:86
const_iterator operator+(int i) const
Definition: QDjangoQuerySet.h:226
The QDjangoWhere class expresses an SQL constraint.
Definition: QDjangoWhere.h:41
bool operator<=(const const_iterator &other) const
Definition: QDjangoQuerySet.h:172
Definition: QDjangoQuerySet.h:79
const_iterator operator++(int)
Definition: QDjangoQuerySet.h:212
QDjangoQuerySet< T > & operator=(const QDjangoQuerySet< T > &other)
Definition: QDjangoQuerySet.h:669
const_iterator ConstIterator
Definition: QDjangoQuerySet.h:287
bool remove()
Definition: QDjangoQuerySet.h:585
bool operator!=(const const_iterator &other) const
Definition: QDjangoQuerySet.h:155
bool operator<(const const_iterator &other) const
Definition: QDjangoQuerySet.h:163
QDjangoWhere where() const
Definition: QDjangoQuerySet.h:659
const_iterator & operator-=(int i)
Definition: QDjangoQuerySet.h:233
int update(const QVariantMap &fields)
Definition: QDjangoQuerySet.h:627
const_iterator operator--(int)
Definition: QDjangoQuerySet.h:258
bool operator>=(const const_iterator &other) const
Definition: QDjangoQuerySet.h:190
difference_type operator-(const const_iterator &other) const
Definition: QDjangoQuerySet.h:264
const T & operator*() const
Definition: QDjangoQuerySet.h:131
const_iterator(const const_iterator &other)
Definition: QDjangoQuerySet.h:111
const_iterator & operator--()
Definition: QDjangoQuerySet.h:249
static QSqlDatabase database()
Returns the database used by QDjango.
Definition: QDjango.cpp:167
QDjangoQuerySet selectRelated(const QStringList &relatedFields=QStringList()) const
Definition: QDjangoQuerySet.h:601
QDjangoQuerySet exclude(const QDjangoWhere &where) const
Definition: QDjangoQuerySet.h:478
QList< QVariantMap > values(const QStringList &fields=QStringList())
Definition: QDjangoQuerySet.h:638
bool operator>(const const_iterator &other) const
Definition: QDjangoQuerySet.h:181
QDjangoQuerySet none() const
Definition: QDjangoQuerySet.h:555
QDjangoQuerySet filter(const QDjangoWhere &where) const
Definition: QDjangoQuerySet.h:496
int size()
Definition: QDjangoQuerySet.h:616
QDjangoQuerySet orderBy(const QStringList &keys) const
Definition: QDjangoQuerySet.h:570
The QDjangoQuerySet class is a template class for performing database queries.
Definition: QDjangoQuerySet.h:47
const_iterator & operator+=(int i)
Definition: QDjangoQuerySet.h:219
int count() const
Definition: QDjangoQuerySet.h:444
const_iterator end() const
Definition: QDjangoQuerySet.h:414
QDjangoQuerySet()
Definition: QDjangoQuerySet.h:329
const_iterator operator-(int i) const
Definition: QDjangoQuerySet.h:240
bool operator==(const const_iterator &other) const
Definition: QDjangoQuerySet.h:145
const_iterator & operator++()
Definition: QDjangoQuerySet.h:203
~QDjangoQuerySet()
Definition: QDjangoQuerySet.h:348
const_iterator()
Definition: QDjangoQuerySet.h:102
const T * operator->() const
Definition: QDjangoQuerySet.h:137
QDjangoQuerySet all() const
Definition: QDjangoQuerySet.h:422
QVariant aggregate(const QDjangoWhere::AggregateType func, const QString &field) const
Definition: QDjangoQuerySet.h:458
T * get(const QDjangoWhere &where, T *target=0) const
Definition: QDjangoQuerySet.h:515
const_iterator begin() const
Definition: QDjangoQuerySet.h:392
QList< QVariantList > valuesList(const QStringList &fields=QStringList())
Definition: QDjangoQuerySet.h:650
const_iterator constBegin() const
Definition: QDjangoQuerySet.h:382
T * at(int index, T *target=0)
Definition: QDjangoQuerySet.h:365
QDjangoQuerySet limit(int pos, int length=-1) const
Definition: QDjangoQuerySet.h:534