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

◆ gserialized_typmod_in()

static uint32 gserialized_typmod_in ( ArrayType *  arr,
int  is_geography 
)
static

Definition at line 234 of file gserialized_typmod.c.

235{
236 int32 typmod = 0;
237 Datum *elem_values;
238 int n = 0;
239 int i = 0;
240
241 if (ARR_ELEMTYPE(arr) != CSTRINGOID)
242 ereport(ERROR,
243 (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
244 errmsg("typmod array must be type cstring[]")));
245
246 if (ARR_NDIM(arr) != 1)
247 ereport(ERROR,
248 (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
249 errmsg("typmod array must be one-dimensional")));
250
251 if (ARR_HASNULL(arr))
252 ereport(ERROR,
253 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
254 errmsg("typmod array must not contain nulls")));
255
256 deconstruct_array(arr,
257 CSTRINGOID, -2, false, 'c', /* hardwire cstring representation details */
258 &elem_values, NULL, &n);
259
260 /* Set the SRID to the default value first */
261 if (is_geography)
263 else
265
266 for (i = 0; i < n; i++)
267 {
268 if ( i == 0 ) /* TYPE */
269 {
270 char *s = DatumGetCString(elem_values[i]);
271 uint8_t type = 0;
272 int z = 0;
273 int m = 0;
274
275 if ( geometry_type_from_string(s, &type, &z, &m) == LW_FAILURE )
276 {
277 ereport(ERROR,
278 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
279 errmsg("Invalid geometry type modifier: %s", s)));
280 }
281 else
282 {
283 TYPMOD_SET_TYPE(typmod, type);
284 if ( z )
285 TYPMOD_SET_Z(typmod);
286 if ( m )
287 TYPMOD_SET_M(typmod);
288 }
289 }
290 if ( i == 1 ) /* SRID */
291 {
292 char *int_string = DatumGetCString(elem_values[i]);
293 char *endp;
294 long l;
295 int32_t srid;
296
297 errno = 0;
298 l = strtol(int_string, &endp, 10);
299
300 if (int_string == endp)
301 ereport(ERROR,
302 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
303 errmsg("invalid input syntax for type %s: \"%s\"",
304 "integer", int_string)));
305
306 if (errno == ERANGE || l < INT_MIN || l > INT_MAX)
307 ereport(ERROR,
308 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
309 errmsg("value \"%s\" is out of range for type %s", int_string,
310 "integer")));
311
312 if (*endp != '\0')
313 ereport(ERROR,
314 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
315 errmsg("invalid input syntax for type %s: \"%s\"",
316 "integer", int_string)));
317
318 srid = clamp_srid(l);
319 POSTGIS_DEBUGF(3, "srid: %d", srid);
320 if ( srid != SRID_UNKNOWN )
321 {
322 TYPMOD_SET_SRID(typmod, srid);
323 }
324 }
325 }
326
327 pfree(elem_values);
328
329 return typmod;
330}
char * s
Definition cu_in_wkt.c:23
#define TYPMOD_SET_SRID(typmod, srid)
Definition liblwgeom.h:193
#define LW_FAILURE
Definition liblwgeom.h:96
int geometry_type_from_string(const char *str, uint8_t *type, int *z, int *m)
Utility function to get type number from string.
Definition lwutil.c:495
#define TYPMOD_SET_TYPE(typmod, type)
Definition liblwgeom.h:195
#define SRID_DEFAULT
Definition liblwgeom.h:225
#define TYPMOD_SET_M(typmod)
Definition liblwgeom.h:199
#define SRID_UNKNOWN
Unknown SRID value.
Definition liblwgeom.h:215
#define TYPMOD_SET_Z(typmod)
Definition liblwgeom.h:197
int32_t clamp_srid(int32_t srid)
Return a valid SRID from an arbitrary integer Raises a notice if what comes out is different from wha...
Definition lwutil.c:339
unsigned int int32
Definition shpopen.c:54

References clamp_srid(), geometry_type_from_string(), LW_FAILURE, s, SRID_DEFAULT, SRID_UNKNOWN, TYPMOD_SET_M, TYPMOD_SET_SRID, TYPMOD_SET_TYPE, and TYPMOD_SET_Z.

Referenced by geography_typmod_in(), and geometry_typmod_in().

Here is the call graph for this function:
Here is the caller graph for this function: