PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ gserialized_typmod_in()

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

Definition at line 217 of file gserialized_typmod.c.

218 {
219  int32 typmod = 0;
220  Datum *elem_values;
221  int n = 0;
222  int i = 0;
223 
224  if (ARR_ELEMTYPE(arr) != CSTRINGOID)
225  ereport(ERROR,
226  (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
227  errmsg("typmod array must be type cstring[]")));
228 
229  if (ARR_NDIM(arr) != 1)
230  ereport(ERROR,
231  (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
232  errmsg("typmod array must be one-dimensional")));
233 
234  if (ARR_HASNULL(arr))
235  ereport(ERROR,
236  (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
237  errmsg("typmod array must not contain nulls")));
238 
239  deconstruct_array(arr,
240  CSTRINGOID, -2, false, 'c', /* hardwire cstring representation details */
241  &elem_values, NULL, &n);
242 
243  /* Set the SRID to the default value first */
244  if (is_geography)
245  TYPMOD_SET_SRID(typmod, SRID_DEFAULT);
246  else
247  TYPMOD_SET_SRID(typmod, SRID_UNKNOWN);
248 
249  for (i = 0; i < n; i++)
250  {
251  if ( i == 0 ) /* TYPE */
252  {
253  char *s = DatumGetCString(elem_values[i]);
254  uint8_t type = 0;
255  int z = 0;
256  int m = 0;
257 
258  if ( geometry_type_from_string(s, &type, &z, &m) == LW_FAILURE )
259  {
260  ereport(ERROR,
261  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
262  errmsg("Invalid geometry type modifier: %s", s)));
263  }
264  else
265  {
266  TYPMOD_SET_TYPE(typmod, type);
267  if ( z )
268  TYPMOD_SET_Z(typmod);
269  if ( m )
270  TYPMOD_SET_M(typmod);
271  }
272  }
273  if ( i == 1 ) /* SRID */
274  {
275  char *int_string = DatumGetCString(elem_values[i]);
276  char *endp;
277  long l;
278  int32_t srid;
279 
280  errno = 0;
281  l = strtol(int_string, &endp, 10);
282 
283  if (int_string == endp)
284  ereport(ERROR,
285  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
286  errmsg("invalid input syntax for type %s: \"%s\"",
287  "integer", int_string)));
288 
289  if (errno == ERANGE || l < INT_MIN || l > INT_MAX)
290  ereport(ERROR,
291  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
292  errmsg("value \"%s\" is out of range for type %s", int_string,
293  "integer")));
294 
295  if (*endp != '\0')
296  ereport(ERROR,
297  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
298  errmsg("invalid input syntax for type %s: \"%s\"",
299  "integer", int_string)));
300 
301  srid = clamp_srid(l);
302  POSTGIS_DEBUGF(3, "srid: %d", srid);
303  if ( srid != SRID_UNKNOWN )
304  {
305  TYPMOD_SET_SRID(typmod, srid);
306  }
307  }
308  }
309 
310  pfree(elem_values);
311 
312  return typmod;
313 }
char * s
Definition: cu_in_wkt.c:23
#define TYPMOD_SET_SRID(typmod, srid)
Definition: liblwgeom.h:208
#define LW_FAILURE
Definition: liblwgeom.h:111
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:489
#define TYPMOD_SET_TYPE(typmod, type)
Definition: liblwgeom.h:210
#define SRID_DEFAULT
Definition: liblwgeom.h:240
#define TYPMOD_SET_M(typmod)
Definition: liblwgeom.h:214
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:230
#define TYPMOD_SET_Z(typmod)
Definition: liblwgeom.h:212
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:333
type
Definition: ovdump.py:42
unsigned int int32
Definition: shpopen.c:54

References clamp_srid(), geometry_type_from_string(), LW_FAILURE, s, SRID_DEFAULT, SRID_UNKNOWN, ovdump::type, 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: