PostGIS  2.1.10dev-r@@SVN_REVISION@@
char * escape_insert_string ( char *  str)

Escape input string suitable for INSERT.

If no characters require escaping, simply return the input pointer. Otherwise return a new allocated string.

Definition at line 194 of file shp2pgsql-core.c.

References result.

Referenced by ShpLoaderGenerateSQLRowStatement().

195 {
196  /*
197  * Escape single quotes by adding a preceding single quote
198  *
199  * 1. find # of characters
200  * 2. make new string
201  */
202 
203  char *result;
204  char *ptr, *optr;
205  int toescape = 0;
206  size_t size;
207 
208  ptr = str;
209 
210  /* Count how many characters we need to escape so we know the size of the string we need to return */
211  while (*ptr)
212  {
213  if (*ptr == '\'')
214  toescape++;
215 
216  ptr++;
217  }
218 
219  /* If we don't have to escape anything, simply return the input pointer */
220  if (toescape == 0)
221  return str;
222 
223  size = ptr - str + toescape + 1;
224  result = calloc(1, size);
225  optr = result;
226  ptr = str;
227 
228  while (*ptr)
229  {
230  if (*ptr == '\'')
231  *optr++='\'';
232 
233  *optr++ = *ptr++;
234  }
235 
236  *optr='\0';
237 
238  return result;
239 }
char ** result
Definition: liblwgeom.h:218

Here is the caller graph for this function: