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 174 of file shp2pgsql-core.c.
175{
176
177
178
179
180
181
182
183 char *result;
184 char *ptr, *optr;
185 int toescape = 0;
186 size_t size;
187
189
190
191 while (*ptr)
192 {
193 if (*ptr == '\'')
194 toescape++;
195
196 ptr++;
197 }
198
199
200 if (toescape == 0)
202
203 size = ptr -
str + toescape + 1;
204 result = calloc(1, size);
205 optr = result;
207
208 while (*ptr)
209 {
210 if (*ptr == '\'')
211 *optr++='\'';
212
213 *optr++ = *ptr++;
214 }
215
216 *optr='\0';
217
218 return result;
219}
References str.
Referenced by ShpLoaderGenerateSQLRowStatement().