use 'limit 0' when gathering metadata, also we don't need getFieldSize at all

This commit is contained in:
Artem Pavlenko 2007-09-07 15:50:40 +00:00
parent ef6f1060d3
commit 92b22558fd

View file

@ -99,38 +99,33 @@ postgis_datasource::postgis_datasource(parameters const& params)
// collect attribute desc // collect attribute desc
s.str(""); s.str("");
s << "select * from " << table_ << " limit 1"; s << "select * from " << table_ << " limit 0";
rs=conn->executeQuery(s.str()); rs=conn->executeQuery(s.str());
if (rs->next()) int count = rs->getNumFields();
for (int i=0;i<count;++i)
{ {
int count = rs->getNumFields(); std::string fld_name=rs->getFieldName(i);
for (int i=0;i<count;++i) int type_oid = rs->getTypeOID(i);
switch (type_oid)
{ {
std::string fld_name=rs->getFieldName(i); case 21: // int2
int length = rs->getFieldLength(i); case 23: // int4
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer));
int type_oid = rs->getTypeOID(i); break;
switch (type_oid) case 700: // float4
{ case 701: // float8
case 21: // int2 desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double));
case 23: // int4 case 1042: // bpchar
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Integer,false,length)); case 1043: // varchar
break; case 25: // text
case 700: // float4 desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String));
case 701: // float8 break;
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::Double,false,length)); default: // shouldn't get here
case 1042: // bpchar
case 1043: // varchar
case 25: // text
desc_.add_descriptor(attribute_descriptor(fld_name,mapnik::String));
break;
default: // shouldn't get here
#ifdef MAPNIK_DEBUG #ifdef MAPNIK_DEBUG
clog << "unknown type_oid="<<type_oid<<endl; clog << "unknown type_oid="<<type_oid<<endl;
#endif #endif
break; break;
} }
}
} }
} }
} }