[QGIS Commit] r10968 - trunk/qgis/src/providers/postgres
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Tue Jun 23 08:35:24 EDT 2009
Author: jef
Date: 2009-06-23 08:35:23 -0400 (Tue, 23 Jun 2009)
New Revision: 10968
Modified:
trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
Log:
reindent postgres provider
Modified: trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
===================================================================
--- trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp 2009-06-23 12:03:18 UTC (rev 10967)
+++ trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp 2009-06-23 12:35:23 UTC (rev 10968)
@@ -1686,8 +1686,8 @@
QString typeName;
//find out type of index
- QgsFieldMap::const_iterator f_it = attributeFields.find(index);
- if(f_it != attributeFields.constEnd())
+ QgsFieldMap::const_iterator f_it = attributeFields.find( index );
+ if ( f_it != attributeFields.constEnd() )
{
typeName = f_it.value().typeName();
}
@@ -1697,19 +1697,19 @@
}
//is type an enum?
- QString typeSql = QString("SELECT typtype FROM pg_type where typname = %1").arg(quotedValue(typeName));
+ QString typeSql = QString( "SELECT typtype FROM pg_type where typname = %1" ).arg( quotedValue( typeName ) );
Result typeRes = connectionRO->PQexec( typeSql );
- if ( PQresultStatus( typeRes ) != PGRES_TUPLES_OK || PQntuples(typeRes) < 1)
+ if ( PQresultStatus( typeRes ) != PGRES_TUPLES_OK || PQntuples( typeRes ) < 1 )
{
return;
}
QString typtype = PQgetvalue( typeRes, 0, 0 );
- if(typtype.compare("e", Qt::CaseInsensitive) == 0)
+ if ( typtype.compare( "e", Qt::CaseInsensitive ) == 0 )
{
//try to read enum_range of attribute
- if(!parseEnumRange(enumList, f_it->name()))
+ if ( !parseEnumRange( enumList, f_it->name() ) )
{
enumList.clear();
}
@@ -1717,37 +1717,37 @@
else
{
//is there a domain check constraint for the attribute?
- if(!parseDomainCheckConstraint(enumList, f_it->name()))
+ if ( !parseDomainCheckConstraint( enumList, f_it->name() ) )
{
- enumList.clear();
+ enumList.clear();
}
}
}
-bool QgsPostgresProvider::parseEnumRange(QStringList& enumValues, const QString& attributeName) const
+bool QgsPostgresProvider::parseEnumRange( QStringList& enumValues, const QString& attributeName ) const
{
enumValues.clear();
- QString enumRangeSql = QString("SELECT enum_range(%1) from %2 limit1").arg(quotedIdentifier(attributeName)).arg(mSchemaTableName);
- Result enumRangeRes = connectionRO->PQexec(enumRangeSql);
- if ( PQresultStatus( enumRangeRes ) == PGRES_TUPLES_OK && PQntuples(enumRangeRes) > 0)
+ QString enumRangeSql = QString( "SELECT enum_range(%1) from %2 limit1" ).arg( quotedIdentifier( attributeName ) ).arg( mSchemaTableName );
+ Result enumRangeRes = connectionRO->PQexec( enumRangeSql );
+ if ( PQresultStatus( enumRangeRes ) == PGRES_TUPLES_OK && PQntuples( enumRangeRes ) > 0 )
{
- QString enumRangeString = PQgetvalue(enumRangeRes, 0, 0);
+ QString enumRangeString = PQgetvalue( enumRangeRes, 0, 0 );
//strip away the brackets at begin and end
- enumRangeString.chop(1);
- enumRangeString.remove(0, 1);
- QStringList rangeSplit = enumRangeString.split(",");
+ enumRangeString.chop( 1 );
+ enumRangeString.remove( 0, 1 );
+ QStringList rangeSplit = enumRangeString.split( "," );
QStringList::const_iterator range_it = rangeSplit.constBegin();
- for(; range_it != rangeSplit.constEnd(); ++range_it)
+ for ( ; range_it != rangeSplit.constEnd(); ++range_it )
{
QString currentEnumValue = *range_it;
//remove quotes from begin and end of the value
- if(currentEnumValue.startsWith("'") || currentEnumValue.startsWith("\""))
+ if ( currentEnumValue.startsWith( "'" ) || currentEnumValue.startsWith( "\"" ) )
{
- currentEnumValue.remove(0, 1);
+ currentEnumValue.remove( 0, 1 );
}
- if(currentEnumValue.endsWith("'") || currentEnumValue.endsWith("\""))
+ if ( currentEnumValue.endsWith( "'" ) || currentEnumValue.endsWith( "\"" ) )
{
- currentEnumValue.chop(1);
+ currentEnumValue.chop( 1 );
}
enumValues << currentEnumValue;
}
@@ -1756,49 +1756,49 @@
return false;
}
-bool QgsPostgresProvider::parseDomainCheckConstraint(QStringList& enumValues, const QString& attributeName) const
+bool QgsPostgresProvider::parseDomainCheckConstraint( QStringList& enumValues, const QString& attributeName ) const
{
enumValues.clear();
//is it a domain type with a check constraint?
- QString domainSql = QString("SELECT domain_name from information_schema.columns where table_name = %1 and column_name = %2").arg(quotedValue(mTableName)).arg(quotedValue(attributeName));
- Result domainResult = connectionRO->PQexec(domainSql);
- if ( PQresultStatus( domainResult ) == PGRES_TUPLES_OK && PQntuples(domainResult) > 0)
+ QString domainSql = QString( "SELECT domain_name from information_schema.columns where table_name = %1 and column_name = %2" ).arg( quotedValue( mTableName ) ).arg( quotedValue( attributeName ) );
+ Result domainResult = connectionRO->PQexec( domainSql );
+ if ( PQresultStatus( domainResult ) == PGRES_TUPLES_OK && PQntuples( domainResult ) > 0 )
{
//a domain type
- QString domainCheckDefinitionSql = QString("SELECT consrc FROM pg_constraint where conname = (SELECT constraint_name FROM information_schema.domain_constraints WHERE domain_name = %1)").arg(quotedValue(PQgetvalue(domainResult, 0, 0)));
- Result domainCheckRes = connectionRO->PQexec(domainCheckDefinitionSql);
- if ( PQresultStatus(domainCheckRes) == PGRES_TUPLES_OK && PQntuples(domainCheckRes) > 0)
+ QString domainCheckDefinitionSql = QString( "SELECT consrc FROM pg_constraint where conname = (SELECT constraint_name FROM information_schema.domain_constraints WHERE domain_name = %1)" ).arg( quotedValue( PQgetvalue( domainResult, 0, 0 ) ) );
+ Result domainCheckRes = connectionRO->PQexec( domainCheckDefinitionSql );
+ if ( PQresultStatus( domainCheckRes ) == PGRES_TUPLES_OK && PQntuples( domainCheckRes ) > 0 )
{
- QString checkDefinition = PQgetvalue(domainCheckRes, 0, 0);
+ QString checkDefinition = PQgetvalue( domainCheckRes, 0, 0 );
//we assume that the constraint is of the following form:
//(VALUE = ANY (ARRAY['a'::text, 'b'::text, 'c'::text, 'd'::text]))
//normally, postgresql creates that if the contstraint has been specified as 'VALUE in ('a', 'b', 'c', 'd')
//todo: ANY must occure before ARRAY
- int anyPos = checkDefinition.indexOf("VALUE = ANY");
- int arrayPosition = checkDefinition.lastIndexOf("ARRAY[");
- int closingBracketPos = checkDefinition.indexOf("]", arrayPosition + 6);
+ int anyPos = checkDefinition.indexOf( "VALUE = ANY" );
+ int arrayPosition = checkDefinition.lastIndexOf( "ARRAY[" );
+ int closingBracketPos = checkDefinition.indexOf( "]", arrayPosition + 6 );
- if(anyPos == -1 || anyPos >= arrayPosition)
+ if ( anyPos == -1 || anyPos >= arrayPosition )
{
return false; //constraint has not the required format
}
- if(arrayPosition != -1)
+ if ( arrayPosition != -1 )
{
- QString valueList = checkDefinition.mid(arrayPosition + 6, closingBracketPos);
- QStringList commaSeparation = valueList.split(",", QString::SkipEmptyParts);
+ QString valueList = checkDefinition.mid( arrayPosition + 6, closingBracketPos );
+ QStringList commaSeparation = valueList.split( ",", QString::SkipEmptyParts );
QStringList::const_iterator cIt = commaSeparation.constBegin();
- for(; cIt != commaSeparation.constEnd(); ++cIt)
+ for ( ; cIt != commaSeparation.constEnd(); ++cIt )
{
//get string between ''
- int beginQuotePos = cIt->indexOf("'");
- int endQuotePos = cIt->lastIndexOf("'");
- if(beginQuotePos != -1 && (endQuotePos - beginQuotePos) > 1)
+ int beginQuotePos = cIt->indexOf( "'" );
+ int endQuotePos = cIt->lastIndexOf( "'" );
+ if ( beginQuotePos != -1 && ( endQuotePos - beginQuotePos ) > 1 )
{
- enumValues << cIt->mid(beginQuotePos + 1, endQuotePos - beginQuotePos - 1);
+ enumValues << cIt->mid( beginQuotePos + 1, endQuotePos - beginQuotePos - 1 );
}
}
}
More information about the QGIS-commit
mailing list