Showing with 21 additions and 42 deletions.
  1. +4 −0 python/__init__.py
  2. +13 −38 python/core/qgsfeature.sip
  3. +3 −3 src/providers/spatialite/qgsspatialitefeatureiterator.cpp
  4. +1 −1 src/providers/spatialite/qgsspatialitefeatureiterator.h
4 changes: 4 additions & 0 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
def __nonzero__(self):
return False

def __repr__(self):
return 'NULL'

QPyNullVariant.__nonzero__ = MethodType(__nonzero__, None, QPyNullVariant)
QPyNullVariant.__repr__ = MethodType(__repr__, None, QPyNullVariant)
except ImportError:
pass
51 changes: 13 additions & 38 deletions python/core/qgsfeature.sip
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,24 @@ typedef QVector<QVariant> QgsAttributes;
// Create the list.
PyObject *l;

if ((l = PyList_New(sipCpp->size())) == NULL)
if ( ( l = PyList_New(sipCpp->size() ) ) == NULL )
return NULL;

// Set the list elements.
for (int i = 0; i < sipCpp->size(); ++i)
for ( int i = 0; i < sipCpp->size(); ++i )
{
QVariant* v = new QVariant( sipCpp->at(i) );
QVariant* v = new QVariant( sipCpp->at( i ) );
PyObject *tobj;

if ( v->isNull() )
{
Py_INCREF( Py_None );
tobj = Py_None;
delete v;
}
else if ((tobj = sipConvertFromNewType(v, sipType_QVariant,Py_None)) == NULL)
if ( ( tobj = sipConvertFromNewType( v, sipType_QVariant,Py_None ) ) == NULL )
{
Py_DECREF( l );
delete v;

return NULL;
}

PyList_SET_ITEM(l, i, tobj);
PyList_SET_ITEM( l, i, tobj );
}

return l;
Expand Down Expand Up @@ -132,17 +128,8 @@ class QgsFeature
}
else
{
QVariant* v = new QVariant(attrs.at(a0));
if ( v->isNull() )
{
delete v;
Py_INCREF( Py_None );
sipRes = Py_None;
}
else
{
sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
}
QVariant* v = new QVariant( attrs.at(a0) );
sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
}
%End

Expand All @@ -156,14 +143,8 @@ class QgsFeature
}
else
{
QVariant v = sipCpp->attribute(fieldIdx);
if ( v.isNull() )
{
Py_INCREF( Py_None );
sipRes = Py_None;
}
else
sipRes = sipConvertFromType( &v, sipType_QVariant, Py_None );
QVariant* v = new QVariant( sipCpp->attribute(fieldIdx) );
sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
}
%End

Expand Down Expand Up @@ -404,14 +385,8 @@ class QgsFeature
}
else
{
QVariant v = sipCpp->attribute(fieldIdx);
if ( v.isNull() )
{
Py_INCREF( Py_None );
sipRes = Py_None;
}
else
sipRes = sipConvertFromType( &v, sipType_QVariant, Py_None );
QVariant* v = new QVariant( sipCpp->attribute(fieldIdx) );
sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
}
%End
/** Utility method to get attribute index from name. Returns -1 if field does not exist or field map is not associated.
Expand Down
6 changes: 3 additions & 3 deletions src/providers/spatialite/qgsspatialitefeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,14 @@ bool QgsSpatiaLiteFeatureIterator::getFeature( sqlite3_stmt *stmt, QgsFeature &f
else
{
int attrIndex = subsetAttributes ? mRequest.subsetOfAttributes()[ic-1] : ic - 1;
feature.setAttribute( attrIndex, getFeatureAttribute( stmt, ic ) );
feature.setAttribute( attrIndex, getFeatureAttribute( stmt, ic, P->attributeFields[attrIndex].type() ) );
}
}

return true;
}

QVariant QgsSpatiaLiteFeatureIterator::getFeatureAttribute( sqlite3_stmt* stmt, int ic )
QVariant QgsSpatiaLiteFeatureIterator::getFeatureAttribute( sqlite3_stmt* stmt, int ic, const QVariant::Type& type )
{
if ( sqlite3_column_type( stmt, ic ) == SQLITE_INTEGER )
{
Expand All @@ -354,7 +354,7 @@ QVariant QgsSpatiaLiteFeatureIterator::getFeatureAttribute( sqlite3_stmt* stmt,
}

// assuming NULL
return QVariant();
return QVariant( type );
}

void QgsSpatiaLiteFeatureIterator::getFeatureGeometry( sqlite3_stmt* stmt, int ic, QgsFeature& feature )
Expand Down
2 changes: 1 addition & 1 deletion src/providers/spatialite/qgsspatialitefeatureiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class QgsSpatiaLiteFeatureIterator : public QgsAbstractFeatureIterator
QString quotedPrimaryKey();
bool getFeature( sqlite3_stmt *stmt, QgsFeature &feature );
QString fieldName( const QgsField& fld );
QVariant getFeatureAttribute( sqlite3_stmt* stmt, int ic );
QVariant getFeatureAttribute( sqlite3_stmt* stmt, int ic, const QVariant::Type& type );
void getFeatureGeometry( sqlite3_stmt* stmt, int ic, QgsFeature& feature );

/**
Expand Down