Skip to content

Commit

Permalink
mssql provider: improve datetime support (fixes #12461)
Browse files Browse the repository at this point in the history
(cherry-picked from 018cdd2)
  • Loading branch information
jef-n committed Jun 29, 2015
1 parent a4cfdcb commit 447825b
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions src/providers/mssql/qgsmssqlprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,16 +311,16 @@ QVariant::Type QgsMssqlProvider::DecodeSqlType( QString sqlTypeName )
{
type = QVariant::ByteArray;
}
else if ( sqlTypeName.startsWith( "date", Qt::CaseInsensitive ) )
{
type = QVariant::Date;
}
else if ( sqlTypeName.startsWith( "datetime", Qt::CaseInsensitive ) ||
sqlTypeName.startsWith( "smalldatetime", Qt::CaseInsensitive ) ||
sqlTypeName.startsWith( "datetime2", Qt::CaseInsensitive ) )
{
type = QVariant::DateTime;
}
else if ( sqlTypeName.startsWith( "date", Qt::CaseInsensitive ) )
{
type = QVariant::Date;
}
else if ( sqlTypeName.startsWith( "time", Qt::CaseInsensitive ) ||
sqlTypeName.startsWith( "timestamp", Qt::CaseInsensitive ) )
{
Expand Down Expand Up @@ -879,6 +879,21 @@ bool QgsMssqlProvider::addFeatures( QgsFeatureList & flist )
// binding a TEXT value
query.addBindValue( attrs[i].toString() );
}
else if ( type == QVariant::Time )
{
// binding a TIME value
query.addBindValue( attrs[i].toTime().toString( Qt::ISODate ) );
}
else if ( type == QVariant::Date )
{
// binding a DATE value
query.addBindValue( attrs[i].toDate().toString( Qt::ISODate ) );
}
else if ( type == QVariant::DateTime )
{
// binding a DATETIME value
query.addBindValue( attrs[i].toDateTime().toString( Qt::ISODate ) );
}
else
{
query.addBindValue( attrs[i] );
Expand Down Expand Up @@ -1119,6 +1134,21 @@ bool QgsMssqlProvider::changeAttributeValues( const QgsChangedAttributesMap &att
// binding a TEXT value
query.addBindValue( it2->toString() );
}
else if ( type == QVariant::DateTime )
{
// binding a DATETIME value
query.addBindValue( it2->toDateTime().toString( Qt::ISODate ) );
}
else if ( type == QVariant::Date )
{
// binding a DATE value
query.addBindValue( it2->toDate().toString( Qt::ISODate ) );
}
else if ( type == QVariant::Time )
{
// binding a TIME value
query.addBindValue( it2->toTime().toString( Qt::ISODate ) );
}
else
{
query.addBindValue( *it2 );
Expand Down

0 comments on commit 447825b

Please sign in to comment.