Bug report #938
table editor can't search in varchar columns of PostGIS layers
|Affected QGIS version:||Regression?:||No|
|Operating System:||Debian||Easy fix?:||No|
|Pull Request or Patch supplied:||Resolution:||fixed|
|Crashes QGIS or corrupts data:||Copied to github as #:||10997|
1. Add a PostGIS layer with varchar field.
2. "Open Table"
3. The varchar column name is not available in the combo box with column names in the bottom. An empty slot there instead.
4. If you select this empty one, enter a string in "Search for:" field ann press search, a "Search string parsing error:" windows pops up which reads:
syntax error, unexpected COMPARISON
BTW - why is the "varchar(30)" forced in the add column dialog? If the lenght can't be made optional easily, why not force "varchar(256)" instead and not force the user to use "text" for anything longer than 30 chars?
SVN r8110, built and running against QT 4.3.3 and QT 4.3.2 on the other machine.
#1 Updated by Steven Mizuno almost 13 years ago
I find that there is a blank item in the drop-down list AND the last column in the table is missing from the list. This doesn't occur for all tables. The missing column may be of any type.
The blank list item follows a column used by QGIS for the feature id (the primary key or unique index, SERIAL4/INT4 type in the table) and that the last column is not in the list. If the feature id is last there is no blank item.
The number of items in the list matches the number of columns that should be listed (the geometry column is not listed).
Also have checked with 0.9.1 (same building and on Windows XP, binary package) and it has the same problem.
#2 Updated by Steven Mizuno almost 13 years ago
I just realized that I wasn't paying attention to the position of the geometry column. It is at the position of the geometry column that the blank list item occurs, not following the feature id column.
This can be shown by building a table where the feature id column is first, then a column of a type other than geometry, the geometry column, then two more columns of a type other than geometry.
The drop-down list for this table will be blank in the position where the geometry column is, then the first column after the geometry column is present, and the last column is missing.
#3 Updated by Steven Mizuno almost 13 years ago
On a further look at this problem: in QgsAttributeTableDisplay constructor where mSearchColumns is loaded the original code uses a standard C 'for' loop using an index counter and the number of fields as a terminating condition. Then, the fields variable is accessed by index, resulting in the blank at the position the geometry column is at and not accessing the last field.
I noticed that in qgsattributetable.cpp where the table header is loaded that an Iterator on a Map is used. I tried this idea to load mSearchColumns and it works.
Refer to the attached patch for the changes.
I have tested the patch on PostGIS layers as well as shapefile layers.