Opened 18 years ago
Last modified 13 years ago
#1536 closed defect
Mapserver postgis driver does not quote field names with special characters — at Initial Version
Reported by: | szekerest | Owned by: | refractions |
---|---|---|---|
Priority: | normal | Milestone: | 6.0 release |
Component: | PostGIS Interface | Version: | 5.6 |
Severity: | normal | Keywords: | |
Cc: | jerry.pisk@… |
Description
Mapserver postgis driver does not quote field names with special characters, (eg with code<=32 or code >=128), that causes syntax error on the server. Field with special characters must be placed between double quotes when constructing the SQL query string. To fix this issue the following code fragments in mappostgis.c for(t = 0; t < layer->numitems; t++) { length += strlen(layer->items[t]) + 7; } columns_wanted = (char *) malloc(length + 1); *columns_wanted = 0; for(t = 0; t < layer->numitems; t++) { strcat(columns_wanted, layer->items[t]); strcat(columns_wanted, "::text,"); } might be replaced with for(t = 0; t < layer->numitems; t++) { if (must_quote(layer->items[t])) length += strlen(layer->items[t]) + 9; else length += strlen(layer->items[t]) + 7; } columns_wanted = (char *) malloc(length + 1); *columns_wanted = 0; for(t = 0; t < layer->numitems; t++) { if (must_quote(layer->items[t])) { strcat(columns_wanted, "\""); strcat(columns_wanted, layer->items[t]); strcat(columns_wanted, "\""); } else strcat(columns_wanted, layer->items[t]); strcat(columns_wanted, "::text,"); } and the following function might be added: static int must_quote(char* field_name) { int i; int len = strlen(field_name); for (i = 0; i < len; i++) { if (field_name[i] <= 32 || field_name[i] >= 128) return 1; } return 0; } Tamas
Note:
See TracTickets
for help on using tickets.