PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ escape_insert_string()

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 176 of file shp2pgsql-core.c.

177{
178 /*
179 * Escape single quotes by adding a preceding single quote
180 *
181 * 1. find # of characters
182 * 2. make new string
183 */
184
185 char *result;
186 char *ptr, *optr;
187 int toescape = 0;
188 size_t size;
189
190 ptr = str;
191
192 /* Count how many characters we need to escape so we know the size of the string we need to return */
193 while (*ptr)
194 {
195 if (*ptr == '\'')
196 toescape++;
197
198 ptr++;
199 }
200
201 /* If we don't have to escape anything, simply return the input pointer */
202 if (toescape == 0)
203 return str;
204
205 size = ptr - str + toescape + 1;
206 result = calloc(1, size);
207 optr = result;
208 ptr = str;
209
210 while (*ptr)
211 {
212 if (*ptr == '\'')
213 *optr++='\'';
214
215 *optr++ = *ptr++;
216 }
217
218 *optr='\0';
219
220 return result;
221}
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
#define str(s)

References result, and str.

Referenced by ShpLoaderGenerateSQLRowStatement().

Here is the caller graph for this function: