47 changes: 47 additions & 0 deletions src/providers/sqlanywhere/qgssqlanywherefeatureiterator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef QGSSQLANYWHEREFEATUREITERATOR_H
#define QGSSQLANYWHEREFEATUREITERATOR_H

#include "qgsfeatureiterator.h"
#include "sqlanystatement.h"

class QgsSqlAnywhereProvider;
class QgsSqlAnywhereResult;

class QgsSqlAnywhereFeatureIterator : public QgsAbstractFeatureIterator
{
public:
QgsSqlAnywhereFeatureIterator( QgsSqlAnywhereProvider* p, const QgsFeatureRequest & request );

~QgsSqlAnywhereFeatureIterator();

//! fetch next feature, return true on success
virtual bool nextFeature( QgsFeature& feature );
bool nextFeature( QgsFeature& feature, SqlAnyStatement *stmt );

//! reset the iterator to the starting position
virtual bool rewind();

//! end of iterating: free the resources / lock
virtual bool close();

protected:
QgsSqlAnywhereProvider* P;

private:
bool prepareStatement( QString whereClause );

QString whereClauseRect() const;

QString quotedPrimaryKey() const;
QString whereClauseFid() const;

/**
* Statement handle for fetching of features by bounding rectangle
*/
SqlAnyStatement *mStmt;

QgsRectangle mStmtRect;

};

#endif // QGSSQLANYWHEREFEATUREITERATOR_H
371 changes: 31 additions & 340 deletions src/providers/sqlanywhere/qgssqlanywhereprovider.cpp

Large diffs are not rendered by default.

58 changes: 6 additions & 52 deletions src/providers/sqlanywhere/qgssqlanywhereprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,8 @@ class QgsSqlAnywhereProvider: public QgsVectorDataProvider
/** Get the QgsCoordinateReferenceSystem for this layer */
QgsCoordinateReferenceSystem crs() { return mCrs; }

/** Gets the feature at the given feature ID
* @param featureId of feature to retrieve
* @param feature which will receive data from the provider
* @param fetchGeometry true if the feature geometry should be fetched
* @param fetchAttributes list of attributes which should be fetched
*/
virtual bool featureAtId( QgsFeatureId featureId,
QgsFeature & feature, bool fetchGeometry = true, QgsAttributeList fetchAttributes = QgsAttributeList() );
/** Query for features specified in request. **/
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request );

/** Accessor for sql where clause used to limit dataset */
virtual QString subsetString();
Expand All @@ -79,23 +73,6 @@ class QgsSqlAnywhereProvider: public QgsVectorDataProvider
virtual bool setSubsetString( QString theSQL, bool updateFeatureCount = true );
virtual bool supportsSubsetString() { return true; }

/** Select features based on a bounding rectangle. Features can be retrieved with calls to nextFeature.
* @param fetchAttributes list of attributes which should be fetched
* @param rect spatial filter
* @param fetchGeometry true if the feature geometry should be fetched
* @param useIntersect true if an accurate intersection test should be used,
* false if a test based on bounding box is sufficient
*/
virtual void select( QgsAttributeList fetchAttributes = QgsAttributeList(),
QgsRectangle rect = QgsRectangle(), bool fetchGeometry = true, bool useIntersect = false );

/**
* Get the next feature resulting from a select operation.
* @param feature feature which will receive data from the provider
* @return true when there was a feature to fetch, false when end was hit
*/
virtual bool nextFeature( QgsFeature & feature );

/** Get the feature type. This corresponds to
* WKBPoint,
* WKBLineString,
Expand Down Expand Up @@ -126,12 +103,7 @@ class QgsSqlAnywhereProvider: public QgsVectorDataProvider
* Get the field information for the layer
* @return vector of QgsField objects
*/
const QgsFieldMap & fields() const { return mAttributeFields; }

/**
* Restart reading features from previous select operation
*/
void rewind();
const QgsFields & fields() const { return mAttributeFields; }

/** Returns the minimum value of an attribute
* @param index the index of the attribute */
Expand Down Expand Up @@ -277,16 +249,12 @@ class QgsSqlAnywhereProvider: public QgsVectorDataProvider
* internal utility functions used to handle common database tasks
*/
void closeDb();
void closeCursors() { closeConnROCursors(); }
void closeConnROCursors();
void closeConnRO();
void closeConnRW();
QString quotedIdentifier( QString id ) const;
QString quotedValue( QString value ) const;
QString getWhereClause() const { return mSubsetString.isEmpty() ? "1=1 " : "( " + mSubsetString + ") "; }
bool hasUniqueData( QString colName );
QString makeSelectSql( QString whereClause ) const;
bool nextFeature( QgsFeature & feature, SqlAnyStatement *stmt );
QString geomSampleSet();
QString geomColIdent() const { return quotedIdentifier( mGeometryColumn ) + mGeometryProjStr; }

Expand All @@ -309,7 +277,7 @@ class QgsSqlAnywhereProvider: public QgsVectorDataProvider
/**
* map of field index number to field type
*/
QgsFieldMap mAttributeFields;
QgsFields mAttributeFields;
/**
* map of field index number to field default value
*/
Expand Down Expand Up @@ -399,22 +367,6 @@ class QgsSqlAnywhereProvider: public QgsVectorDataProvider
*/
long mNumberFeatures;

/**
* Statement handle for fetching of features by bounding rectangle
*/
SqlAnyStatement *mStmt;
QgsAttributeList mStmtAttributesToFetch;
bool mStmtFetchGeom;
QgsRectangle mStmtRect;
bool mStmtUseIntersect;

/**
* Statement handle for fetching of features by ID
*/
SqlAnyStatement *mIdStmt;
QgsAttributeList mIdStmtAttributesToFetch;
bool mIdStmtFetchGeom;

/**
* Read-only connection to SQL Anywhere database
*/
Expand All @@ -424,6 +376,8 @@ class QgsSqlAnywhereProvider: public QgsVectorDataProvider
*/
SqlAnyConnection *mConnRW;

friend class QgsSqlAnywhereFeatureIterator;

}; // class QgsSqlAnywhereProvider


Expand Down