Check the consistency of the metadata we want to enforce in the typmod: srid, type and dimensionality.
If things are inconsistent, shut down the query.
111{
120
121 POSTGIS_DEBUG(2, "Entered function");
122
123
124 if (typmod < 0) return gser;
125
126 POSTGIS_DEBUGF(3, "Got geom(type = %d, srid = %d, hasz = %d, hasm = %d)", geom_type, geom_srid, geom_z, geom_m);
127 POSTGIS_DEBUGF(3, "Got typmod(type = %d, srid = %d, hasz = %d, hasm = %d)", typmod_type, typmod_srid, typmod_z, typmod_m);
128
129
130
131
132
133
134
135
136
137
140 {
143 pfree(gser);
146 else
148 }
149
150
151 if ( typmod_srid > 0 && typmod_srid != geom_srid )
152 {
153 ereport(ERROR, (
154 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
155 errmsg("Geometry SRID (%d) does not match column SRID (%d)", geom_srid, typmod_srid) ));
156 }
157
158
159 if ( typmod_type > 0 &&
160
165
166 (typmod_type != geom_type)) )
167 {
168 ereport(ERROR, (
169 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
170 errmsg(
"Geometry type (%s) does not match column type (%s)",
lwtype_name(geom_type),
lwtype_name(typmod_type)) ));
171 }
172
173
174 if ( typmod_z && ! geom_z )
175 {
176 ereport(ERROR, (
177 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
178 errmsg("Column has Z dimension but geometry does not" )));
179 }
180
181
182 if ( geom_z && ! typmod_z )
183 {
184 ereport(ERROR, (
185 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
186 errmsg("Geometry has Z dimension but column does not" )));
187 }
188
189
190 if ( typmod_m && ! geom_m )
191 {
192 ereport(ERROR, (
193 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
194 errmsg("Column has M dimension but geometry does not" )));
195 }
196
197
198 if ( geom_m && ! typmod_m )
199 {
200 ereport(ERROR, (
201 errcode(ERRCODE_INVALID_PARAMETER_VALUE),
202 errmsg("Geometry has M dimension but column does not" )));
203 }
204
205 return gser;
206
207}
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
int gserialized_is_geodetic(const GSERIALIZED *g)
Check if a GSERIALIZED is a geography.
int gserialized_has_m(const GSERIALIZED *g)
Check if a GSERIALIZED has an M ordinate.
int gserialized_is_empty(const GSERIALIZED *g)
Check if a GSERIALIZED is empty without deserializing first.
int gserialized_has_z(const GSERIALIZED *g)
Check if a GSERIALIZED has a Z ordinate.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
const char * lwtype_name(uint8_t type)
Return the type name string associated with a type number (e.g.
#define TYPMOD_GET_SRID(typmod)
Macros for manipulating the 'typemod' int.
LWGEOM * lwpoint_as_lwgeom(const LWPOINT *obj)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
#define TYPMOD_GET_M(typmod)
LWPOINT * lwpoint_construct_empty(int32_t srid, char hasz, char hasm)
#define TYPMOD_GET_TYPE(typmod)
#define TYPMOD_GET_Z(typmod)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)