Changeset 657 for trunk

Show
Ignore:
Timestamp:
02/22/08 20:25:52 (9 months ago)
Author:
tom
Message:

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.

Location:
trunk/plugins/input/postgis
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/plugins/input/postgis/postgisfs.cpp

    r650 r657  
    106106        { 
    107107           std::string name = rs_->getFieldName(pos); 
    108            const char* buf=rs_->getValue(pos); 
    109            int oid = rs_->getTypeOID(pos); 
     108 
     109           if (!rs_->isNull(pos)) 
     110           { 
     111              const char* buf=rs_->getValue(pos); 
     112              int oid = rs_->getTypeOID(pos); 
    110113            
    111            if (oid==23) //int4 
    112            { 
    113               int val = int4net(buf); 
    114               boost::put(*feature,name,val); 
    115            } 
    116            else if (oid==21) //int2 
    117            { 
    118               int val = int2net(buf); 
    119               boost::put(*feature,name,val); 
    120            } 
    121            else if (oid == 700) // float4 
    122            { 
    123               float val; 
    124               float4net(val,buf); 
    125               boost::put(*feature,name,val); 
    126            } 
    127            else if (oid == 701) // float8 
    128            { 
    129               double val; 
    130               float8net(val,buf); 
    131               boost::put(*feature,name,val); 
    132            } 
    133            else if (oid==25 || oid==1042 || oid==1043) // text or bpchar or varchar 
    134            { 
    135               //std::string str(buf); 
    136               //trim(str); 
    137               //std::wstring wstr = tr_->transcode(str); 
    138               UnicodeString ustr = tr_->transcode(buf); 
    139               boost::put(*feature,name,ustr); 
    140            } 
    141            else if (oid == 1700) // numeric 
    142            { 
    143               std::string str = numeric2string(buf); 
    144               try  
     114              if (oid==23) //int4 
    145115              { 
    146                  double val = boost::lexical_cast<double>(str); 
     116                 int val = int4net(buf); 
    147117                 boost::put(*feature,name,val); 
    148118              } 
    149               catch (boost::bad_lexical_cast & ex) 
     119              else if (oid==21) //int2 
    150120              { 
    151                  std::clog << ex.what() << "\n";  
     121                 int val = int2net(buf); 
     122                 boost::put(*feature,name,val); 
    152123              } 
    153            } 
    154            else  
    155            { 
     124              else if (oid == 700) // float4 
     125              { 
     126                 float val; 
     127                 float4net(val,buf); 
     128                 boost::put(*feature,name,val); 
     129              } 
     130              else if (oid == 701) // float8 
     131              { 
     132                 double val; 
     133                 float8net(val,buf); 
     134                 boost::put(*feature,name,val); 
     135              } 
     136              else if (oid==25 || oid==1042 || oid==1043) // text or bpchar or varchar 
     137              { 
     138                 //std::string str(buf); 
     139                 //trim(str); 
     140                 //std::wstring wstr = tr_->transcode(str); 
     141                 UnicodeString ustr = tr_->transcode(buf); 
     142                 boost::put(*feature,name,ustr); 
     143              } 
     144              else if (oid == 1700) // numeric 
     145              { 
     146                 std::string str = numeric2string(buf); 
     147                 try  
     148                 { 
     149                    double val = boost::lexical_cast<double>(str); 
     150                    boost::put(*feature,name,val); 
     151                 } 
     152                 catch (boost::bad_lexical_cast & ex) 
     153                 { 
     154                    std::clog << ex.what() << "\n";  
     155                 } 
     156              } 
     157              else  
     158              { 
    156159#ifdef MAPNIK_DEBUG 
    157               std::clog << "uknown OID = " << oid << " FIXME \n"; 
     160                 std::clog << "uknown OID = " << oid << " FIXME \n"; 
    158161#endif 
     162              } 
    159163           } 
    160164        } 
  • trunk/plugins/input/postgis/resultset.hpp

    r222 r657  
    122122        return 0; 
    123123    } 
     124 
     125    bool isNull(int index) const 
     126    { 
     127        return PQgetisnull(res_,pos_,index); 
     128    } 
    124129     
    125130    const char* getValue(int index) const