Skip to content
Permalink
Browse files

Use QgsMessageLog instead of QgsLogger for parsing string methods

  • Loading branch information
troopa81 committed Feb 22, 2019
1 parent 46474b4 commit e9a9d9771575320983b82c63bc1cde75361f2230
Showing with 24 additions and 14 deletions.
  1. +14 −14 src/providers/postgres/qgspostgresprovider.cpp
  2. +10 −0 src/providers/postgres/qgspostgresprovider.h
@@ -4217,7 +4217,7 @@ static void jumpSpace( const QString &txt, int &i )
++i;
}

static QString getNextString( const QString &txt, int &i, const QString &sep )
QString QgsPostgresProvider::getNextString( const QString &txt, int &i, const QString &sep )
{
jumpSpace( txt, i );
QString cur = txt.mid( i );
@@ -4226,14 +4226,14 @@ static QString getNextString( const QString &txt, int &i, const QString &sep )
QRegExp stringRe( "^\"((?:\\\\.|[^\"\\\\])*)\".*" );
if ( !stringRe.exactMatch( cur ) )
{
QgsLogger::warning( "Cannot find end of double quoted string: " + txt );
QgsMessageLog::logMessage( tr( "Cannot find end of double quoted string: %1" ).arg( txt ), tr( "PostGIS" ) );
return QString();
}
i += stringRe.cap( 1 ).length() + 2;
jumpSpace( txt, i );
if ( !txt.midRef( i ).startsWith( sep ) && i < txt.length() )
{
QgsLogger::warning( "Cannot find separator: " + txt.mid( i ) );
QgsMessageLog::logMessage( tr( "Cannot find separator: %1" ).arg( txt.mid( i ) ), tr( "PostGIS" ) );
return QString();
}
i += sep.length();
@@ -4252,7 +4252,7 @@ static QString getNextString( const QString &txt, int &i, const QString &sep )
}
}

static QVariant parseHstore( const QString &txt )
QVariant QgsPostgresProvider::parseHstore( const QString &txt )
{
QVariantMap result;
int i = 0;
@@ -4262,7 +4262,7 @@ static QVariant parseHstore( const QString &txt )
QString value = getNextString( txt, i, QStringLiteral( "," ) );
if ( key.isNull() || value.isNull() )
{
QgsLogger::warning( "Error parsing hstore: " + txt );
QgsMessageLog::logMessage( tr( "Error parsing hstore: %1" ).arg( txt ), tr( "PostGIS" ) );
break;
}
result.insert( key, value );
@@ -4271,7 +4271,7 @@ static QVariant parseHstore( const QString &txt )
return result;
}

static QVariant parseJson( const QString &txt )
QVariant QgsPostgresProvider::parseJson( const QString &txt )
{
QVariant result;
QJsonDocument jsonResponse = QJsonDocument::fromJson( txt.toUtf8() );
@@ -4280,7 +4280,7 @@ static QVariant parseJson( const QString &txt )
return result;
}

static QVariant parseOtherArray( const QString &txt, QVariant::Type subType, const QString &typeName )
QVariant QgsPostgresProvider::parseOtherArray( const QString &txt, QVariant::Type subType, const QString &typeName )
{
int i = 0;
QVariantList result;
@@ -4289,15 +4289,15 @@ static QVariant parseOtherArray( const QString &txt, QVariant::Type subType, con
const QString value = getNextString( txt, i, QStringLiteral( "," ) );
if ( value.isNull() )
{
QgsLogger::warning( "Error parsing array: " + txt );
QgsMessageLog::logMessage( tr( "Error parsing array: %1" ).arg( txt ), tr( "PostGIS" ) );
break;
}
result.append( QgsPostgresProvider::convertValue( subType, QVariant::Invalid, value, typeName ) );
}
return result;
}

static QVariant parseStringArray( const QString &txt )
QVariant QgsPostgresProvider::parseStringArray( const QString &txt )
{
int i = 0;
QStringList result;
@@ -4306,20 +4306,20 @@ static QVariant parseStringArray( const QString &txt )
const QString value = getNextString( txt, i, QStringLiteral( "," ) );
if ( value.isNull() )
{
QgsLogger::warning( "Error parsing array: " + txt );
QgsMessageLog::logMessage( tr( "Error parsing array: %1" ).arg( txt ), tr( "PostGIS" ) );
break;
}
result.append( value );
}
return result;
}

static QVariant parseMultidimensionalArray( const QString &txt )
QVariant QgsPostgresProvider::parseMultidimensionalArray( const QString &txt )
{
QStringList result;
if ( !txt.startsWith( '{' ) || !txt.endsWith( '}' ) )
{
QgsLogger::warning( "Error parsing array, missing curly braces: " + txt );
QgsMessageLog::logMessage( tr( "Error parsing array, missing curly braces: %1" ).arg( txt ), tr( "PostGIS" ) );
return result;
}

@@ -4352,12 +4352,12 @@ static QVariant parseMultidimensionalArray( const QString &txt )

}

static QVariant parseArray( const QString &txt, QVariant::Type type, QVariant::Type subType, const QString &typeName )
QVariant QgsPostgresProvider::parseArray( const QString &txt, QVariant::Type type, QVariant::Type subType, const QString &typeName )
{
if ( !txt.startsWith( '{' ) || !txt.endsWith( '}' ) )
{
if ( !txt.isEmpty() )
QgsLogger::warning( "Error parsing array, missing curly braces: " + txt );
QgsMessageLog::logMessage( tr( "Error parsing array, missing curly braces: %1" ).arg( txt ), tr( "PostGIS" ) );
return QVariant( type );
}
QString inner = txt.mid( 1, txt.length() - 2 );
@@ -264,6 +264,16 @@ class QgsPostgresProvider : public QgsVectorDataProvider

QString geomParam( int offset ) const;


static QString getNextString( const QString &txt, int &i, const QString &sep );
static QVariant parseHstore( const QString &txt );
static QVariant parseJson( const QString &txt );
static QVariant parseOtherArray( const QString &txt, QVariant::Type subType, const QString &typeName );
static QVariant parseStringArray( const QString &txt );
static QVariant parseMultidimensionalArray( const QString &txt );
static QVariant parseArray( const QString &txt, QVariant::Type type, QVariant::Type subType, const QString &typeName );


/**
* Gets parametrized primary key clause
* \param offset specifies offset to use for the pk value parameter

0 comments on commit e9a9d97

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