@@ -170,8 +170,8 @@ QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
170
170
getFeatureCount ();
171
171
172
172
// Get the relation oid for use in later queries
173
- sql = " select oid from pg_class where relname = '" + mTableName + " ' and relnamespace = ("
174
- " select oid from pg_namespace where nspname = '" + mSchemaName + " ')" ;
173
+ sql = " SELECT oid FROM pg_class WHERE relname = '" + mTableName + " ' AND relnamespace = ("
174
+ " SELECT oid FROM pg_namespace WHERE nspname = '" + mSchemaName + " ')" ;
175
175
PGresult *tresult= PQexec (pd, (const char *)(sql.utf8 ()));
176
176
QString tableoid = PQgetvalue (tresult, 0 , 0 );
177
177
PQclear (tresult);
@@ -190,7 +190,7 @@ to the rest of qgis...
190
190
191
191
// Populate the field vector for this layer. The field vector contains
192
192
// field name, type, length, and precision (if numeric)
193
- sql = " select * from " + mSchemaTableName + " limit 1 " ;
193
+ sql = " select * from " + mSchemaTableName + " limit 0 " ;
194
194
195
195
PGresult *result = PQexec (pd, (const char *) (sql.utf8 ()));
196
196
// --std::cout << "Field: Name, Type, Size, Modifier:" << std::endl;
@@ -206,30 +206,24 @@ to the rest of qgis...
206
206
int fieldModifier = PQfmod (result, i);
207
207
QString fieldComment (" " );
208
208
209
- sql = " select typelem from pg_type where typelem = " + typOid + " and typlen = -1" ;
210
- // //--std::cout << sql << std::endl;
211
- PGresult *oidResult = PQexec (pd, (const char *) sql);
212
- // get the oid of the "real" type
213
- QString poid = PQgetvalue (oidResult, 0 , PQfnumber (oidResult, " typelem" ));
214
- PQclear (oidResult);
209
+ sql = " SELECT typname, typlen FROM pg_type WHERE "
210
+ " oid = (SELECT typelem FROM pg_type WHERE "
211
+ " typelem = " + typOid + " AND typlen = -1)" ;
215
212
216
- sql = " select typname, typlen from pg_type where oid = " + poid;
217
- // //--std::cout << sql << std::endl;
218
- oidResult = PQexec (pd, (const char *) sql);
213
+ PGresult* oidResult = PQexec (pd, (const char *) sql);
219
214
QString fieldType = PQgetvalue (oidResult, 0 , 0 );
220
215
QString fieldSize = PQgetvalue (oidResult, 0 , 1 );
221
216
PQclear (oidResult);
222
217
223
- sql = " select attnum from pg_attribute where attrelid = " + tableoid + " and attname = '" + fieldName + " '" ;
218
+ sql = " SELECT attnum FROM pg_attribute WHERE "
219
+ " attrelid = " + tableoid + " AND attname = '" + fieldName + " '" ;
224
220
PGresult *tresult = PQexec (pd, (const char *)(sql.utf8 ()));
225
221
QString attnum = PQgetvalue (tresult, 0 , 0 );
226
222
PQclear (tresult);
227
223
228
- sql = " SELECT description FROM pg_description WHERE objoid = " + tableoid +
229
- " AND objsubid = " + attnum;
230
-
224
+ sql = " SELECT description FROM pg_description WHERE "
225
+ " objoid = " + tableoid + " AND objsubid = " + attnum;
231
226
tresult = PQexec (pd, (const char *)(sql.utf8 ()));
232
-
233
227
if (PQntuples (tresult) > 0 )
234
228
fieldComment = PQgetvalue (tresult, 0 , 0 );
235
229
PQclear (tresult);
0 commit comments