Skip to content

Commit d996966

Browse files
committedMar 19, 2015
#5605 Support for long/longlong types
1 parent 6eb1b5b commit d996966

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed
 

‎src/providers/delimitedtext/qgsdelimitedtextprovider.cpp

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ QStringList QgsDelimitedTextProvider::readCsvtFieldTypes( QString filename, QStr
245245
// not allowed in OGR CSVT files. Also doesn't care if int and string fields have
246246

247247
strTypeList = strTypeList.toLower();
248-
QRegExp reTypeList( "^(?:\\s*(\\\"?)(?:integer|real|string|date|datetime|time)(?:\\(\\d+(?:\\.\\d+)?\\))?\\1\\s*(?:,|$))+" );
248+
QRegExp reTypeList( "^(?:\\s*(\\\"?)(?:integer|real|long|longlong|string|date|datetime|time)(?:\\(\\d+(?:\\.\\d+)?\\))?\\1\\s*(?:,|$))+" );
249249
if ( ! reTypeList.exactMatch( strTypeList ) )
250250
{
251251
// Looks like this was supposed to be a CSVT file, so report bad formatted string
@@ -407,6 +407,7 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )
407407

408408
QList<bool> isEmpty;
409409
QList<bool> couldBeInt;
410+
QList<bool> couldBeLongLong;
410411
QList<bool> couldBeDouble;
411412

412413
while ( true )
@@ -561,27 +562,28 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )
561562
{
562563

563564
QString &value = parts[i];
564-
if ( value.isEmpty() )
565-
continue;
566-
567-
// try to convert attribute values to integer and double
568-
569-
while ( couldBeInt.size() <= i )
570-
{
565+
if ( value.isEmpty() ) {
571566
isEmpty.append( true );
572567
couldBeInt.append( false );
568+
couldBeLongLong.append( false );
573569
couldBeDouble.append( false );
570+
continue;
574571
}
575-
if ( isEmpty[i] )
576-
{
577-
isEmpty[i] = false;
578-
couldBeInt[i] = true;
579-
couldBeDouble[i] = true;
580-
}
572+
// try to convert attribute values to integer, long and double
573+
isEmpty.append( false );
574+
// try all possible formats
575+
couldBeInt.append( true );
576+
couldBeLongLong.append( true );
577+
couldBeDouble.append( true );
581578
if ( couldBeInt[i] )
582579
{
583580
value.toInt( &couldBeInt[i] );
584581
}
582+
583+
if ( couldBeLongLong[i] )
584+
{
585+
value.toLongLong( &couldBeLongLong[i] );
586+
}
585587
if ( couldBeDouble[i] )
586588
{
587589
if ( ! mDecimalPoint.isEmpty() )
@@ -620,6 +622,11 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )
620622
fieldType = QVariant::Int;
621623
typeName = "integer";
622624
}
625+
else if ( csvtTypes[i] == "long" || csvtTypes[i]== "longlong" )
626+
{
627+
fieldType = QVariant::LongLong; //QVariant doesn't support long
628+
typeName = "longlong";
629+
}
623630
else if ( csvtTypes[i] == "real" )
624631
{
625632
fieldType = QVariant::Double;
@@ -633,6 +640,11 @@ void QgsDelimitedTextProvider::scanFile( bool buildIndexes )
633640
fieldType = QVariant::Int;
634641
typeName = "integer";
635642
}
643+
else if ( couldBeLongLong[i] )
644+
{
645+
fieldType = QVariant::LongLong;
646+
typeName = "longlong";
647+
}
636648
else if ( couldBeDouble[i] )
637649
{
638650
fieldType = QVariant::Double;
@@ -997,12 +1009,14 @@ bool QgsDelimitedTextProvider::setSubsetString( QString subset, bool updateFeatu
9971009

9981010
if ( valid )
9991011
{
1000-
1001-
if ( mSubsetExpression ) delete mSubsetExpression;
1012+
QgsExpression * tmpSubsetExpression = mSubsetExpression;
1013+
// using a tmp pointer to avoid the pointer being dereferenced by
1014+
// a friend class after it has been freed but before it has been
1015+
// reassigned
10021016
QString previousSubset = mSubsetString;
10031017
mSubsetString = subset;
10041018
mSubsetExpression = expression;
1005-
1019+
if ( tmpSubsetExpression ) delete tmpSubsetExpression;
10061020
// Update the feature count and extents if requested
10071021

10081022
// Usage of updateFeatureCount is a bit painful, basically expect that it

0 commit comments

Comments
 (0)