Skip to content

Commit bd58bc3

Browse files
committedMar 2, 2017
oracle provider: update qocispatial driver for/from Qt5
* handling of private data * rely on implicit byte array sharing instead of using data pointers * sync with qoci
1 parent febff07 commit bd58bc3

File tree

8 files changed

+345
-325
lines changed

8 files changed

+345
-325
lines changed
 

‎src/providers/oracle/ocispatial/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ ADD_DEFINITIONS(-DQT_PLUGIN)
99
ADD_DEFINITIONS(-DQT_NO_DEBUG)
1010
ADD_DEFINITIONS(-DQT_SHARED)
1111

12-
INCLUDE_DIRECTORIES(SYSTEM ${OCI_INCLUDE_DIR})
12+
INCLUDE_DIRECTORIES(SYSTEM
13+
${OCI_INCLUDE_DIR}
14+
${Qt5Sql_PRIVATE_INCLUDE_DIRS}
15+
)
1316

1417
SET(QSQLOCISPATIAL_SRC qsql_ocispatial.cpp main.cpp)
15-
QT5_WRAP_CPP(QSQLOCISPATIAL_SRC qsql_ocispatial.h main.h)
18+
QT5_WRAP_CPP(QSQLOCISPATIAL_MOC_SRC qsql_ocispatial.h main.h)
1619

17-
ADD_LIBRARY(qsqlocispatial SHARED ${QSQLOCISPATIAL_SRC})
20+
ADD_LIBRARY(qsqlocispatial SHARED ${QSQLOCISPATIAL_SRC} ${QSQLOCISPATIAL_MOC_SRC})
1821

1922
TARGET_LINK_LIBRARIES(qsqlocispatial
2023
${QT_QTCORE_LIBRARY}

‎src/providers/oracle/ocispatial/main.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@
4242
****************************************************************************/
4343

4444
#include "main.h"
45+
#include <qsqldriverplugin.h>
4546
#include "qsql_ocispatial.h"
4647

47-
QT_BEGIN_NAMESPACE
48-
4948
QOCISpatialDriverPlugin::QOCISpatialDriverPlugin()
5049
: QSqlDriverPlugin()
5150
{
@@ -60,12 +59,3 @@ QSqlDriver* QOCISpatialDriverPlugin::create( const QString &name )
6059
}
6160
return 0;
6261
}
63-
64-
QStringList QOCISpatialDriverPlugin::keys() const
65-
{
66-
QStringList l;
67-
l << QLatin1String( "QOCISPATIAL8" ) << QLatin1String( "QOCISPATIAL" );
68-
return l;
69-
}
70-
71-
QT_END_NAMESPACE

‎src/providers/oracle/ocispatial/main.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,16 @@
4141
**
4242
****************************************************************************/
4343

44-
#ifndef QOCISPATIAL_MAIN_H
45-
#define QOCISPATIAL_MAIN_H
46-
47-
#include <QSqlDriverPlugin>
48-
#include <QStringList>
44+
#include <qsqldriverplugin.h>
45+
#include "qsql_ocispatial.h"
4946

5047
class QOCISpatialDriverPlugin : public QSqlDriverPlugin
5148
{
5249
Q_OBJECT
5350
Q_PLUGIN_METADATA( IID "org.qt-project.Qt.QSqlDriverFactoryInterface" FILE "qocispatial.json" )
51+
5452
public:
5553
QOCISpatialDriverPlugin();
5654

5755
QSqlDriver* create( const QString & );
58-
QStringList keys() const;
5956
};
60-
61-
#endif

‎src/providers/oracle/ocispatial/qsql_ocispatial.cpp

Lines changed: 305 additions & 242 deletions
Large diffs are not rendered by default.

‎src/providers/oracle/ocispatial/qsql_ocispatial.h

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -42,88 +42,56 @@
4242
#ifndef QSQL_OCISPATIAL_H
4343
#define QSQL_OCISPATIAL_H
4444

45-
#include <QtSql/qsqlresult.h>
4645
#include <QtSql/qsqldriver.h>
47-
#include "qsqlcachedresult_p.h"
4846

4947
#ifdef QT_PLUGIN
5048
#define Q_EXPORT_SQLDRIVER_OCISPATIAL
5149
#else
5250
#define Q_EXPORT_SQLDRIVER_OCISPATIAL Q_SQL_EXPORT
5351
#endif
5452

55-
QT_BEGIN_HEADER
56-
5753
typedef struct OCIEnv OCIEnv;
5854
typedef struct OCISvcCtx OCISvcCtx;
5955

6056
QT_BEGIN_NAMESPACE
6157

62-
class QOCISpatialDriver;
63-
class QOCISpatialCols;
64-
struct QOCISpatialDriverPrivate;
65-
struct QOCISpatialResultPrivate;
66-
67-
class Q_EXPORT_SQLDRIVER_OCISPATIAL QOCISpatialResult : public QSqlCachedResult
68-
{
69-
friend class QOCISpatialDriver;
70-
friend struct QOCISpatialResultPrivate;
71-
friend class QOCISpatialCols;
72-
public:
73-
QOCISpatialResult( const QOCISpatialDriver * db, const QOCISpatialDriverPrivate* p );
74-
~QOCISpatialResult();
75-
bool prepare( const QString& query );
76-
bool exec();
77-
QVariant handle() const;
78-
79-
protected:
80-
bool gotoNext( ValueCache &values, int index );
81-
bool reset( const QString& query );
82-
int size();
83-
int numRowsAffected();
84-
QSqlRecord record() const;
85-
QVariant lastInsertId() const;
86-
87-
private:
88-
QOCISpatialResultPrivate *d = nullptr;
89-
};
58+
class QSqlResult;
59+
class QOCISpatialDriverPrivate;
9060

9161
class Q_EXPORT_SQLDRIVER_OCISPATIAL QOCISpatialDriver : public QSqlDriver
9262
{
63+
Q_DECLARE_PRIVATE( QOCISpatialDriver )
9364
Q_OBJECT
94-
friend struct QOCISpatialResultPrivate;
95-
friend class QOCISpatialPrivate;
65+
friend class QOCISpatialCols;
66+
friend class QOCISpatialResultPrivate;
67+
9668
public:
97-
explicit QOCISpatialDriver( QObject* parent = 0 );
98-
QOCISpatialDriver( OCIEnv* env, OCISvcCtx* ctx, QObject* parent = 0 );
69+
explicit QOCISpatialDriver( QObject* parent = nullptr );
70+
QOCISpatialDriver( OCIEnv* env, OCISvcCtx* ctx, QObject* parent = nullptr );
9971
~QOCISpatialDriver();
10072
bool hasFeature( DriverFeature f ) const;
101-
bool open( const QString & db,
102-
const QString & user,
103-
const QString & password,
104-
const QString & host,
73+
bool open( const QString &db,
74+
const QString &user,
75+
const QString &password,
76+
const QString &host,
10577
int port,
106-
const QString& connOpts );
78+
const QString &connOpts ) override;
10779
void close();
10880
QSqlResult *createResult() const;
109-
QStringList tables( QSql::TableType ) const;
110-
QSqlRecord record( const QString& tablename ) const;
111-
QSqlIndex primaryIndex( const QString& tablename ) const;
81+
QStringList tables( QSql::TableType ) const override;
82+
QSqlRecord record( const QString& tablename ) const override;
83+
QSqlIndex primaryIndex( const QString& tablename ) const override;
11284
QString formatValue( const QSqlField &field,
113-
bool trimStrings ) const;
85+
bool trimStrings ) const override;
11486
QVariant handle() const;
115-
QString escapeIdentifier( const QString &identifier, IdentifierType ) const;
87+
QString escapeIdentifier( const QString &identifier, IdentifierType ) const override;
11688

11789
protected:
118-
bool beginTransaction();
119-
bool commitTransaction();
120-
bool rollbackTransaction();
121-
private:
122-
QOCISpatialDriverPrivate *d = nullptr;
90+
bool beginTransaction() override;
91+
bool commitTransaction() override;
92+
bool rollbackTransaction() override;
12393
};
12494

12595
QT_END_NAMESPACE
12696

127-
QT_END_HEADER
128-
12997
#endif // QSQL_OCISPATIAL_H

‎src/providers/oracle/ocispatial/wkbptr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define WKBPTR_H
1919

2020
#include <QSharedData>
21+
#include <QVector>
2122

2223
union wkbPtr
2324
{

‎src/providers/oracle/qgsoraclefeatureiterator.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ bool QgsOracleFeatureIterator::fetchFeature( QgsFeature& feature )
267267

268268
if ( mFetchGeometry )
269269
{
270-
QByteArray *ba = static_cast<QByteArray*>( mQry.value( col++ ).data() );
271-
if ( ba->size() > 0 )
270+
QByteArray ba( mQry.value( col++ ).toByteArray() );
271+
if ( ba.size() > 0 )
272272
{
273273
QgsGeometry g;
274-
g.fromWkb( *ba );
274+
g.fromWkb( ba );
275275
feature.setGeometry( g );
276276
}
277277
else
@@ -375,11 +375,11 @@ bool QgsOracleFeatureIterator::fetchFeature( QgsFeature& feature )
375375
QVariant v = mQry.value( col );
376376
if ( fld.type() == QVariant::ByteArray && fld.typeName().endsWith( ".SDO_GEOMETRY" ) )
377377
{
378-
QByteArray *ba = static_cast<QByteArray*>( v.data() );
379-
if ( ba->size() > 0 )
378+
QByteArray ba( v.toByteArray() );
379+
if ( ba.size() > 0 )
380380
{
381381
QgsGeometry g;
382-
g.fromWkb( *ba );
382+
g.fromWkb( ba );
383383
v = g.exportToWkt();
384384
}
385385
else

‎src/providers/oracle/qgsoracleprovider.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,9 +2244,9 @@ QgsRectangle QgsOracleProvider::extent() const
22442244

22452245
if ( ok && qry.next() )
22462246
{
2247-
QByteArray *ba = static_cast<QByteArray*>( qry.value( 0 ).data() );
2247+
QByteArray ba( qry.value( 0 ).toByteArray() );
22482248
QgsGeometry g;
2249-
g.fromWkb( *ba );
2249+
g.fromWkb( ba );
22502250
mLayerExtent = g.boundingBox();
22512251
QgsDebugMsg( "extent: " + mLayerExtent.toString() );
22522252
}

0 commit comments

Comments
 (0)
Please sign in to comment.