Skip to content
Permalink
Browse files

[spatialite provider] Fix timestamp/datetime conversion failure when …

…timezone present
  • Loading branch information
nirvn committed Nov 10, 2020
1 parent fe05aad commit b2f49f003d0c7326d90ff98585c6208af15949ea
@@ -613,7 +613,7 @@ QVariant QgsSpatiaLiteFeatureIterator::getFeatureAttribute( sqlite3_stmt *stmt,
else if ( type == QVariant::DateTime )
{
// first use the GDAL date format
QDateTime dt = QDateTime::fromString( txt, QStringLiteral( "yyyy-MM-ddThh:mm:ss" ) );
QDateTime dt = QDateTime::fromString( txt, Qt::ISODate );
if ( !dt.isValid() )
{
// if that fails, try SQLite's default date format
@@ -3975,7 +3975,7 @@ QSet<QVariant> QgsSpatiaLiteProvider::uniqueValues( int index, int limit ) const
const QString txt = QString::fromUtf8( ( const char * ) sqlite3_column_text( stmt, 0 ) );
if ( mAttributeFields.at( index ).type() == QVariant::DateTime )
{
QDateTime dt = QDateTime::fromString( txt, QStringLiteral( "yyyy-MM-ddThh:mm:ss" ) );
QDateTime dt = QDateTime::fromString( txt, Qt::ISODate );
if ( !dt.isValid() )
{
// if that fails, try SQLite's default date format
@@ -4288,7 +4288,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList &flist, Flags flags )
else if ( type == QVariant::DateTime )
{
QDateTime dt = v.toDateTime();
QByteArray ba = dt.toString( QStringLiteral( "yyyy-MM-ddThh:mm:ss" ) ).toUtf8();
QByteArray ba = dt.toString( Qt::ISODate ).toUtf8();
sqlite3_bind_text( stmt, ++ia, ba.constData(), ba.size(), SQLITE_TRANSIENT );
}
else if ( type == QVariant::Date )
@@ -4680,7 +4680,7 @@ bool QgsSpatiaLiteProvider::changeAttributeValues( const QgsChangedAttributesMap
}
else if ( type == QVariant::DateTime )
{
sql += QStringLiteral( "%1=%2" ).arg( QgsSqliteUtils::quotedIdentifier( fld.name() ), QgsSqliteUtils::quotedString( val.toDateTime().toString( QStringLiteral( "yyyy-MM-ddThh:mm:ss" ) ) ) );
sql += QStringLiteral( "%1=%2" ).arg( QgsSqliteUtils::quotedIdentifier( fld.name() ), QgsSqliteUtils::quotedString( val.toDateTime().toString( Qt::ISODate ) ) );
}
else if ( type == QVariant::Date )
{

0 comments on commit b2f49f0

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