27 #include "../common/StringUtils.h" 
   28 #include "../common/Translator.h" 
   29 #include "../dataaccess/dataset/CheckConstraint.h" 
   30 #include "../dataaccess/dataset/DataSet.h" 
   31 #include "../dataaccess/dataset/ForeignKey.h" 
   32 #include "../dataaccess/dataset/Index.h" 
   33 #include "../dataaccess/dataset/ObjectIdSet.h" 
   34 #include "../dataaccess/dataset/PrimaryKey.h" 
   35 #include "../dataaccess/dataset/Sequence.h" 
   36 #include "../dataaccess/dataset/UniqueKey.h" 
   37 #include "../dataaccess/datasource/ScopedTransaction.h" 
   38 #include "../dataaccess/query/Select.h" 
   39 #include "../dataaccess/query/SQLDialect.h" 
   40 #include "../dataaccess/utils/Utils.h" 
   41 #include "../datatype/Array.h" 
   42 #include "../datatype/Enums.h" 
   43 #include "../datatype/Property.h" 
   44 #include "../datatype/SimpleData.h" 
   45 #include "../geometry/GeometryProperty.h" 
   46 #include "../geometry/Utils.h" 
   47 #include "../raster/Grid.h" 
   48 #include "../raster/BandProperty.h" 
   49 #include "../raster/RasterProperty.h" 
   50 #include "../geometry/Geometry.h" 
   67 #include <boost/format.hpp> 
   75     m_isInTransaction(false)
 
   81   m_ds->getConnPool()->release(m_conn);
 
   97   m_isInTransaction = 
true;
 
  102  m_isInTransaction = 
false;
 
  108   m_isInTransaction = 
false;
 
  114  return m_isInTransaction;
 
  122    std::auto_ptr<std::string> sql(
new std::string(
"SELECT * FROM "));
 
  125   PGresult* result = m_conn->query(*sql);
 
  127   std::vector<int> ptypes;
 
  128   Convert2TerraLib(result, m_ds->getGeomTypeId(), m_ds->getRasterTypeId(), ptypes);
 
  130   return std::auto_ptr<te::da::DataSet>(
new DataSet(result, ptypes, m_ds->isTimeAnInteger(), m_ds->getCharEncoding()));
 
  134                                                                 const std::string& propertyName,
 
  142     throw Exception(
TE_TR(
"The envelope is missing!"));
 
  144   std::auto_ptr<te::dt::Property> p = getProperty(name, propertyName);
 
  150   std::string sql(
"SELECT * FROM ");
 
  158   PGresult* result = m_conn->query(sql);
 
  160   std::vector<int> ptypes;
 
  161   Convert2TerraLib(result, m_ds->getGeomTypeId(), m_ds->getRasterTypeId(), ptypes);
 
  163   return std::auto_ptr<te::da::DataSet>(
new DataSet(result, ptypes, m_ds->isTimeAnInteger(), m_ds->getCharEncoding()));
 
  167                                                                 const std::string& propertyName,
 
  175     throw Exception(
TE_TR(
"The geometry is missing!"));
 
  179   std::string sql(
"SELECT * FROM ");
 
  191   PGresult* result = m_conn->query(sql);
 
  193   std::vector<int> ptypes;
 
  194   Convert2TerraLib(result, m_ds->getGeomTypeId(), m_ds->getRasterTypeId(), ptypes);
 
  196   return std::auto_ptr<te::da::DataSet>(
new DataSet(result, ptypes, m_ds->isTimeAnInteger(), m_ds->getCharEncoding()));
 
  206   SQLVisitor visitor(*(m_ds->getDialect()), sql, m_conn->getConn());
 
  209   return query(sql, travType, isConnected,accessPolicy);
 
  217   PGresult* result = m_conn->query(query);
 
  219   std::vector<int> ptypes;
 
  220   Convert2TerraLib(result, m_ds->getGeomTypeId(), m_ds->getRasterTypeId(), ptypes);
 
  222   return std::auto_ptr<te::da::DataSet>(
new DataSet(result, ptypes, m_ds->isTimeAnInteger(), m_ds->getCharEncoding()));
 
  229   SQLVisitor visitor(*(m_ds->getDialect()), sql, m_conn->getConn());
 
  237   m_conn->execute(command);
 
  242   return std::auto_ptr<te::da::PreparedQuery>(
new PreparedQuery(
this, qName));
 
  247   return std::auto_ptr<te::da::BatchExecutor>(0);
 
  256   throw Exception(
TE_TR(
"Not implemented yet!"));
 
  266   std::vector<std::string> datasetNames;
 
  268   std::string sql(
"SELECT pg_class.oid, pg_namespace.nspname, pg_class.relname, pg_class.relkind " 
  269                   "FROM pg_class, pg_namespace " 
  270                   "WHERE pg_class.relname !~ '^pg_' " 
  271                   "AND pg_class.relname NOT IN ('spatial_ref_sys', 'geometry_columns', 'geography_columns', 'raster_columns', 'raster_overviews') " 
  272                   "AND pg_class.relkind in ('r','v') " 
  273                   "AND pg_class.relnamespace = pg_namespace.oid " 
  274                   "AND pg_namespace.nspname NOT IN ('information_schema', 'pg_toast', 'pg_temp_1', 'pg_catalog', 'topology')");
 
  276   std::auto_ptr<te::da::DataSet> datasetInfo = query(sql);
 
  278   while(datasetInfo->moveNext())
 
  280     std::string datasetName = std::string(datasetInfo->getString(1) + 
"." + datasetInfo->getString(2));
 
  281     datasetNames.push_back(datasetName);
 
  289   return getDataSetNames().size();
 
  294   std::string datasetName = getFullName(name);
 
  297   unsigned int dtid = getDataSetId(datasetName);
 
  304   boost::ptr_vector<te::dt::Property> properties = getProperties(datasetName);
 
  305   for(std::size_t i = 0; i < properties.size(); ++i)
 
  317   return std::auto_ptr<te::da::DataSetType>(dt);
 
  322   std::string fullDatasetName = getFullName(datasetName);
 
  324   boost::ptr_vector<te::dt::Property> properties;
 
  326   std::auto_ptr<te::da::DataSet> pInfo = getPropertiesInfo(fullDatasetName);
 
  328   while(pInfo->moveNext())
 
  330     unsigned int attNum = pInfo->getInt16(0);
 
  331     std::string attName = pInfo->getString(1);
 
  332     unsigned int attType = pInfo->getInt32(2);
 
  333     bool attNotNull = pInfo->getBool(3);
 
  334     std::string fmt = pInfo->getString(4);
 
  335     bool attHasDefault = pInfo->getBool(5);
 
  336     std::string attDefValue = pInfo->getString(6);
 
  337     int ndims = pInfo->getInt32(7);
 
  340                                             fmt.c_str(), attHasDefault, attDefValue.c_str(),
 
  341                                             ndims, m_ds->getGeomTypeId(), m_ds->getRasterTypeId());
 
  343     properties.push_back(p);
 
  347       getGeometryInfo(datasetName, static_cast<te::gm::GeometryProperty*>(p));
 
  351       getRasterInfo(datasetName, static_cast<te::rst::RasterProperty*>(p));
 
  360   std::string fullDatasetName = getFullName(datasetName);
 
  364   std::string pName = name;
 
  367   std::size_t pos = pName.find_last_of(
".");
 
  368   if(pos != std::string::npos)
 
  369     pName = pName.substr(++pos);
 
  371   std::auto_ptr<te::da::DataSet> pInfo = getPropertiesInfo(fullDatasetName);
 
  372   while(pInfo->moveNext())
 
  374     std::string attName = pInfo->getString(1);
 
  378     unsigned int attNum = pInfo->getInt16(0);
 
  379     unsigned int attType = pInfo->getInt32(2);
 
  380     bool attNotNull = pInfo->getBool(3);
 
  381     std::string fmt = pInfo->getString(4);
 
  382     bool attHasDefault = pInfo->getBool(5);
 
  383     std::string attDefValue = pInfo->getString(6);
 
  384     int ndims = pInfo->getInt32(7);
 
  387                           fmt.c_str(), attHasDefault, attDefValue.c_str(),
 
  388                           ndims, m_ds->getGeomTypeId(), m_ds->getRasterTypeId());
 
  392       getGeometryInfo(datasetName, static_cast<te::gm::GeometryProperty*>(p));
 
  396       getRasterInfo(datasetName, static_cast<te::rst::RasterProperty*>(p));
 
  400   return std::auto_ptr<te::dt::Property>(p);
 
  405   std::string fullDatasetName = getFullName(datasetName);
 
  407   boost::ptr_vector<te::dt::Property> properties = getProperties(fullDatasetName);
 
  409   assert(propertyPos < properties.size());
 
  411   return std::auto_ptr<te::dt::Property>(properties[propertyPos].clone());
 
  416   std::string fullDatasetName = getFullName(datasetName);
 
  418   boost::ptr_vector<te::dt::Property> properties = getProperties(fullDatasetName);
 
  420   std::size_t numProperties = properties.size();
 
  422   std::vector<std::string> pNames(numProperties);
 
  424   for(std::size_t i = 0; i < numProperties; ++i)
 
  425     pNames[i] = properties[i].getName();
 
  432   std::string fullDatasetName = getFullName(datasetName);
 
  433   return getProperties(fullDatasetName).size();
 
  438   std::string fullDatasetName = getFullName(datasetName);
 
  440   std::vector<std::string> pNames = getPropertyNames(fullDatasetName);
 
  442   if(std::find(pNames.begin(), pNames.end(), name) != pNames.end())
 
  450   std::string fullDatasetName = getFullName(datasetName);
 
  452   std::string pName = p->
getName();
 
  461     sql  = 
"SELECT AddGeometryColumn('";
 
  464     std::size_t pos = fullDatasetName.find(
".");
 
  466     if(pos == std::string::npos)
 
  490     sql = 
"ALTER TABLE ";
 
  491     sql += fullDatasetName;
 
  492     sql += 
" ADD COLUMN ";
 
  504   std::string fullDatasetName = getFullName(datasetName);
 
  506   std::auto_ptr<te::dt::Property> p = getProperty(fullDatasetName, name);
 
  512     sql  =  
"SELECT DropGeometryColumn('";
 
  515     std::size_t pos = fullDatasetName.find(
".");
 
  517     if(pos == std::string::npos)
 
  519       sql += m_ds->getCurrentSchema();
 
  536     sql  = 
" ALTER TABLE ";
 
  537     sql += fullDatasetName;
 
  538     sql += 
" DROP COLUMN ";
 
  546                                           const std::string& name,
 
  547                                           const std::string& newName)
 
  549   std::string fullDatasetName = getFullName(datasetName);
 
  551   std::auto_ptr<te::dt::Property> p = getProperty(fullDatasetName, name);
 
  553   std::string sql(
"ALTER TABLE ");
 
  554   sql += fullDatasetName;
 
  555   sql += 
" RENAME COLUMN ";
 
  556   sql += name + 
" TO ";
 
  563     sql = 
"UPDATE geometry_columns SET f_geometry_column = '" + newName + 
"'";
 
  564     sql += 
" WHERE f_table_name = '" ;
 
  567     std::size_t pos = fullDatasetName.find(
".");
 
  569     if(pos == std::string::npos)
 
  571       sql += fullDatasetName;
 
  572       sql += 
"' AND f_table_schema ='";
 
  573       sql += m_ds->getCurrentSchema();
 
  578       sql += fullDatasetName.substr(pos + 1);
 
  579       sql += 
"' AND f_table_schema ='";
 
  580       sql += fullDatasetName.substr(0, pos);
 
  584     sql += 
" AND f_geometry_column = '" + name + 
"'";
 
  592   std::auto_ptr<te::dt::Property> prp(newProp);
 
  596     type = 
"NUMERIC USING " + propName+ 
"::numeric";
 
  601   std::string sql(
"ALTER TABLE ");
 
  602   sql += datasetName + 
" ALTER COLUMN " + propName + 
" TYPE " + type; 
 
  609   std::string fullDatasetName = getFullName(datasetName);
 
  613   std::auto_ptr<te::da::DataSet> pkInfo = getConstraints(fullDatasetName, 
'p');
 
  615   while(pkInfo->moveNext())
 
  617     unsigned int pkId = pkInfo->getInt32(0);
 
  618     std::string pkName  = pkInfo->getString(2);
 
  622     std::auto_ptr<te::dt::Array> pkCols(pkInfo->getArray(8));
 
  623     std::size_t size = pkCols->getDimensionSize(0);
 
  625     std::vector<std::size_t> pos;
 
  627     for(std::size_t i = 0; i < size; ++i)
 
  633       std::auto_ptr<te::dt::Property> p = getProperty(static_cast<te::dt::Int16*>(pkCol)->getValue(), fullDatasetName);
 
  634       pk->
add(p.release());
 
  639   std::vector<std::string> idxNames = getIndexNames(fullDatasetName);
 
  641   for(std::size_t i = 0; i < idxNames.size(); ++i)
 
  643     if(pk->
getName() == idxNames[i])
 
  650   return std::auto_ptr<te::da::PrimaryKey>(pk);
 
  655   std::string fullDatasetName = getFullName(datasetName);
 
  657   std::auto_ptr<te::da::PrimaryKey> pk = getPrimaryKey(fullDatasetName);
 
  659   if(pk->getName() == name)
 
  667   std::string fullDatasetName = getFullName(datasetName);
 
  671   if(getPrimaryKey(fullDatasetName).
get() != 0)
 
  672     dropPrimaryKey(fullDatasetName);
 
  678     pkName = fullDatasetName + 
"_pk";
 
  680     boost::replace_all(pkName, 
".", 
"_");
 
  687   std::string sql(
"ALTER TABLE ");
 
  688   sql += fullDatasetName;
 
  689   sql += 
" ADD CONSTRAINT ";
 
  691   sql += 
" PRIMARY KEY (";
 
  693   const std::vector<te::dt::Property*>& properties = pk->
getProperties();
 
  695   std::size_t size = properties.size();
 
  697   for(std::size_t i = 0; i < size; ++i)
 
  702     sql += properties[i]->getName();
 
  712   std::string fullDatasetName = getFullName(datasetName);
 
  714   std::auto_ptr<te::da::PrimaryKey> pk = getPrimaryKey(fullDatasetName);
 
  716   std::string pkName = pk->getName();
 
  718   std::string sql(
"ALTER TABLE ");
 
  719   sql += fullDatasetName;
 
  720   sql += 
" DROP CONSTRAINT " + pkName;
 
  727   std::string fullDatasetName = getFullName(datasetName);
 
  731   std::auto_ptr<te::da::DataSet> fkInfo = getConstraints(fullDatasetName, 
'f');
 
  733   while(fkInfo->moveNext())
 
  735     std::string fkName  = fkInfo->getString(2);
 
  740     unsigned int fkId = fkInfo->getInt32(0);
 
  741     unsigned int refDatasetId = fkInfo->getInt32(4);
 
  742     char onUpdate = fkInfo->getChar(5);
 
  743     char onDeletion = fkInfo->getChar(6);
 
  745     std::auto_ptr<te::dt::Array> fkCols(fkInfo->getArray(8));
 
  746     std::auto_ptr<te::dt::Array> fkRefCols(fkInfo->getArray(9));
 
  748     assert(fkCols->getDimension() == 1);
 
  749     assert(fkCols->getDimension() == fkRefCols->getDimension());
 
  750     assert(fkCols->getDimensionSize(0) == fkRefCols->getDimensionSize(0));
 
  752     std::string refName = getDataSetName(refDatasetId);
 
  753     std::auto_ptr<te::da::DataSetType> refdt = getDataSetType(refName);
 
  760     std::size_t size = fkCols->getDimensionSize(0);
 
  762     std::vector<std::size_t> pos;
 
  765     for(std::size_t i = 0; i < size; ++i)
 
  770       fk->
addRefProperty(refdt->getPropertyById(static_cast<te::dt::Int16*>(fkRefCol)->getValue()));
 
  773       fk->
add(getProperty(static_cast<te::dt::Int16*>(fkCol)->getValue(), datasetName).release());
 
  777   return std::auto_ptr<te::da::ForeignKey>(fk);
 
  782   std::string fullDatasetName = getFullName(datasetName);
 
  784   std::vector<std::string> fkNames;
 
  786   std::auto_ptr<te::da::DataSet> fkInfo = getConstraints(fullDatasetName, 
'f');
 
  788   while(fkInfo->moveNext())
 
  790     std::string fkName  = fkInfo->getString(2);
 
  791     fkNames.push_back(fkName);
 
  799   std::string fullDatasetName = getFullName(datasetName);
 
  801   std::vector<std::string> fkNames = getForeignKeyNames(fullDatasetName);
 
  802   if(std::find(fkNames.begin(), fkNames.end(), name) != fkNames.end())
 
  810   std::string fullDatasetName = getFullName(datasetName);
 
  812   std::string fkName = fk->
getName();
 
  814   std::string sql(
"ALTER TABLE ");
 
  815   sql += fullDatasetName;
 
  816   sql += 
" ADD CONSTRAINT ";
 
  818   sql += 
" FOREIGN KEY (";
 
  822   for(std::size_t i = 0; i < size; ++i)
 
  834   for(
size_t i = 0; i < size; ++i)
 
  842   sql += 
") ON DELETE ";
 
  847       sql += 
" NO ACTION ";
 
  864       sql += 
"SET DEFAULT ";
 
  868   sql += 
" ON UPDATE ";
 
  873       sql += 
" NO ACTION ";
 
  890       sql += 
"SET DEFAULT ";
 
  899   std::string fullDatasetName = getFullName(datasetName);
 
  901   std::string sql(
"ALTER TABLE ");
 
  902   sql += fullDatasetName;
 
  903   sql += 
" DROP CONSTRAINT ";
 
  911   std::string fullDatasetName = getFullName(datasetName);
 
  915   std::auto_ptr<te::da::DataSet> ukInfo = getConstraints(fullDatasetName, 
'u');
 
  917   while(ukInfo->moveNext())
 
  919     std::string ukName  = ukInfo->getString(2);
 
  924     unsigned int ukId = ukInfo->getInt32(0);
 
  926     std::auto_ptr<te::dt::Array> ukCols(ukInfo->getArray(8));
 
  930     std::size_t size = ukCols->getDimensionSize(0);
 
  932     std::vector<std::size_t> pos;
 
  935     for(std::size_t i = 0; i < size; ++i)
 
  941       std::auto_ptr<te::dt::Property> p = getProperty(static_cast<te::dt::Int16*>(ukCol)->getValue(), fullDatasetName);
 
  943       uk->add(p.release());
 
  948   std::vector<std::string> idxNames = getIndexNames(fullDatasetName);
 
  950   for(std::size_t i = 0; i < idxNames.size(); ++i)
 
  952     if(uk->
getName() == idxNames[i])
 
  959   return std::auto_ptr<te::da::UniqueKey>(uk);
 
  964   std::string fullDatasetName = getFullName(datasetName);
 
  966   std::vector<std::string> ukNames;
 
  968   std::auto_ptr<te::da::DataSet> ukInfo = getConstraints(fullDatasetName, 
'u');
 
  970   while(ukInfo->moveNext())
 
  972     std::string ukName  = ukInfo->getString(2);
 
  973     ukNames.push_back(ukName);
 
  981   std::string fullDatasetName = getFullName(datasetName);
 
  983   std::vector<std::string> ukNames = getUniqueKeyNames(fullDatasetName);
 
  985   if(std::find(ukNames.begin(), ukNames.end(), name) != ukNames.end())
 
  993   std::string fullDatasetName = getFullName(datasetName);
 
  995   std::string ukName = uk->
getName();
 
  997   std::string sql(
"ALTER TABLE ");
 
  998   sql += fullDatasetName;
 
  999   sql += 
" ADD CONSTRAINT ";
 
 1003   const std::vector<te::dt::Property*>& properties = uk->
getProperties();
 
 1005   std::size_t size = properties.size();
 
 1007   for(std::size_t i = 0; i < size; ++i)
 
 1012     sql += properties[i]->getName();
 
 1022   std::string fullDatasetName = getFullName(datasetName);
 
 1024   std::string sql(
"ALTER TABLE ");
 
 1025   sql += fullDatasetName;
 
 1026   sql += 
" DROP CONSTRAINT ";
 
 1032   if(indexExists(fullDatasetName, name))
 
 1033     dropIndex(fullDatasetName, name);
 
 1038   std::string fullDatasetName = getFullName(datasetName);
 
 1042   std::auto_ptr<te::da::DataSet> ccInfo = getConstraints(datasetName, 
'c');
 
 1044   while(ccInfo->moveNext())
 
 1046     std::string ccName  = ccInfo->getString(2);
 
 1051     unsigned int ccId = ccInfo->getInt32(0);
 
 1058   return std::auto_ptr<te::da::CheckConstraint>(cc);
 
 1063   std::string fullDatasetName = getFullName(datasetName);
 
 1065   std::vector<std::string> ccNames;
 
 1067   std::auto_ptr<te::da::DataSet> ccInfo = getConstraints(fullDatasetName, 
'c');
 
 1069   while(ccInfo->moveNext())
 
 1071     std::string ccName = ccInfo->getString(2);
 
 1073     ccNames.push_back(ccName);
 
 1081   std::string fullDatasetName = getFullName(datasetName);
 
 1083   std::vector<std::string> ccNames = getCheckConstraintNames(fullDatasetName);
 
 1085   if(std::find(ccNames.begin(), ccNames.end(), name) != ccNames.end())
 
 1093   std::string fullDatasetName = getFullName(datasetName);
 
 1095   std::string ccName = cc->
getName();
 
 1097   std::string sql(
"ALTER TABLE ");
 
 1098   sql += fullDatasetName;
 
 1099   sql += 
" ADD CONSTRAINT ";
 
 1110   std::string fullDatasetName = getFullName(datasetName);
 
 1112   std::string sql(
"ALTER TABLE ");
 
 1113   sql += fullDatasetName;
 
 1114   sql += 
" DROP CONSTRAINT ";
 
 1122   std::string fullDatasetName = getFullName(datasetName);
 
 1126   unsigned int dtid = getDataSetId(fullDatasetName);
 
 1128   std::string sql(
"SELECT idx_table.oid, s.nspname, idx_table.relname, pg_index.indkey, pg_am.amname, pg_index.indisunique, pg_index.indisprimary "  
 1129                   "FROM pg_index, pg_class idx_table, pg_am, pg_namespace s " 
 1130                   "WHERE s.oid = idx_table.relnamespace " 
 1131                   "AND pg_index.indexrelid = idx_table.oid " 
 1132                   "AND idx_table.relam = pg_am.oid " 
 1133                   "AND pg_index.indrelid = ");
 
 1136   std::auto_ptr<te::da::DataSet> idxInfo = query(sql);
 
 1138   while(idxInfo->moveNext())
 
 1140     std::string idxName = idxInfo->getString(2);
 
 1145     unsigned int idxId = idxInfo->getInt32(0);
 
 1147     std::auto_ptr<te::dt::Array> idxCols(idxInfo->getArray(3));
 
 1149     std::string idxType = idxInfo->getString(4);
 
 1153     std::size_t size = idxCols->getDimensionSize(0);
 
 1155     std::vector<std::size_t> pos;
 
 1158     for(std::size_t i = 0; i < size; ++i)
 
 1163       std::auto_ptr<te::dt::Property> p = getProperty(static_cast<te::dt::Int16*>(idxCol)->getValue(), fullDatasetName);
 
 1165       idx->
add(p.release());
 
 1169   return std::auto_ptr<te::da::Index>(idx);
 
 1174   std::string fullDatasetName = getFullName(datasetName);
 
 1176   std::vector<std::string> idxNames;
 
 1178   unsigned int dtid = getDataSetId(fullDatasetName);
 
 1180   std::string sql(
"SELECT idx_table.oid, s.nspname, idx_table.relname, pg_index.indkey, pg_am.amname, pg_index.indisunique, pg_index.indisprimary "  
 1181                   "FROM pg_index, pg_class idx_table, pg_am, pg_namespace s " 
 1182                   "WHERE s.oid = idx_table.relnamespace " 
 1183                   "AND pg_index.indexrelid = idx_table.oid " 
 1184                   "AND idx_table.relam = pg_am.oid " 
 1185                   "AND pg_index.indrelid = ");
 
 1188   std::auto_ptr<te::da::DataSet> idxInfo = query(sql);
 
 1190   while(idxInfo->moveNext())
 
 1192     std::string idxName = idxInfo->getString(2);
 
 1194     idxNames.push_back(idxName);
 
 1202   std::string fullDatasetName = getFullName(datasetName);
 
 1204   std::vector<std::string> idxNames = getIndexNames(fullDatasetName);
 
 1206   if(std::find(idxNames.begin(), idxNames.end(), name) != idxNames.end())
 
 1213                                     const std::map<std::string, std::string>& options) 
 
 1215   std::string fullDatasetName = getFullName(datasetName);
 
 1217   std::string idxName = idx->
getName();
 
 1220   std::auto_ptr<te::da::PrimaryKey> pk = getPrimaryKey(fullDatasetName);
 
 1222   if(pk.get() && (pk->getAssociatedIndex() == idx))
 
 1225   std::vector<std::string> ukNames = getUniqueKeyNames(datasetName);
 
 1227   for(std::size_t i = 0; i < ukNames.size(); ++i)
 
 1228     if(getUniqueKey(datasetName, ukNames[i])->getAssociatedIndex() == idx)
 
 1232   std::string sql(
"CREATE INDEX ");
 
 1235   sql += fullDatasetName;
 
 1238     sql += 
" USING HASH (";
 
 1240     sql += 
" USING GIST (";
 
 1242     sql += 
" USING BTREE (";
 
 1244     throw Exception(
TE_TR(
"The index type is not supported!"));
 
 1248   for(
size_t i = 0; i < numProperties; ++i)
 
 1263   std::string fullDatasetName = getFullName(datasetName);
 
 1265   std::string sql(
"DROP INDEX ");
 
 1276   std::vector<std::string> seqNames;
 
 1278   std::string sql(
"SELECT c.oid, n.nspname, c.relname, c.relkind " 
 1279                   "FROM pg_class c, pg_namespace n " 
 1280                   "WHERE c.relname !~ '^pg_' " 
 1281                   "AND c.relkind = 'S' " 
 1282                   "AND c.relnamespace = n.oid " 
 1283                   "AND n.nspname NOT IN ('information_schema', 'pg_toast', 'pg_temp_1', 'pg_catalog')");
 
 1285   std::auto_ptr<te::da::DataSet> seqNamesInfo = query(sql);
 
 1287   while(seqNamesInfo->moveNext())
 
 1289     std::string seqName(seqNamesInfo->getString(2));
 
 1294     std::string sql(
"SELECT * FROM ");
 
 1297     std::auto_ptr<te::da::DataSet> result(query(sql));
 
 1299     if(result->moveNext())
 
 1301       unsigned int seqId = getDataSetId(seqName);
 
 1306       if(result->getBool(8))
 
 1318   return std::auto_ptr<te::da::Sequence>(seq);
 
 1323   std::vector<std::string> seqNames;
 
 1325   std::string sql(
"SELECT c.oid, n.nspname, c.relname, c.relkind " 
 1326                   "FROM pg_class c, pg_namespace n " 
 1327                   "WHERE c.relname !~ '^pg_' " 
 1328                   "AND c.relkind = 'S' " 
 1329                   "AND c.relnamespace = n.oid " 
 1330                   "AND n.nspname NOT IN ('information_schema', 'pg_toast', 'pg_temp_1', 'pg_catalog')");
 
 1332   std::auto_ptr<te::da::DataSet> seqNamesInfo = query(sql);
 
 1334   while(seqNamesInfo->moveNext())
 
 1336     std::string seqName(seqNamesInfo->getString(2));
 
 1337     seqNames.push_back(seqName);
 
 1345   std::vector<std::string> seqNames = getSequenceNames();
 
 1347   if(std::find(seqNames.begin(), seqNames.end(), name) != seqNames.end())
 
 1355   std::string seqName = sequence->
getName();
 
 1357   std::string sql(
"CREATE SEQUENCE ");
 
 1359   sql += 
" INCREMENT BY ";
 
 1361   sql += 
" MINVALUE ";
 
 1363   sql += 
" MAXVALUE ";
 
 1365   sql += 
" START WITH ";
 
 1377     sql += 
" OWNED BY ";
 
 1385   unsigned int seqId = getDataSetId(seqName);
 
 1387   sequence->
setId(seqId);
 
 1392   std::auto_ptr<te::da::Sequence> seq = getSequence(name);
 
 1394   std::string sql(
"DROP SEQUENCE ");
 
 1402   std::string sql(
"SELECT ST_Extent(");
 
 1403   sql += propertyName;
 
 1407   PGresult* result = PQexec(m_conn->getConn(), sql.c_str());
 
 1409   if(PQresultStatus(result) != PGRES_TUPLES_OK)
 
 1411     std::string errmsg(
TE_TR(
"Could not find the envelope for the given geometry property due to the following error: "));
 
 1412     errmsg += PQerrorMessage(m_conn->getConn());
 
 1416     throw Exception(errmsg);
 
 1419   const char* boxStr = PQgetvalue(result, 0, 0);
 
 1427   return std::auto_ptr<te::gm::Envelope>(mbr);
 
 1432   std::auto_ptr<te::dt::Property> p = getProperty(datasetName, propertyPos);
 
 1434   std::string sql(
"SELECT ST_Extent(");
 
 1435   sql += p->getName();
 
 1439   PGresult* result = PQexec(m_conn->getConn(), sql.c_str());
 
 1441   if(PQresultStatus(result) != PGRES_TUPLES_OK)
 
 1443     std::string errmsg(
TE_TR(
"Could not find the envelope for the given geometry property due to the following error: "));
 
 1444     errmsg += PQerrorMessage(m_conn->getConn());
 
 1448     throw Exception(errmsg);
 
 1451   const char* boxStr = PQgetvalue(result, 0, 0);
 
 1459   return std::auto_ptr<te::gm::Envelope>(mbr);
 
 1464   std::auto_ptr<te::da::DataSet> result = getDataSet(datasetName);
 
 1465   return result->size();
 
 1470   std::vector<std::string> datasetNames = getDataSetNames();
 
 1472   if(datasetNames.empty())
 
 1480   std::string datasetName = getFullName(name);
 
 1482   std::vector<std::string> datasetNames = getDataSetNames();
 
 1484   if(std::find(datasetNames.begin(), datasetNames.end(), datasetName) != datasetNames.end())
 
 1492   std::string datasetName = dt->
getName();
 
 1493   datasetName = getFullName(datasetName);
 
 1495   std::string sql  = 
"CREATE TABLE ";
 
 1502   unsigned int dtid = getDataSetId(datasetName);
 
 1507   std::size_t nCols = dt->
size();
 
 1508   for(std::size_t i = 0; i < nCols; ++i)
 
 1517   for(std::size_t i = 0; i < nUKs; ++i)
 
 1522   for(std::size_t i = 0; i < nIdxs; ++i)
 
 1523       addIndex(datasetName, dt->
getIndex(i), options);
 
 1527   for(std::size_t i = 0; i < nFKs; ++i)
 
 1533   for(std::size_t i = 0; i < nCCs; ++i)
 
 1537   std::vector<std::string> indexNames = getIndexNames(datasetName);
 
 1542     for(std::size_t i = 0; i < indexNames.size(); ++i)
 
 1544       if(pk->
getName() == indexNames[i])
 
 1555   for(std::size_t i = 0; i < numUKs; ++i)
 
 1559     for(std::size_t j = 0; j < indexNames.size(); ++j)
 
 1561       if(uk->
getName() == indexNames[j])
 
 1571                                                   const std::string& ,
 
 1572                                                   const std::map<std::string, std::string>& )
 
 1574   throw Exception(
TE_TR(
"Not implemented yet!"));
 
 1579   std::auto_ptr<te::da::DataSetType> dt = getDataSetType(name);
 
 1585     std::string tSchema, tName;
 
 1586     SplitTableName(dt->getName(), &(m_ds->getCurrentSchema()), tSchema, tName);
 
 1588     sql = 
"SELECT DropGeometryTable('";
 
 1596     sql += 
"DROP TABLE ";
 
 1597     sql += dt->getName();
 
 1605   std::string newTableName, newTableSchema, oldTableName, oldTableSchema;
 
 1607   std::string sql(
"ALTER TABLE ");
 
 1609   sql += 
" RENAME TO ";
 
 1611   SplitTableName(newName, &(m_ds->getCurrentSchema()), newTableSchema, newTableName);
 
 1613   sql += newTableName;
 
 1618   std::auto_ptr<te::da::DataSetType> dt = getDataSetType(name);
 
 1622     SplitTableName(name, &(m_ds->getCurrentSchema()), oldTableSchema, oldTableName);
 
 1624     sql  = 
"UPDATE geometry_columns SET f_table_name = '";
 
 1625     sql += newTableName;
 
 1626     sql += 
"' WHERE f_table_name = '";
 
 1627     sql += oldTableName;
 
 1628     sql += 
"' AND f_table_schema ='";
 
 1629     sql += oldTableSchema;
 
 1638                                const std::map<std::string, std::string>& options,
 
 1642     limit = std::string::npos;
 
 1645   std::string sql  = 
"INSERT INTO ";
 
 1651   std::auto_ptr<PreparedQuery> pq(
new PreparedQuery(
this, 
"a" + boost::lexical_cast<std::string>((intptr_t)(
this))));
 
 1657   std::size_t nProcessedRows = 0;
 
 1659   pq->prepare(sql, paramTypes);
 
 1661   while(d->
moveNext() && (nProcessedRows != limit))
 
 1675   throw Exception(
TE_TR(
"Not implemented yet!"));
 
 1755                                             const std::vector<std::size_t>& ,
 
 1757                                             const std::map<std::string, std::string>& ,
 
 1760   throw Exception(
TE_TR(
"Not implemented yet!"));
 
 1813                                   const std::vector< std::set<int> >& properties,
 
 1814                                   const std::vector<size_t>& ids)
 
 1820   std::set<int>::iterator it;
 
 1828       std::string sql = 
"UPDATE " + datasetName + 
" SET "; 
 
 1829       plst = properties[i];
 
 1835       for(it = plst.begin(); it != plst.end(); ++it)
 
 1853       for(
size_t j=0; j<ids.size(); ++j)
 
 1866       sql += 
"(" + pName + 
")=(" + value + 
") WHERE " + id;
 
 1875   catch(te::pgis::Exception& e)
 
 1885   throw Exception(
TE_TR(
"Not implemented yet!"));
 
 1890   std::string sql(
"SELECT oid FROM pg_type WHERE typname = 'geometry'");
 
 1892   std::auto_ptr<te::da::DataSet> result(query(sql));
 
 1894   unsigned int id = 0;
 
 1896   if(result->moveNext())
 
 1897     id = result->getInt32(0);
 
 1904   std::string sql(
"SELECT oid FROM pg_type WHERE typname = 'raster'");
 
 1906   std::auto_ptr<te::da::DataSet> result(query(sql));
 
 1908   unsigned int id = 0;
 
 1910   if(result->moveNext())
 
 1911     id = result->getInt32(0);
 
 1918   std::string sql(
"SELECT current_schema()");
 
 1920   std::auto_ptr<te::da::DataSet> result(query(sql));
 
 1922   if(!result->moveNext())
 
 1923     Exception(
TE_TR(
"Could not get information about PostgreSQL database backend!"));
 
 1925   currentSchema = result->getString(0);
 
 1930   std::string sql = 
"SELECT g.coord_dimension, g.srid, g.type " 
 1931                     "FROM geometry_columns g " 
 1932                     "WHERE g.f_table_name = '";
 
 1934   std::string tname, sname;
 
 1936   SplitTableName(datasetName, &(m_ds->getCurrentSchema()), sname, tname);
 
 1939   sql += 
"' AND g.f_table_schema = '";
 
 1941   sql += 
"' AND f_geometry_column = '";
 
 1945   std::auto_ptr<te::da::DataSet> result(query(sql));
 
 1947   if(result->moveNext())
 
 1950     int srid = result->getInt32(1);
 
 1966   std::string sql = 
"SELECT * FROM raster_columns as r WHERE r.r_table_name = '";
 
 1968   std::string tname, sname;
 
 1970   SplitTableName(datasetName, &(m_ds->getCurrentSchema()), sname, tname);
 
 1973   sql += 
"' AND r.r_table_schema = '";
 
 1975   sql += 
"' AND r_raster_column = '";
 
 1979   std::auto_ptr<te::da::DataSet> result(query(sql));
 
 1981   if(result->moveNext())
 
 1983     int srid = result->getInt32(
"srid");
 
 1985     double scale_x = result->getDouble(
"scale_x");
 
 1987     double scale_y = result->getDouble(
"scale_y");
 
 1989     int blocksize_x = result->getInt32(
"blocksize_x");
 
 1991     int blocksize_y = result->getInt32(
"blocksize_y");
 
 1995     int nbands = result->getInt32(
"num_bands");
 
 1997     std::auto_ptr<te::dt::Array> pixel_types(result->getArray(
"pixel_types"));
 
 1999     std::auto_ptr<te::dt::Array> nodata_values(result->getArray(
"nodata_values"));
 
 2001     std::auto_ptr<te::gm::Geometry> g(result->getGeometry(
"extent"));
 
 2007     rp->
set(grid.release());
 
 2009     for(
int i = 0; i != nbands; ++i)
 
 2011       std::vector<std::size_t> pos(1, i);
 
 2013       std::string st = pixel_types->getData(pos)->toString();
 
 2019       else if(st == 
"8BUI")
 
 2021       else if(st == 
"16BI")
 
 2023       else if(st == 
"16BUI")
 
 2025       else if(st == 
"32BI")
 
 2027       else if(st == 
"32BUI")
 
 2029       else if(st == 
"32BF")
 
 2031       else if(st == 
"64BF")
 
 2034         throw Exception(
TE_TR(
"Band data type not supported by PostGIS driver!"));
 
 2038       bp->
m_blkh = blocksize_y;
 
 2040       bp->
m_blkw = blocksize_x;
 
 2058   std::string fullName = name;
 
 2060   if(fullName.find(
".") == std::string::npos)
 
 2061     fullName = m_ds->getCurrentSchema() + 
"." + name;
 
 2070  std::string tname, sname;
 
 2072   SplitTableName(tableName, &(m_ds->getCurrentSchema()), sname, tname);
 
 2074   std::string sql(
"SELECT pg_class.oid " 
 2075                   "FROM pg_class, pg_namespace " 
 2076                   "WHERE pg_class.relnamespace = pg_namespace.oid "  
 2077                   "AND lower(pg_class.relname) = '");
 
 2080   sql += 
"' AND lower(pg_namespace.nspname) = '";
 
 2084   std::auto_ptr<te::da::DataSet> result(query(sql));
 
 2086   if(result->moveNext() == 
false)
 
 2087     throw Exception(
TE_TR(
"Could not find the table oid!"));
 
 2089   unsigned int tableid = result->getInt32(0);
 
 2096   std::string sql(
"SELECT pg_namespace.nspname, pg_class.relname " 
 2097                   "FROM pg_class, pg_namespace " 
 2098                   "WHERE pg_class.relnamespace = pg_namespace.oid "  
 2099                   "AND pg_class.oid = ");
 
 2103   std::auto_ptr<te::da::DataSet> result(query(sql));
 
 2105   if(result->moveNext() == 
false)
 
 2106     throw Exception(
TE_TR(
"Could not find the dataset name!"));
 
 2108   std::string tname  = result->getString(0);
 
 2110               tname += result->getString(1);
 
 2117   std::string fullDatasetName = getFullName(datasetName);
 
 2119   unsigned int dtid = getDataSetId(fullDatasetName);
 
 2121   std::string sql(
"SELECT a.attnum, a.attname, t.oid, a.attnotnull, format_type(a.atttypid, a.atttypmod), a.atthasdef, pg_get_expr(d.adbin, d.adrelid), a.attndims " 
 2122                   "FROM pg_attribute AS a INNER JOIN pg_type AS t ON (a.atttypid = t.oid) LEFT JOIN pg_attrdef AS d ON (a.attrelid = d.adrelid AND a.attnum = d.adnum) " 
 2123                   "WHERE a.attrelid = ");
 
 2125   sql += 
" AND a.attisdropped = false" 
 2127          " ORDER BY a.attnum";
 
 2135     throw Exception(
TE_TR(
"The informed property is not valid!"));
 
 2137   std::string sql(
"SELECT attnum " 
 2138                   "FROM pg_attribute WHERE attrelid = ");
 
 2140   sql += 
" AND attisdropped = false " 
 2145   std::auto_ptr<te::da::DataSet> result(query(sql));
 
 2147   if(result->moveNext() == 
false)
 
 2148     throw Exception(
TE_TR(
"Could not find the property ID!"));
 
 2150   unsigned int id = result->getInt32(0);
 
 2156   unsigned int dtid = getDataSetId(datasetName);
 
 2158   std::string sql(
"SELECT a.attnum, a.attname, t.oid, a.attnotnull, format_type(a.atttypid, a.atttypmod), a.atthasdef, pg_get_expr(d.adbin, d.adrelid), a.attndims " 
 2159                   "FROM pg_attribute AS a INNER JOIN pg_type AS t ON (a.atttypid = t.oid) LEFT JOIN pg_attrdef AS d ON (a.attrelid = d.adrelid AND a.attnum = d.adnum) " 
 2160                   "WHERE a.attrelid = ");
 
 2162               sql += 
" AND a.attnum = ";
 
 2164               sql += 
" AND a.attisdropped = false" 
 2165                      " AND a.attnum > 0";
 
 2167   std::auto_ptr<te::da::DataSet> result(query(sql));
 
 2169   std::auto_ptr<te::dt::Property> p(0);
 
 2171   if(result->moveNext())
 
 2173     unsigned int attNum = result->getInt16(0);
 
 2174     std::string attName = result->getString(1);
 
 2175     unsigned int attType = result->getInt32(2);
 
 2176     bool attNotNull = result->getBool(3);
 
 2177     std::string fmt = result->getString(4);
 
 2178     bool attHasDefault = result->getBool(5);
 
 2179     std::string attDefValue = result->getString(6);
 
 2180     int ndims = result->getInt32(7);
 
 2182     p.reset(
Convert2TerraLib(attNum, attName.c_str(), attType, attNotNull, fmt.c_str(), attHasDefault,
 
 2183                              attDefValue.c_str(),ndims, m_ds->getGeomTypeId(), m_ds->getRasterTypeId()));
 
 2186       getGeometryInfo(datasetName, static_cast<te::gm::GeometryProperty*>(p.get()));
 
 2194   unsigned int dtid = getDataSetId(datasetName);
 
 2196   std::string sql(
"SELECT c.oid, n.nspname, c.conname, c.contype, c.confrelid, c.confupdtype, c.confdeltype, c.confmatchtype, c.conkey, c.confkey, pg_get_constraintdef(c.oid) " 
 2197                   "FROM pg_constraint c, pg_namespace n " 
 2198                   "WHERE c.connamespace = n.oid " 
 2199                   "AND c.conrelid = ");
 
 2204     sql += 
" AND c.contype = '";
 
 2214   std::string datasetName = dt->
getName();
 
 2215   unsigned int dtid = dt->
getId();
 
 2217   std::string sql(
"SELECT c.oid, n.nspname, c.conname, c.contype, c.confrelid, c.confupdtype, c.confdeltype, c.confmatchtype, c.conkey, c.confkey, pg_get_constraintdef(c.oid) " 
 2218                   "FROM pg_constraint c, pg_namespace n " 
 2219                   "WHERE c.connamespace = n.oid " 
 2220                   "AND c.conrelid = ");
 
 2223   std::auto_ptr<te::da::DataSet> cInfo = query(sql);
 
 2225   while(cInfo->moveNext())
 
 2227     char cType = cInfo->getChar(3);
 
 2231       unsigned int pkId = cInfo->getInt32(0);
 
 2232       std::string pkName  = cInfo->getString(2);
 
 2236       std::auto_ptr<te::dt::Array> pkCols(cInfo->getArray(8));
 
 2237       std::size_t size = pkCols->getDimensionSize(0);
 
 2239       std::vector<std::size_t> pos;
 
 2241       for(std::size_t i = 0; i < size; ++i)
 
 2252       std::vector<std::string> idxNames = getIndexNames(datasetName);
 
 2254       for(std::size_t i = 0; i < idxNames.size(); ++i)
 
 2256         if(pk->
getName() == idxNames[i])
 
 2267     else if (cType == 
'f')
 
 2270       unsigned int fkId = cInfo->getInt32(0);
 
 2271       unsigned int refDatasetId = cInfo->getInt32(4);
 
 2272       char onUpdate = cInfo->getChar(5);
 
 2273       char onDeletion = cInfo->getChar(6);
 
 2275       std::auto_ptr<te::dt::Array> fkCols(cInfo->getArray(8));
 
 2276       std::auto_ptr<te::dt::Array> fkRefCols(cInfo->getArray(9));
 
 2278       assert(fkCols->getDimension() == 1);
 
 2279       assert(fkCols->getDimension() == fkRefCols->getDimension());
 
 2280       assert(fkCols->getDimensionSize(0) == fkRefCols->getDimensionSize(0));
 
 2282       std::string refName = getDataSetName(refDatasetId);
 
 2284       std::auto_ptr<te::da::DataSetType> refDatasetType = getDataSetType(refName);
 
 2286       std::string fkName  = cInfo->getString(2);
 
 2293       std::size_t size = fkCols->getDimensionSize(0);
 
 2295       std::vector<std::size_t> pos;
 
 2298       for(std::size_t i = 0; i < size; ++i)
 
 2303         fk->
addRefProperty(refDatasetType->getPropertyById(static_cast<te::dt::Int16*>(fkRefCol)->getValue()));
 
 2306         fk->
add(getProperty(static_cast<te::dt::Int16*>(fkCol)->getValue(), datasetName).release());
 
 2313     else if(cType == 
'u')
 
 2316       unsigned int ukId = cInfo->getInt32(0);
 
 2317       std::string ukName  = cInfo->getString(2);
 
 2319       std::auto_ptr<te::dt::Array> ukCols(cInfo->getArray(8));
 
 2323       std::size_t size = ukCols->getDimensionSize(0);
 
 2325       std::vector<std::size_t> pos;
 
 2328       for(std::size_t i = 0; i < size; ++i)
 
 2334         std::auto_ptr<te::dt::Property> p = getProperty(static_cast<te::dt::Int16*>(ukCol)->getValue(), datasetName);
 
 2335         uk->add(p.release());
 
 2339       std::vector<std::string> idxNames = getIndexNames(datasetName);
 
 2341       for(std::size_t i = 0; i < idxNames.size(); ++i)
 
 2343         if(uk->getName() == idxNames[i])
 
 2345           uk->setAssociatedIndex(getIndex(datasetName, idxNames[i]).
get());
 
 2354     else if(cType == 
'c')
 
 2357       std::string ccName = cInfo->getString(2);
 
 2359       unsigned int ccId = cInfo->getInt32(0);
 
 2374   std::string datasetName = dt->
getName();
 
 2375   unsigned int dtid = dt->
getId();
 
 2377   std::string sql(
"SELECT idx_table.oid, s.nspname, idx_table.relname, pg_index.indkey, pg_am.amname, pg_index.indisunique, pg_index.indisprimary "  
 2378                   "FROM pg_index, pg_class idx_table, pg_am, pg_namespace s " 
 2379                   "WHERE s.oid = idx_table.relnamespace " 
 2380                   "AND pg_index.indexrelid = idx_table.oid " 
 2381                   "AND idx_table.relam = pg_am.oid " 
 2382                   "AND pg_index.indrelid = ");
 
 2385   std::auto_ptr<te::da::DataSet> idxInfo = query(sql);
 
 2387   while(idxInfo->moveNext())
 
 2389     unsigned int idxId = idxInfo->getInt32(0);
 
 2390     std::string idxName = idxInfo->getString(2);
 
 2392     std::auto_ptr<te::dt::Array> idxCols(idxInfo->getArray(3));
 
 2394     std::string idxType = idxInfo->getString(4);
 
 2395     bool isUK = idxInfo->getBool(5);
 
 2396     bool isPK = idxInfo->getBool(6);
 
 2400     std::size_t size = idxCols->getDimensionSize(0);
 
 2402     std::vector<std::size_t> pos;
 
 2405     for(std::size_t i = 0; i < size; ++i)
 
 2414     idxName = idxInfo->getString(2);
 
 2431   std::vector<te::da::Sequence*> seqs;
 
 2434   std::vector<std::string> seqNames;
 
 2436   std::string sql(
"SELECT c.oid, n.nspname, c.relname, c.relkind " 
 2437                   "FROM pg_class c, pg_namespace n " 
 2438                   "WHERE c.relname !~ '^pg_' " 
 2439                   "AND c.relkind = 'S' " 
 2440                   "AND c.relnamespace = n.oid " 
 2441                   "AND n.nspname NOT IN ('information_schema', 'pg_toast', 'pg_temp_1', 'pg_catalog')");
 
 2443   std::auto_ptr<te::da::DataSet> seqNamesInfo = query(sql);
 
 2445   while(seqNamesInfo->moveNext())
 
 2447     std::string seqName(seqNamesInfo->getString(2));
 
 2448     seqNames.push_back(seqName);
 
 2451   for(std::size_t i = 0; i < seqNames.size(); ++i)
 
 2453     std::string seqName = seqNames[i];
 
 2455     std::string sql(
"SELECT * FROM ");
 
 2458     std::auto_ptr<te::da::DataSet> result(query(sql));
 
 2460     if(result->moveNext() == 
false)
 
 2461       throw Exception((boost::format(
TE_TR(
"There is no information about the sequence \"%1%\"!")) % seqName).str());
 
 2463     unsigned int seqId = getDataSetId(seqName);
 
 2468     if(result->getBool(8))
 
 2478     seqs.push_back(seq);
 
 2486   int encodingId = PQclientEncoding(m_conn->getConn());
 
 2487   std::string encodingStr = pg_encoding_to_char(encodingId);
 
virtual void setName(const std::string &name)
It sets the constraint name. 
 
void setTitle(const std::string &title)
It sets a human descriptive title for the DataSetType. 
 
Property * getProperty(std::size_t i) const 
It returns the i-th property. 
 
void getDatabaseInfo(std::string ¤tSchema)
It retrieves some information about the database such as the default schema used when no one is provi...
 
boost::int64_t getMinValue() const 
It returns the minimum value that the sequence can generate. 
 
void getIndexes(te::da::DataSetType *dt)
It gets all the indexes of the given dataset and adds them to the dummy schema. 
 
std::auto_ptr< te::da::DataSet > getPropertiesInfo(const std::string &datasetName)
It gets the information about the given dataset. 
 
std::auto_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName)
It retrieves the primary key of the dataset. 
 
void set(te::rst::Grid *grid)
Sets the definition of the raster grid support. 
 
bool isInTransaction() const 
It returns true if a transaction is in progress, otherwise, it returns false. 
 
void update(const std::string &datasetName, te::da::DataSet *dataset, const std::vector< std::size_t > &properties, const te::da::ObjectIdSet *oids, const std::map< std::string, std::string > &options, std::size_t limit=0)
It updates the contents of a dataset for the set of data items. 
 
std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset. 
 
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key. 
 
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code. 
 
Utility functions for the data access module. 
 
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset. 
 
void SplitTableName(const std::string &fullName, const std::string *defaultSchema, std::string &schemaName, std::string &tableName)
 
void setMaxValue(boost::int64_t value)
It sets the maximum value that the sequence can generate. 
 
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property. 
 
void setGeometryType(GeomType t)
It sets the geometry subtype. 
 
std::auto_ptr< te::da::DataSet > getConstraints(const std::string &datasetName, char conType= '\0')
It gets the dataset containing information about one of the constraints(primary, foreign or unique ke...
 
CharEncoding
Supported charsets (character encoding). 
 
void getRasterInfo(const std::string &datasetName, te::rst::RasterProperty *rp)
It loads information about a given raster column. 
 
te::dt::Property * getOwner() const 
It returns the property type associated to the sequence. 
 
std::auto_ptr< te::da::ForeignKey > getForeignKey(const std::string &datasetName, const std::string &name)
It retrieves the foreign key from the given dataset. 
 
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source. 
 
std::auto_ptr< te::da::CheckConstraint > getCheckConstraint(const std::string &datasetName, const std::string &name)
It gets the check constraint of the dataset with the given name. 
 
bool uniqueKeyExists(const std::string &datasetName, const std::string &name)
It checks if a unique key with the given name exists in the dataset. 
 
std::string Convert2LCase(const std::string &value)
It converts a string to lower case. 
 
void setAsNoCycle()
It sets the sequence as not cycled (it can't wrap). 
 
boost::int64_t getMaxValue() const 
It returns the maximum value that the sequence can generate. 
 
void addForeignKey(const std::string &datasetName, te::da::ForeignKey *fk)
It adds a foreign key constraint to a dataset. 
 
A raster band description. 
 
Connection * getConnection() const 
It returns the underlying connection. 
 
std::auto_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor. 
 
A class that models the description of a dataset. 
 
std::vector< std::string > getUniqueKeyNames(const std::string &datasetName)
It gets the unique key names of the given dataset. 
 
void addPrimaryKey(const std::string &datasetName, te::da::PrimaryKey *pk)
It adds a primary key constraint to the dataset schema. 
 
std::size_t getNumberOfUniqueKeys() const 
It returns the number of unique keys defined for the dataset type. 
 
const std::string & GetGeometryName(te::gm::GeomType t)
It returns the geometry names as usual for PostGIS. 
 
CheckConstraint * getCheckConstraint(std::size_t i) const 
It returns the i-th check-constraint associated to the dataset type. 
 
struct pg_result PGresult
 
void addUniqueKey(const std::string &datasetName, te::da::UniqueKey *uk)
It adds a unique key constraint to the dataset. 
 
virtual Property * clone() const =0
It returns a clone of the object. 
 
An static class with global definitions. 
 
std::string getDataSetName(unsigned int id)
It looks for a dataset name with the given id in the PostgreSQL. 
 
A visitor for building an SQL statement using PostGIS dialect. 
 
bool checkConstraintExists(const std::string &datasetName, const std::string &name)
It checks if a check-constraint with the given name exists in the data source. 
 
PrimaryKey * getPrimaryKey() const 
It returns the primary key associated to the dataset type. 
 
virtual void setId(unsigned int id)
It sets the constraint identifier. 
 
An utility class to coordinate transactions. 
 
boost::int64_t getCachedValues() const 
It returns how many sequence numbers are preallocated. 
 
SpatialRelation
Spatial relations between geometric objects. 
 
void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema. 
 
It describes a sequence (a number generator). 
 
void add(te::dt::Property *p)
It adds the property to the list of properties of the index. 
 
te::gm::Envelope * GetEnvelope(const char *str)
It converts the pgType to a valid TerraLib data type. 
 
A class that implements a connection to a PostgreSQL database. 
 
TEDATAACCESSEXPORT std::string GetSQLValueNames(const DataSetType *dt)
 
A class that describes a check constraint. 
 
void commit()
It commits the transaction. 
 
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
 
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits::max(). 
 
#define TE_TR(message)
It marks a string in order to get translated. 
 
std::auto_ptr< te::da::PreparedQuery > getPrepared(const std::string &qName=std::string(""))
It creates a prepared query object that may be used for query commands (select, insert, update and delete) that are used repeatedly. 
 
int GetCoordDimension(GeomType t)
It returns the number of measurements or axes needed to describe a position in a coordinate system...
 
std::auto_ptr< te::da::DataSet > query(const te::da::Select &q, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It executes a query that may return some data using a generic query. A dataset can be connected or di...
 
It models a property definition. 
 
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids=0)
It removes all the informed items from the dataset. 
 
std::vector< te::da::Sequence * > getSequences()
It gets information about all the sequences in the datasource. 
 
const std::vector< te::dt::Property * > & getProperties() const 
It returns the properties that take part of the primary key. 
 
void dropCheckConstraint(const std::string &datasetName, const std::string &name)
It removes the check constraint from the dataset. 
 
void commit()
It commits the transaction. 
 
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset. 
 
Index * getIndex(std::size_t i) const 
It returns the i-th index associated to the dataset type. 
 
void setId(unsigned int id)
It sets the property identifier. 
 
void changePropertyDefinition(const std::string &datasetName, const std::string &propName, te::dt::Property *newProp)
 
void optimize(const std::map< std::string, std::string > &opInfo)
For some data access drivers, this method will perform some operations to optimize the data storage...
 
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source. 
 
void setIncrement(boost::int64_t n)
It sets the increment value. 
 
te::da::DataSource * getDataSource() const 
It returns the parent data source of the transactor. 
 
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection. 
 
AccessPolicy
Supported data access policies (can be used as bitfield). 
 
TraverseType
A dataset can be traversed in two ways: 
 
std::auto_ptr< te::da::DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name. A dataset can be connected or disconnected. A connected dataset, after its creation through the data source transactor, continues to depend on the connection given by its associated data source. Differently, a disconnected dataset, after its creation, no more depends of the connection given by the data source, and it continues to live after the connection has been released to the data source. 
 
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source. 
 
~Transactor()
The destructor will automatically release the connection to the pool. 
 
std::size_t getNumberOfForeignKeys() const 
It returns the number of foreign keys defined for the dataset type. 
 
void getGeometryInfo(const std::string &datasetName, te::gm::GeometryProperty *gp)
It loads information about a given geometry column. 
 
void add(te::rst::BandProperty *b)
It adds a new band information to the property. 
 
std::auto_ptr< te::dt::Property > getProperty(const std::string &datasetName, const std::string &name)
It retrieves the property with the given name from the dataset. 
 
std::auto_ptr< te::gm::Envelope > getExtent(const std::string &datasetName, const std::string &propertyName)
It retrieves the bounding rectangle of the spatial property for the given dataset. 
 
const std::string & getExpression() const 
It returns the check constraint expression. 
 
void setOnDeleteAction(FKActionType a)
It sets the action to be performed when a referenced element value in the referenced DataSetType is b...
 
void setCachedValues(boost::int64_t value)
It sets how many sequence numbers are to be preallocated. 
 
int getSRID() const 
It returns the spatial reference system identifier associated to this property. 
 
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset. 
 
An Envelope defines a 2D rectangular region. 
 
Implementation of a dataset for the PostGIS driver. 
 
void add(te::dt::Property *p)
It adds a property to the foreign key constraint. 
 
This class represents a set of unique ids created in the same context. i.e. from the same data set...
 
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos. 
 
void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema. 
 
void Convert2PostGIS(const te::gm::Envelope *e, int srid, std::string &output)
It converts the envelope into a PostGIS BOX3D. 
 
std::string escape(const std::string &value)
It escapes a string for using in commands and queries. 
 
Property * getPropertyById(unsigned int id) const 
It searches for a property with the given ID. 
 
int m_blkw
Block width (pixels). 
 
GeomType getGeometryType() const 
It returns the geometry subtype allowed for the property. 
 
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset. 
 
void createDataSet(te::da::DataSetType *dt, const std::map< std::string, std::string > &options)
It creates the dataset schema definition in the target data source. 
 
std::size_t getNumberOfIndexes() const 
It returns the number of indexes defined for the dataset type. 
 
DataSetType * getReferencedDataSetType() const 
It returns the referenced DataSetType of this foreign key constraint. 
 
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source. 
 
It models a foreign key constraint for a DataSetType. 
 
virtual std::string getAsString(std::size_t i, int precision=0) const 
Method for retrieving a data value as a string plain representation. 
 
A base class for values that can be retrieved from the data access module. 
 
void addRefProperty(te::dt::Property *p)
It adds a reference property (on the referenced DataSetType) of this foreign key constraint. 
 
It describes a unique key (uk) constraint. 
 
void setAssociatedIndex(Index *idx)
It sets the associated index. 
 
void add(const std::string &datasetName, te::da::DataSet *d, const std::map< std::string, std::string > &options, std::size_t limit=0)
It adds data items to the dataset in the data source. 
 
Property * getParent() const 
It returns the parent of this property, or NULL, if it doesn't have one. 
 
std::size_t size() const 
It returns the number of properties of the CompositeProperty. 
 
GeomType getGeomTypeId() const 
It returns the geometry subclass type identifier. 
 
TEDATAACCESSEXPORT std::vector< int > GetPropertyDataTypes(const te::da::DataSet *dataset)
 
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset. 
 
void addIndex(const std::string &datasetName, te::da::Index *idx, const std::map< std::string, std::string > &options)
It adds an index to the dataset. 
 
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards. 
 
A class that implements a connection to a PostgreSQL database. 
 
void getPropertyId(te::dt::Property *p)
It sets the property id from the PostgreSQL system. 
 
A Select models a query to be used when retrieving data from a DataSource. 
 
std::auto_ptr< te::da::UniqueKey > getUniqueKey(const std::string &datasetName, const std::string &name)
It gets the unique key in the dataset with the given name. 
 
bool isCycled() const 
It returns true if the sequence can wrap, otherwise it returns false. 
 
Implementation of the data source for the PostGIS driver. 
 
int getType() const 
It returns the property data type. 
 
void add(Constraint *c)
It adds a new constraint. 
 
A Transactor can be viewed as a connection to the data source for reading/writing things into it...
 
void rollBack()
It aborts the transaction. Any changes will be rolled-back. 
 
A dataset is the unit of information manipulated by the data access module of TerraLib. 
 
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema. 
 
const std::vector< te::dt::Property * > & getProperties() const 
It returns the properties that form the unique key. 
 
bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source. 
 
void cloneDataSet(const std::string &name, const std::string &cloneName, const std::map< std::string, std::string > &options)
It clones the dataset in the data source. 
 
te::common::CharEncoding getEncoding()
It return the DataSource current encoding. 
 
te::common::CharEncoding GetTeEncoding(const char *const encoding)
 
void setAssociatedIndex(Index *idx)
It sets the associated index. 
 
ForeignKey * getForeignKey(std::size_t i) const 
It returns the i-th foreign key associated to the dataset type. 
 
void setOnUpdateAction(FKActionType a)
It sets the action to be performed when a referenced element value in the referenced DataSetType is b...
 
An exception class for the PostGIS driver. 
 
A visitor for building an SQL statement using PostGIS dialect. 
 
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object. 
 
std::string GetSpatialRelation(te::gm::SpatialRelation rel)
It converts the spatial relationship to PostGIS dialect. 
 
const std::vector< te::dt::Property * > & getProperties() const 
It returns the properties that take part of the index. 
 
std::size_t getNumberOfCheckConstraints() const 
It returns the number of check-constraints defined over the dataset type. 
 
std::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset. 
 
bool indexExists(const std::string &datasetName, const std::string &name)
It checks if an index with the given name exists in the dataset. 
 
It describes a primary key (pk) constraint. 
 
Transactor(DataSource *ds, Connection *conn)
Constructor. 
 
void renameProperty(const std::string &datasetName, const std::string &propertyName, const std::string &newPropertyName)
It renames a property of the given dataset. 
 
void setExpression(const std::string &e)
It sets the check constraint expression. 
 
std::string getFullName(const std::string &name)
It gets the full name of the given name including the schema name. 
 
te::dt::Property * Convert2TerraLib(unsigned int attNum, const char *attName, unsigned int attType, bool attNotNull, const char *fmt, bool attHasDefault, const char *attDefValue, unsigned int pgisGeomTypeOid, unsigned int pgisRasterTypeOid)
It creates a PropertyType from a PostgreSQL attribute description. 
 
void execute(const te::da::Query &command)
It executes the specified command using a generic query representation. 
 
unsigned int getGeomTypeId()
It will check in the database catalog the number that identifies the PostGIS Geometry type...
 
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source. 
 
boost::int64_t getIncrement() const 
It returns the increment value. 
 
void dropSequence(const std::string &name)
It removes the sequence from the data source. 
 
boost::int64_t getStartValue() const 
It returns the initial value of the sequence. 
 
bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset. 
 
FKActionType getOnUpdateAction() const 
It returns the action performed when a referenced element value in the referenced DataSetType is bein...
 
void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset. 
 
unsigned int getRasterTypeId()
It will check in the database catalog the number that identifies the PostGIS Raster type...
 
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset. 
 
void addCheckConstraint(const std::string &datasetName, te::da::CheckConstraint *cc)
It adds a check constraint to the dataset. 
 
void setAsCycle()
It sets the sequence as cycled (it can wrap). 
 
te::da::IndexType GetIndexType(const char *t)
It converts the PostgreSQL index string to a TerraLib index type. 
 
std::string GetBoxSpatialRelation(te::gm::SpatialRelation rel)
It converts the spatial relationship to PostGIS dialect. 
 
void setReferencedDataSetType(DataSetType *refDt)
It sets the referenced DataSetType of this foreign key constraint. 
 
std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset. 
 
te::da::FKActionType GetAction(char a)
It converts the PostgreSQL foreign key modifier to a TerraLib data type. 
 
void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the dataset schema. 
 
A template for atomic data types (integers, floats, strings and others). 
 
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string. 
 
int m_blkh
Block height (pixels). 
 
A dataset is the unit of information manipulated by the data access module of TerraLib. 
 
virtual const std::string & getName() const 
It returns the constraint name. 
 
A class that implements a connection pool for PostGIS. 
 
const std::string & getName() const 
It returns the sequence name. 
 
std::vector< std::string > getCheckConstraintNames(const std::string &datasetName)
It gets the check constraint names of the given dataset. 
 
A rectified grid is the spatial support for raster data. 
 
IndexType getIndexType() const 
It gets the index type. 
 
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos. 
 
bool foreignKeyExists(const std::string &datasetName, const std::string &name)
It checks if a foreign key with the given name exists in the data source. 
 
const std::vector< te::dt::Property * > & getProperties() const 
It returns the properties that take part of the foreign key constraint. 
 
void addSequence(te::da::Sequence *sequence)
It creates a new sequence in the data source. 
 
void begin()
It starts a new transaction. 
 
virtual bool moveFirst()=0
It moves the internal pointer to the first item in the collection. 
 
const std::vector< te::dt::Property * > & getReferencedProperties() const 
It returns the referenced properties (on the referenced DataSetType) of this foreign key constraint...
 
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command. 
 
A class that implements a prepared query for PostgreSQL data access driver. 
 
void cancel()
It requests that the data source stop the processing of the current command. 
 
void setId(unsigned int id)
It sets the sequence identifier. 
 
A Query is independent from the data source language/dialect. 
 
It describes an index associated to a DataSetType. 
 
bool hasDataSets()
It checks if the data source has any dataset. 
 
bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset. 
 
unsigned int getId() const 
It returns the property identifier. 
 
std::string GetSQLBindValues(std::size_t nproperties)
 
UniqueKey * getUniqueKey(std::size_t i) const 
It returns the i-th unique key. 
 
void setMinValue(boost::int64_t value)
It sets the minimum value that the sequence can generate. 
 
bool SetColumnDef(std::string &s, const std::string &tname, const te::dt::SimpleProperty *p, bool justDataType=false)
 
unsigned int getDataSetId(const std::string &datasetName)
It looks for the dataset id in the PostgreSQL system. 
 
std::auto_ptr< te::da::Index > getIndex(const std::string &datasetName, const std::string &name)
It gets the index with the given name from the dataset. 
 
void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset. 
 
A class that implements a prepared query for PostgreSQL data access driver. 
 
std::auto_ptr< te::da::Sequence > getSequence(const std::string &name)
It gets the sequence with the given name in the data source. 
 
FKActionType getOnDeleteAction() const 
It returns the action performed when a referenced element value in the referenced DataSetType is bein...
 
const std::string & getName() const 
It returns the property name. 
 
const std::string & getName() const 
It returns the index name.