Skip to content
Permalink
Browse files

[mssql] Fix time fields converted to null

Likely only an issue when using the MSSQL Linux ODBC driver
  • Loading branch information
nyalldawson committed May 29, 2017
1 parent 4081927 commit ce3737ec7fe497a24f11266bd33b865cae828e0b
Showing with 18 additions and 1 deletion.
  1. +18 −1 src/providers/mssql/qgsmssqlfeatureiterator.cpp
@@ -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 );
}

0 comments on commit ce3737e

Please sign in to comment.
You can’t perform that action at this time.