mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-12 00:02:25 -04:00
mssql provider: improve datetime support (fixes #12461)
This commit is contained in:
parent
cce3bb206e
commit
018cdd25da
@ -309,16 +309,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 ) )
|
||||
{
|
||||
@ -877,6 +877,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] );
|
||||
@ -1117,6 +1132,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 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user