/
qgsmssqlfeatureiterator.h
123 lines (89 loc) · 3.6 KB
/
qgsmssqlfeatureiterator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/***************************************************************************
qgsmssqlfeatureiterator.h - description
-------------------
begin : 2011-10-08
copyright : (C) 2011 by Tamas Szekeres
email : szekerest at gmail.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSMSSQLFEATUREITERATOR_H
#define QGSMSSQLFEATUREITERATOR_H
#include "qgsmssqlgeometryparser.h"
#include "qgsfeatureiterator.h"
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QtSql/QSqlError>
class QgsMssqlProvider;
class QgsMssqlFeatureSource : public QgsAbstractFeatureSource
{
public:
explicit QgsMssqlFeatureSource( const QgsMssqlProvider* p );
~QgsMssqlFeatureSource();
virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request ) override;
protected:
QgsFields mFields;
QString mFidColName;
long mSRId;
/* sql geo type */
bool mIsGeography;
QString mGeometryColName;
QString mGeometryColType;
// current layer name
QString mSchemaName;
QString mTableName;
// login
QString mUserName;
QString mPassword;
// server access
QString mService;
QString mDatabaseName;
QString mHost;
// SQL statement used to limit the features retrieved
QString mSqlWhereClause;
// Return True if this feature source has spatial attributes.
bool isSpatial() { return !mGeometryColName.isEmpty() || !mGeometryColType.isEmpty(); }
friend class QgsMssqlFeatureIterator;
friend class QgsMssqlExpressionCompiler;
};
class QgsMssqlFeatureIterator : public QgsAbstractFeatureIteratorFromSource<QgsMssqlFeatureSource>
{
public:
QgsMssqlFeatureIterator( QgsMssqlFeatureSource* source, bool ownSource, const QgsFeatureRequest& request );
~QgsMssqlFeatureIterator();
//! reset the iterator to the starting position
virtual bool rewind() override;
//! end of iterating: free the resources / lock
virtual bool close() override;
protected:
void BuildStatement( const QgsFeatureRequest& request );
//! fetch next feature, return true on success
virtual bool fetchFeature( QgsFeature& feature ) override;
//! fetch next feature filter expression
bool nextFeatureFilterExpression( QgsFeature& f ) override;
private:
virtual bool prepareOrderBy( const QList<QgsFeatureRequest::OrderByClause> &orderBys ) override;
// The current database
QSqlDatabase mDatabase;
// The current sql query
QSqlQuery* mQuery;
// The current sql statement
QString mStatement;
QString mOrderByClause;
QString mFallbackStatement;
// Field index of FID column
long mFidCol;
// List of attribute indices to fetch with nextFeature calls
QgsAttributeList mAttributesToFetch;
// for parsing sql geometries
QgsMssqlGeometryParser mParser;
bool mExpressionCompiled;
bool mOrderByCompiled;
};
#endif // QGSMSSQLFEATUREITERATOR_H