Function to parse the Mapserver DATA parameter for geometry * column name, table name and name of a column to serve as a * unique record id */
| 1752 | * unique record id |
| 1753 | */ |
| 1754 | static int msMSSQL2008LayerParseData(layerObj *layer, char **geom_column_name, char **geom_column_type, char **table_name, char **urid_name, char **user_srid, char **index_name, int debug) |
| 1755 | { |
| 1756 | char *pos_opt, *pos_scn, *tmp, *pos_srid, *pos_urid, *pos_geomtype, *pos_geomtype2, *pos_indexHint, *data; |
| 1757 | int slength; |
| 1758 | |
| 1759 | data = layer->data; |
| 1760 | |
| 1761 | /* given a string of the from 'geom from ctivalues' or 'geom from () as foo' |
| 1762 | * return geom_column_name as 'geom' |
| 1763 | * and table name as 'ctivalues' or 'geom from () as foo' |
| 1764 | */ |
| 1765 | |
| 1766 | /* First look for the optional ' using unique ID' string */ |
| 1767 | pos_urid = strstrIgnoreCase(data, " using unique "); |
| 1768 | |
| 1769 | if(pos_urid) { |
| 1770 | /* CHANGE - protect the trailing edge for thing like 'using unique ftab_id using srid=33' */ |
| 1771 | tmp = strstr(pos_urid + 14, " "); |
| 1772 | if(!tmp) { |
| 1773 | tmp = pos_urid + strlen(pos_urid); |
| 1774 | } |
| 1775 | *urid_name = (char *) msSmallMalloc((tmp - (pos_urid + 14)) + 1); |
| 1776 | strlcpy(*urid_name, pos_urid + 14, (tmp - (pos_urid + 14)) + 1); |
| 1777 | } |
| 1778 | |
| 1779 | /* Find the srid */ |
| 1780 | pos_srid = strstrIgnoreCase(data, " using SRID="); |
| 1781 | if(!pos_srid) { |
| 1782 | *user_srid = (char *) msSmallMalloc(2); |
| 1783 | (*user_srid)[0] = '0'; |
| 1784 | (*user_srid)[1] = 0; |
| 1785 | } else { |
| 1786 | slength = strspn(pos_srid + 12, "-0123456789"); |
| 1787 | if(!slength) { |
| 1788 | msSetError(MS_QUERYERR, DATA_ERROR_MESSAGE, "msMSSQL2008LayerParseData()", "Error parsing MSSQL2008 data variable: You specified 'using SRID=#' but didnt have any numbers!<br><br>\n\nMore Help:<br><br>\n\n", data); |
| 1789 | |
| 1790 | return MS_FAILURE; |
| 1791 | } else { |
| 1792 | *user_srid = (char *) msSmallMalloc(slength + 1); |
| 1793 | strlcpy(*user_srid, pos_srid + 12, slength+1); |
| 1794 | } |
| 1795 | } |
| 1796 | |
| 1797 | pos_indexHint = strstrIgnoreCase(data, " using index "); |
| 1798 | if(pos_indexHint) { |
| 1799 | /* CHANGE - protect the trailing edge for thing like 'using unique ftab_id using srid=33' */ |
| 1800 | tmp = strstr(pos_indexHint + 13, " "); |
| 1801 | if(!tmp) { |
| 1802 | tmp = pos_indexHint + strlen(pos_indexHint); |
| 1803 | } |
| 1804 | *index_name = (char *) msSmallMalloc((tmp - (pos_indexHint + 13)) + 1); |
| 1805 | strlcpy(*index_name, pos_indexHint + 13, tmp - (pos_indexHint + 13)+1); |
| 1806 | } |
| 1807 | |
| 1808 | /* this is a little hack so the rest of the code works. If the ' using SRID=' comes before */ |
| 1809 | /* the ' using unique ', then make sure pos_opt points to where the ' using SRID' starts! */ |
| 1810 | pos_opt = pos_urid; |
| 1811 | if ( !pos_opt || ( pos_srid && pos_srid < pos_opt ) ) pos_opt = pos_srid; |
no test coverage detected