Skip to content

Commit 9eb4953

Browse files
committed
postgres provider: cosmetics (followup 09f410c)
1 parent 09f410c commit 9eb4953

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

src/providers/postgres/qgspostgresprovider.cpp

+22-15
Original file line numberDiff line numberDiff line change
@@ -656,25 +656,32 @@ bool QgsPostgresProvider::loadFields()
656656

657657
QgsPostgresResult result = connectionRO()->PQexec( sql );
658658

659-
QSet<QString> fields;
660-
661-
/* Collect type info */
662-
sql = "SELECT oid, typname,typtype,typelem,typlen FROM pg_type";
659+
// Collect type info
660+
sql = "SELECT oid,typname,typtype,typelem,typlen FROM pg_type";
663661
QgsPostgresResult typeResult = connectionRO()->PQexec( sql );
662+
663+
struct PGTypeInfo
664+
{
665+
QString typeName;
666+
QString typeType;
667+
QString typeElem;
668+
int typeLen;
669+
};
670+
664671
QMap<int, PGTypeInfo> typeMap;
665672
for ( int i = 0; i < typeResult.PQntuples(); ++i )
666673
{
667674
PGTypeInfo typeInfo =
668675
{
669-
/*typeName = */ typeResult.PQgetvalue( i, 1 ),
670-
/*typeType = */ typeResult.PQgetvalue( i, 2 ),
671-
/*typeElem = */ typeResult.PQgetvalue( i, 3 ),
672-
/*typeLen = */ typeResult.PQgetvalue( i, 4 ).toInt()
676+
/* typeName = */ typeResult.PQgetvalue( i, 1 ),
677+
/* typeType = */ typeResult.PQgetvalue( i, 2 ),
678+
/* typeElem = */ typeResult.PQgetvalue( i, 3 ),
679+
/* typeLen = */ typeResult.PQgetvalue( i, 4 ).toInt()
673680
};
674681
typeMap.insert( typeResult.PQgetvalue( i, 0 ).toInt(), typeInfo );
675682
}
676683

677-
/* Collect table oids */
684+
// Collect table oids
678685
QSet<int> tableoids;
679686
for ( int i = 0; i < result.PQnfields(); i++ )
680687
{
@@ -692,7 +699,7 @@ bool QgsPostgresProvider::loadFields()
692699

693700
QString tableoidsFilter = "(" + tableoidsList.join( "," ) + ")";
694701

695-
/* Collect formatted field types */
702+
// Collect formatted field types
696703
sql = "SELECT attrelid, attnum, pg_catalog.format_type(atttypid,atttypmod) FROM pg_attribute WHERE attrelid IN " + tableoidsFilter;
697704
QgsPostgresResult fmtFieldTypeResult = connectionRO()->PQexec( sql );
698705
QMap<int, QMap<int, QString> > fmtFieldTypeMap;
@@ -704,7 +711,7 @@ bool QgsPostgresProvider::loadFields()
704711
fmtFieldTypeMap[attrelid][attnum] = formatType;
705712
}
706713

707-
/* Collect descriptions */
714+
// Collect descriptions
708715
sql = "SELECT objoid, objsubid, description FROM pg_description WHERE objoid IN " + tableoidsFilter;
709716
QgsPostgresResult descrResult = connectionRO()->PQexec( sql );
710717
QMap<int, QMap<int, QString> > descrMap;
@@ -716,6 +723,7 @@ bool QgsPostgresProvider::loadFields()
716723
descrMap[objoid][objsubid] = descr;
717724
}
718725

726+
QSet<QString> fields;
719727
mAttributeFields.clear();
720728
for ( int i = 0; i < result.PQnfields(); i++ )
721729
{
@@ -1952,6 +1960,7 @@ bool QgsPostgresProvider::addAttributes( const QList<QgsField> &attributes )
19521960
{
19531961
conn->begin();
19541962

1963+
QString delim = "";
19551964
QString sql = QString( "ALTER TABLE %1 " ).arg( mQuery );
19561965
for ( QList<QgsField>::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter )
19571966
{
@@ -1966,11 +1975,9 @@ bool QgsPostgresProvider::addAttributes( const QList<QgsField> &attributes )
19661975
if ( iter->length() > 0 && iter->precision() >= 0 )
19671976
type = QString( "%1(%2,%3)" ).arg( type ).arg( iter->length() ).arg( iter->precision() );
19681977
}
1969-
sql.append( QString( "ADD COLUMN %1 %2, " ).arg( quotedIdentifier( iter->name() ) ).arg( type ) );
1978+
sql.append( QString( "%1ADD COLUMN %2 %3" ).arg( delim ).arg( quotedIdentifier( iter->name() ) ).arg( type ) );
1979+
delim = ",";
19701980
}
1971-
sql.chop( 2 ); /* ", " */
1972-
sql.append( ";" );
1973-
QgsDebugMsg( sql );
19741981

19751982
//send sql statement and do error handling
19761983
QgsPostgresResult result = conn->PQexec( sql );

src/providers/postgres/qgspostgresprovider.h

-8
Original file line numberDiff line numberDiff line change
@@ -455,14 +455,6 @@ class QgsPostgresProvider : public QgsVectorDataProvider
455455
QString mWhat;
456456
};
457457

458-
struct PGTypeInfo
459-
{
460-
QString typeName;
461-
QString typeType;
462-
QString typeElem;
463-
int typeLen;
464-
};
465-
466458
// A function that determines if the given schema.table.column
467459
// contains unqiue entries
468460
bool uniqueData( QString query, QString colName );

0 commit comments

Comments
 (0)