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;
306 int update(
const QVariantMap &fields);
307 QList<QVariantMap>
values(
const QStringList &fields = QStringList());
308 QList<QVariantList>
valuesList(
const QStringList &fields = QStringList());
311 T *
at(
int index, T *target = 0);
322 QDjangoQuerySetPrivate *d;
330 d =
new QDjangoQuerySetPrivate(T::staticMetaObject.className());
340 other.d->counter.ref();
349 if (!d->counter.deref())
366 T *entry = target ? target :
new T;
367 if (!d->sqlLoad(entry, index))
424 other.d->lowMark = d->lowMark;
425 other.d->highMark = d->highMark;
426 other.d->orderBy = d->orderBy;
427 other.d->selectRelated = d->selectRelated;
428 other.d->whereClause = d->whereClause;
445 return d->properties.size();
448 QDjangoQuery query(d->countQuery());
449 if (!query.exec() || !query.next())
451 return query.value(0).toInt();
468 other.d->addFilter(!where);
486 other.d->addFilter(where);
505 return qs.
size() == 1 ? qs.
at(0, target) : 0;
524 Q_ASSERT(length >= -1);
527 other.d->lowMark += pos;
531 other.d->highMark = other.d->lowMark + length;
533 if (d->highMark > 0 && other.d->highMark > d->highMark)
534 other.d->highMark = d->highMark;
560 Q_ASSERT(!d->lowMark && !d->highMark);
563 other.d->orderBy << keys;
574 return d->sqlDelete();
585 other.d->selectRelated =
true;
600 return d->properties.size();
609 return d->sqlUpdate(fields);
620 return d->sqlValues(fields);
632 return d->sqlValuesList(fields);
651 other.d->counter.ref();
652 if (!d->counter.deref())
~QDjangoQuerySet()
Definition: QDjangoQuerySet.h:347
The QDjangoWhere class expresses an SQL constraint.
Definition: QDjangoWhere.h:40
int update(const QVariantMap &fields)
Definition: QDjangoQuerySet.h:607
const_iterator operator--(int)
Definition: QDjangoQuerySet.h:258
difference_type operator-(const const_iterator &other) const
Definition: QDjangoQuerySet.h:264
static QSqlDatabase database()
Returns the database used by QDjango.
Definition: QDjango.cpp:166
bool remove()
Definition: QDjangoQuerySet.h:572
QDjangoQuerySet selectRelated() const
Definition: QDjangoQuerySet.h:582
QDjangoWhere where() const
Definition: QDjangoQuerySet.h:639
bool operator==(const const_iterator &other) const
Definition: QDjangoQuerySet.h:145
int count() const
Definition: QDjangoQuerySet.h:442
const_iterator()
Definition: QDjangoQuerySet.h:102
const_iterator operator++(int)
Definition: QDjangoQuerySet.h:212
bool operator<=(const const_iterator &other) const
Definition: QDjangoQuerySet.h:172
Definition: QDjangoQuerySet.h:78
QDjangoQuerySet limit(int pos, int length=-1) const
Definition: QDjangoQuerySet.h:521
const_iterator & operator-=(int i)
Definition: QDjangoQuerySet.h:233
QDjangoQuerySet filter(const QDjangoWhere &where) const
Definition: QDjangoQuerySet.h:483
const_iterator constBegin() const
Definition: QDjangoQuerySet.h:381
QDjangoQuerySet exclude(const QDjangoWhere &where) const
Definition: QDjangoQuerySet.h:465
QDjangoQuerySet()
Definition: QDjangoQuerySet.h:328
const_iterator & operator+=(int i)
Definition: QDjangoQuerySet.h:219
QDjangoQuerySet< T > & operator=(const QDjangoQuerySet< T > &other)
Definition: QDjangoQuerySet.h:649
const_iterator ConstIterator
Definition: QDjangoQuerySet.h:287
const_iterator & operator++()
Definition: QDjangoQuerySet.h:203
const_iterator & operator--()
Definition: QDjangoQuerySet.h:249
const_iterator constEnd() const
Definition: QDjangoQuerySet.h:402
const_iterator(const const_iterator &other)
Definition: QDjangoQuerySet.h:111
The QDjangoQuerySet class is a template class for performing database queries.
Definition: QDjangoQuerySet.h:46
QDjangoQuerySet none() const
Definition: QDjangoQuerySet.h:542
T * at(int index, T *target=0)
Definition: QDjangoQuerySet.h:364
QList< QVariantList > valuesList(const QStringList &fields=QStringList())
Definition: QDjangoQuerySet.h:630
bool operator!=(const const_iterator &other) const
Definition: QDjangoQuerySet.h:155
const_iterator end() const
Definition: QDjangoQuerySet.h:413
const_iterator operator+(int i) const
Definition: QDjangoQuerySet.h:226
QDjangoQuerySet orderBy(const QStringList &keys) const
Definition: QDjangoQuerySet.h:557
T * get(const QDjangoWhere &where, T *target=0) const
Definition: QDjangoQuerySet.h:502
const_iterator operator-(int i) const
Definition: QDjangoQuerySet.h:240
int size()
Definition: QDjangoQuerySet.h:596
QDjangoQuerySet all() const
Definition: QDjangoQuerySet.h:421
const T & operator*() const
Definition: QDjangoQuerySet.h:131
bool operator<(const const_iterator &other) const
Definition: QDjangoQuerySet.h:163
std::bidirectional_iterator_tag iterator_category
Definition: QDjangoQuerySet.h:86
const T * operator->() const
Definition: QDjangoQuerySet.h:137
const_iterator begin() const
Definition: QDjangoQuerySet.h:391
QList< QVariantMap > values(const QStringList &fields=QStringList())
Definition: QDjangoQuerySet.h:618
bool operator>=(const const_iterator &other) const
Definition: QDjangoQuerySet.h:190
bool operator>(const const_iterator &other) const
Definition: QDjangoQuerySet.h:181