QDjango
Classes | Public Types | Public Member Functions | List of all members
QDjangoQuerySet< T > Class Template Reference

The QDjangoQuerySet class is a template class for performing database queries. More...

#include <QDjangoQuerySet.h>

Classes

class  const_iterator
 

Public Types

typedef const_iterator ConstIterator
 

Public Member Functions

 QDjangoQuerySet ()
 
 QDjangoQuerySet (const QDjangoQuerySet< T > &other)
 
 ~QDjangoQuerySet ()
 
QDjangoQuerySet all () const
 
QDjangoQuerySet exclude (const QDjangoWhere &where) const
 
QDjangoQuerySet filter (const QDjangoWhere &where) const
 
QDjangoQuerySet limit (int pos, int length=-1) const
 
QDjangoQuerySet none () const
 
QDjangoQuerySet orderBy (const QStringList &keys) const
 
QDjangoQuerySet selectRelated () const
 
int count () const
 
QDjangoWhere where () const
 
bool remove ()
 
int size ()
 
int update (const QVariantMap &fields)
 
QList< QVariantMap > values (const QStringList &fields=QStringList())
 
QList< QVariantList > valuesList (const QStringList &fields=QStringList())
 
T * get (const QDjangoWhere &where, T *target=0) const
 
T * at (int index, T *target=0)
 
const_iterator constBegin () const
 
const_iterator begin () const
 
const_iterator constEnd () const
 
const_iterator end () const
 
QDjangoQuerySet< T > & operator= (const QDjangoQuerySet< T > &other)
 

Detailed Description

template<class T>
class QDjangoQuerySet< T >

The QDjangoQuerySet class is a template class for performing database queries.

The QDjangoQuerySet template class allows you to define and manipulate sets of QDjangoModel objects stored in the database.

You can chain filter expressions using the filter() and exclude() methods or apply limits on the number of rows using the limit() method.

You can retrieve database values using the values() and valuesList() methods or retrieve model instances using the get() and at() methods.

You can also delete sets of objects using the remove() method.

Behinds the scenes, the QDjangoQuerySet class uses implicit sharing to reduce memory usage and avoid needless copying of data.

Member Typedef Documentation

template<class T>
typedef const_iterator QDjangoQuerySet< T >::ConstIterator

Qt-style synonym for QDjangoQuerySet::const_iterator.

Constructor & Destructor Documentation

template<class T >
QDjangoQuerySet< T >::QDjangoQuerySet ( )

Constructs a new queryset.

template<class T >
QDjangoQuerySet< T >::QDjangoQuerySet ( const QDjangoQuerySet< T > &  other)

Constructs a copy of other.

Parameters
other
template<class T >
QDjangoQuerySet< T >::~QDjangoQuerySet ( )

Destroys the queryset.

Member Function Documentation

template<class T >
QDjangoQuerySet< T > QDjangoQuerySet< T >::all ( ) const

Returns a copy of the current QDjangoQuerySet.

template<class T >
T * QDjangoQuerySet< T >::at ( int  index,
T *  target = 0 
)

Returns the object in the QDjangoQuerySet at the given index.

Returns 0 if the index is out of bounds.

If target is 0, a new object instance will be allocated which you must free yourself.

Parameters
index
targetoptional existing model instance.
template<class T >
QDjangoQuerySet< T >::const_iterator QDjangoQuerySet< T >::begin ( ) const

Returns a const STL-style iterator pointing to the first object in the QDjangoQuerySet.

See also
constBegin() and end().
template<class T >
QDjangoQuerySet< T >::const_iterator QDjangoQuerySet< T >::constBegin ( ) const

Returns a const STL-style iterator pointing to the first object in the QDjangoQuerySet.

See also
begin() and constEnd().
template<class T >
QDjangoQuerySet< T >::const_iterator QDjangoQuerySet< T >::constEnd ( ) const

Returns a const STL-style iterator pointing to the imaginary object after the last object in the QDjangoQuerySet.

See also
constBegin() and end().
template<class T >
int QDjangoQuerySet< T >::count ( ) const

Counts the number of objects in the queryset using an SQL COUNT query, or -1 if the query failed.

If you intend to iterate over the results, you should consider using size() instead.

Note
If the QDjangoQuerySet is already fully fetched, this simply returns the number of objects.
template<class T >
QDjangoQuerySet< T >::const_iterator QDjangoQuerySet< T >::end ( ) const

Returns a const STL-style iterator pointing to the imaginary object after the last object in the QDjangoQuerySet.

See also
begin() and constEnd().
template<class T >
QDjangoQuerySet< T > QDjangoQuerySet< T >::exclude ( const QDjangoWhere where) const

Returns a new QDjangoQuerySet containing objects for which the given key where condition is false.

You can chain calls to filter() and exclude() to further refine the filtering conditions.

Parameters
whereQDjangoWhere expressing the exclude condition
See also
filter()
template<class T >
QDjangoQuerySet< T > QDjangoQuerySet< T >::filter ( const QDjangoWhere where) const

Returns a new QDjangoQuerySet containing objects for which the given where condition is true.

You can chain calls to filter() and exclude() to progressively refine your filtering conditions.

Parameters
whereQDjangoWhere expressing the filter condition
See also
exclude()
template<class T >
T * QDjangoQuerySet< T >::get ( const QDjangoWhere where,
T *  target = 0 
) const

Returns the object in the QDjangoQuerySet for which the given where condition is true.

Returns 0 if the number of matching object is not exactly one.

If target is 0, a new object instance will be allocated which you must free yourself.

Parameters
whereQDjangoWhere expressing the lookup condition
targetoptional existing model instance.
template<class T >
QDjangoQuerySet< T > QDjangoQuerySet< T >::limit ( int  pos,
int  length = -1 
) const

Returns a new QDjangoQuerySet containing limiting the number of records to manipulate.

You can chain calls to limit() to further restrict the number of returned records.

However, you cannot apply additional restrictions using filter(), exclude(), get(), orderBy() or remove() on the returned QDjangoQuerySet.

Parameters
posoffset of the records
lengthmaximum number of records
template<class T >
QDjangoQuerySet< T > QDjangoQuerySet< T >::none ( ) const

Returns an empty QDjangoQuerySet.

template<class T >
QDjangoQuerySet< T > & QDjangoQuerySet< T >::operator= ( const QDjangoQuerySet< T > &  other)

Assigns the specified queryset to this object.

Parameters
other
template<class T >
QDjangoQuerySet< T > QDjangoQuerySet< T >::orderBy ( const QStringList &  keys) const

Returns a QDjangoQuerySet whose elements are ordered using the given keys.

By default the elements will by in ascending order. You can prefix the key names with a "-" (minus sign) to use descending order.

Parameters
keys
template<class T >
bool QDjangoQuerySet< T >::remove ( )

Deletes all objects in the QDjangoQuerySet.

Returns
true if deletion succeeded, false otherwise
template<class T >
QDjangoQuerySet< T > QDjangoQuerySet< T >::selectRelated ( ) const

Returns a QDjangoQuerySet that will automatically "follow" foreign-key relationships, selecting that additional related-object data when it executes its query.

template<class T >
int QDjangoQuerySet< T >::size ( )

Returns the number of objects in the QDjangoQuerySet, or -1 if the query failed.

If you do not plan to access the objects, you should consider using count() instead.

template<class T >
int QDjangoQuerySet< T >::update ( const QVariantMap &  fields)

Performs an SQL update query for the specified fields and returns the number of rows affected, or -1 if the update failed.

template<class T >
QList< QVariantMap > QDjangoQuerySet< T >::values ( const QStringList &  fields = QStringList())

Returns a list of property hashes for the current QDjangoQuerySet. If no fields are specified, all the model's declared fields are returned.

Parameters
fields
template<class T >
QList< QVariantList > QDjangoQuerySet< T >::valuesList ( const QStringList &  fields = QStringList())

Returns a list of property lists for the current QDjangoQuerySet. If no fields are specified, all the model's fields are returned in the order they where declared.

Parameters
fields
template<class T >
QDjangoWhere QDjangoQuerySet< T >::where ( ) const

Returns the QDjangoWhere expressing the WHERE clause of the QDjangoQuerySet.


The documentation for this class was generated from the following file: