Skip to content

Commit f601083

Browse files
Maksim Rylovmrylov
authored andcommittedDec 7, 2020
Minor fixes in qgshanaresultset.cpp
1 parent b2a6e57 commit f601083

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed
 

‎src/providers/hana/qgshanaresultset.cpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,30 +101,35 @@ QVariant QgsHanaResultSet::getValue( unsigned short columnIndex )
101101
return QgsHanaUtils::toVariant( mResultSet->getBoolean( columnIndex ), QVariant::Bool );
102102
case SQLDataTypes::Char:
103103
{
104+
String str = mResultSet->getString( columnIndex );
104105
if ( mMetadata->getColumnLength( columnIndex ) == 1 )
105106
{
106-
Byte value = mResultSet->getByte( columnIndex );
107-
if ( value.isNull() )
107+
if ( str.isNull() || str->empty() )
108108
return QVariant( QVariant::Char );
109109
else
110-
return QVariant( QChar( *value ) );
110+
return QVariant( QChar( str->at( 0 ) ) );
111111
}
112112
else
113-
return QgsHanaUtils::toVariant( mResultSet->getString( columnIndex ) );
113+
return QgsHanaUtils::toVariant( str );
114114
}
115115
case SQLDataTypes::WChar:
116+
{
117+
NString str = mResultSet->getNString( columnIndex );
116118
if ( mMetadata->getColumnLength( columnIndex ) == 1 )
117119
{
118-
UByte value = mResultSet->getUByte( columnIndex );
119-
if ( value.isNull() )
120+
if ( str.isNull() || str->empty() )
120121
return QVariant( QVariant::Char );
121122
else
122-
return QVariant( QChar( *value ) );
123+
return QVariant( QChar( str->at( 0 ) ) );
123124
}
124125
else
125-
return QgsHanaUtils::toVariant( mResultSet->getNString( columnIndex ) );
126+
return QgsHanaUtils::toVariant( str );
127+
}
126128
case SQLDataTypes::TinyInt:
127-
return QgsHanaUtils::toVariant( mResultSet->getUByte( columnIndex ) );
129+
if ( mMetadata ->isSigned( columnIndex ) )
130+
return QgsHanaUtils::toVariant( mResultSet->getByte( columnIndex ) );
131+
else
132+
return QgsHanaUtils::toVariant( mResultSet->getUByte( columnIndex ) );
128133
case SQLDataTypes::SmallInt:
129134
if ( mMetadata ->isSigned( columnIndex ) )
130135
return QgsHanaUtils::toVariant( mResultSet->getShort( columnIndex ) );
@@ -174,34 +179,32 @@ QVariant QgsHanaResultSet::getValue( unsigned short columnIndex )
174179

175180
QgsGeometry QgsHanaResultSet::getGeometry( unsigned short columnIndex )
176181
{
177-
auto createGeometry = []( const char *data, size_t size )
182+
auto toWkbSize = []( size_t size )
178183
{
179-
if ( size == 0 || data == nullptr )
180-
return QgsGeometry();
181-
182184
if ( size > static_cast<size_t>( std::numeric_limits<int>::max() ) )
183185
throw QgsHanaException( "Geometry size is larger than maximum integer value" );
184-
185-
QByteArray wkbBytes( data, static_cast<int>( size ) );
186-
QgsGeometry geom;
187-
geom.fromWkb( wkbBytes );
188-
return geom;
186+
return static_cast<int>( size );
189187
};
190188

191189
size_t bufLength = mResultSet->getBinaryLength( columnIndex );
192190
if ( bufLength == ResultSet::UNKNOWN_LENGTH )
193191
{
194192
Binary wkb = mResultSet->getBinary( columnIndex );
195-
if ( wkb.isNull() || wkb->size() == 0 )
196-
return QgsGeometry();
197-
else
198-
return createGeometry( wkb->data(), wkb->size() );
193+
if ( !wkb.isNull() && wkb->size() > 0 )
194+
{
195+
QByteArray wkbBytes( wkb->data(), toWkbSize( wkb->size() ) );
196+
QgsGeometry geom;
197+
geom.fromWkb( wkbBytes );
198+
return geom;
199+
}
199200
}
200201
else if ( bufLength != 0 && bufLength != odbc::ResultSet::NULL_DATA )
201202
{
202-
mBuffer.resize( bufLength );
203-
mResultSet->getBinaryData( columnIndex, mBuffer.data(), bufLength );
204-
return createGeometry( mBuffer.data(), bufLength );
203+
QByteArray wkbBytes( toWkbSize( bufLength ), '0' );
204+
mResultSet->getBinaryData( columnIndex, wkbBytes.data(), bufLength );
205+
QgsGeometry geom;
206+
geom.fromWkb( wkbBytes );
207+
return geom;
205208
}
206209

207210
return QgsGeometry();

‎src/providers/hana/qgshanaresultset.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "qgsgeometry.h"
2121

2222
#include <memory>
23-
#include <vector>
2423

2524
#include <QString>
2625
#include <QVariant>
@@ -57,7 +56,6 @@ class QgsHanaResultSet
5756
private:
5857
odbc::ResultSetRef mResultSet;
5958
odbc::ResultSetMetaDataUnicodeRef mMetadata;
60-
std::vector<char> mBuffer;
6159
};
6260

6361
#endif // QGSHANARESULTSET_H

0 commit comments

Comments
 (0)
Please sign in to comment.