Check for null values in the PostGIS results and don't add attributes

with null values to the feature rather than adding a value based on
decoding a buffer full of undefined data.
This commit is contained in:
Tom Hughes 2008-02-23 01:25:52 +00:00
parent 02962156c5
commit 13d32335e0
2 changed files with 52 additions and 43 deletions

View file

@ -105,57 +105,61 @@ feature_ptr postgis_featureset::next()
for (unsigned pos=1;pos<num_attrs_+1;++pos)
{
std::string name = rs_->getFieldName(pos);
const char* buf=rs_->getValue(pos);
int oid = rs_->getTypeOID(pos);
if (!rs_->isNull(pos))
{
const char* buf=rs_->getValue(pos);
int oid = rs_->getTypeOID(pos);
if (oid==23) //int4
{
int val = int4net(buf);
boost::put(*feature,name,val);
}
else if (oid==21) //int2
{
int val = int2net(buf);
boost::put(*feature,name,val);
}
else if (oid == 700) // float4
{
float val;
float4net(val,buf);
boost::put(*feature,name,val);
}
else if (oid == 701) // float8
{
double val;
float8net(val,buf);
boost::put(*feature,name,val);
}
else if (oid==25 || oid==1042 || oid==1043) // text or bpchar or varchar
{
//std::string str(buf);
//trim(str);
//std::wstring wstr = tr_->transcode(str);
UnicodeString ustr = tr_->transcode(buf);
boost::put(*feature,name,ustr);
}
else if (oid == 1700) // numeric
{
std::string str = numeric2string(buf);
try
if (oid==23) //int4
{
double val = boost::lexical_cast<double>(str);
int val = int4net(buf);
boost::put(*feature,name,val);
}
catch (boost::bad_lexical_cast & ex)
else if (oid==21) //int2
{
std::clog << ex.what() << "\n";
int val = int2net(buf);
boost::put(*feature,name,val);
}
}
else
{
else if (oid == 700) // float4
{
float val;
float4net(val,buf);
boost::put(*feature,name,val);
}
else if (oid == 701) // float8
{
double val;
float8net(val,buf);
boost::put(*feature,name,val);
}
else if (oid==25 || oid==1042 || oid==1043) // text or bpchar or varchar
{
//std::string str(buf);
//trim(str);
//std::wstring wstr = tr_->transcode(str);
UnicodeString ustr = tr_->transcode(buf);
boost::put(*feature,name,ustr);
}
else if (oid == 1700) // numeric
{
std::string str = numeric2string(buf);
try
{
double val = boost::lexical_cast<double>(str);
boost::put(*feature,name,val);
}
catch (boost::bad_lexical_cast & ex)
{
std::clog << ex.what() << "\n";
}
}
else
{
#ifdef MAPNIK_DEBUG
std::clog << "uknown OID = " << oid << " FIXME \n";
std::clog << "uknown OID = " << oid << " FIXME \n";
#endif
}
}
}
++count_;

View file

@ -121,6 +121,11 @@ public:
return PQftype(res_,col);
return 0;
}
bool isNull(int index) const
{
return PQgetisnull(res_,pos_,index);
}
const char* getValue(int index) const
{