Skip to content

Commit

Permalink
[mssql] Fix time fields converted to null
Browse files Browse the repository at this point in the history
Likely only an issue when using the MSSQL Linux ODBC driver
  • Loading branch information
nyalldawson committed May 29, 2017
1 parent 4081927 commit ce3737e
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/providers/mssql/qgsmssqlfeatureiterator.cpp
Expand Up @@ -301,8 +301,25 @@ bool QgsMssqlFeatureIterator::fetchFeature( QgsFeature& feature )
{
QVariant v = mQuery->value( i );
const QgsField &fld = mSource->mFields.at( mAttributesToFetch.at( i ) );
if ( v.type() != fld.type() )

// special handling for time fields
if ( fld.type() == QVariant::Time && v.type() == QVariant::ByteArray )
{
QList<QByteArray> parts = v.toByteArray().split( '\0' );
if ( parts.count() >= 3 )
{
int hours = QString( parts.at( 0 ) ).at( 0 ).toAscii();
int minutes = QString( parts.at( 1 ) ).at( 0 ).toAscii();
int seconds = QString( parts.at( 2 ) ).at( 0 ).toAscii();
v = QTime( hours, minutes, seconds );
}
else
v = QgsVectorDataProvider::convertValue( fld.type(), v.toString() );
}
else if ( v.type() != fld.type() )
{
v = QgsVectorDataProvider::convertValue( fld.type(), v.toString() );
}
feature.setAttribute( mAttributesToFetch.at( i ), v );
}

Expand Down

0 comments on commit ce3737e

Please sign in to comment.