Skip to content

Commit ce3737e

Browse files
committedMay 29, 2017
[mssql] Fix time fields converted to null
Likely only an issue when using the MSSQL Linux ODBC driver
1 parent 4081927 commit ce3737e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed
 

‎src/providers/mssql/qgsmssqlfeatureiterator.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,25 @@ bool QgsMssqlFeatureIterator::fetchFeature( QgsFeature& feature )
301301
{
302302
QVariant v = mQuery->value( i );
303303
const QgsField &fld = mSource->mFields.at( mAttributesToFetch.at( i ) );
304-
if ( v.type() != fld.type() )
304+
305+
// special handling for time fields
306+
if ( fld.type() == QVariant::Time && v.type() == QVariant::ByteArray )
307+
{
308+
QList<QByteArray> parts = v.toByteArray().split( '\0' );
309+
if ( parts.count() >= 3 )
310+
{
311+
int hours = QString( parts.at( 0 ) ).at( 0 ).toAscii();
312+
int minutes = QString( parts.at( 1 ) ).at( 0 ).toAscii();
313+
int seconds = QString( parts.at( 2 ) ).at( 0 ).toAscii();
314+
v = QTime( hours, minutes, seconds );
315+
}
316+
else
317+
v = QgsVectorDataProvider::convertValue( fld.type(), v.toString() );
318+
}
319+
else if ( v.type() != fld.type() )
320+
{
305321
v = QgsVectorDataProvider::convertValue( fld.type(), v.toString() );
322+
}
306323
feature.setAttribute( mAttributesToFetch.at( i ), v );
307324
}
308325

0 commit comments

Comments
 (0)
Please sign in to comment.