Feature request #954
PostGIS tables with uppercase column names do not display/edit data
|Pull Request or Patch supplied:||Resolution:||fixed|
|Easy fix?:||No||Copied to github as #:||11013|
On PostGIS/PostgreSQL tables that have uppercase and other special characters in their column names, I have noticed that:
1. Identify, Attribute Table, MapTips don't display values for column names that have uppercase, but the column name is displayed (if appropriate)
2. when opening Attribute Table there are messages on the console like: "column number -1 is out of range 0..7" - one message for each such attribute (the range shown varies with the number of columns in the table)
3. couldn't add or delete such columns
4. couldn't update such columns
So, trying my hand at fixing PostgreSQL object name quoting, I have modified qgspostgresprovider.cpp in four places as shown in the attached patch file.
I have added \\" before and after the affected PostgreSQL object names in the query strings being constructed.
A code enhancement would be to add a function like quoteIdentifier() that takes a string (the identifier) and adds double quotes on both ends. Then any use of an identifier in a SQL string would be like: "SELECT " + quoteIdentifier(someString) + "..." This seems like extra work but I believe it leads to fewer mistakes as adding the quotes in-line is tedious and sometimes confusing as to exactly where in the string they go. This would also give a single place to add other processing on an identifier if it were ever necessary.
I would be willing to give this a try.
#1 Updated by Steven Mizuno over 12 years ago
replaced the patch attachment with a corrected file as I discovered some extra spaces were being added to the column name in the ADD column part of the patch.
Changed Platform to All as this problem affects all platforms as far as I can tell.
I failed to note that the patch fixes all of the problems listed.