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') "
275 "ORDER BY pg_class.relname"
278 std::auto_ptr<te::da::DataSet> datasetInfo = query(sql);
280 while(datasetInfo->moveNext())
282 std::string datasetName = std::string(datasetInfo->getString(1) +
"." + datasetInfo->getString(2));
283 datasetNames.push_back(datasetName);
291 return getDataSetNames().size();
296 std::string datasetName = getFullName(name);
299 unsigned int dtid = getDataSetId(datasetName);
306 boost::ptr_vector<te::dt::Property> properties = getProperties(datasetName);
307 for(std::size_t i = 0; i < properties.size(); ++i)
319 return std::auto_ptr<te::da::DataSetType>(dt);
324 std::string fullDatasetName = getFullName(datasetName);
326 boost::ptr_vector<te::dt::Property> properties;
328 std::auto_ptr<te::da::DataSet> pInfo = getPropertiesInfo(fullDatasetName);
330 while(pInfo->moveNext())
332 unsigned int attNum = pInfo->getInt16(0);
333 std::string attName = pInfo->getString(1);
334 unsigned int attType = pInfo->getInt32(2);
335 bool attNotNull = pInfo->getBool(3);
336 std::string fmt = pInfo->getString(4);
337 bool attHasDefault = pInfo->getBool(5);
338 std::string attDefValue = pInfo->getString(6);
339 int ndims = pInfo->getInt32(7);
342 fmt.c_str(), attHasDefault, attDefValue.c_str(),
343 ndims, m_ds->getGeomTypeId(), m_ds->getRasterTypeId());
345 properties.push_back(p);
349 getGeometryInfo(datasetName, static_cast<te::gm::GeometryProperty*>(p));
353 getRasterInfo(datasetName, static_cast<te::rst::RasterProperty*>(p));
362 std::string fullDatasetName = getFullName(datasetName);
366 std::string pName = name;
369 std::size_t pos = pName.find_last_of(
".");
370 if(pos != std::string::npos)
371 pName = pName.substr(++pos);
373 std::auto_ptr<te::da::DataSet> pInfo = getPropertiesInfo(fullDatasetName);
374 while(pInfo->moveNext())
376 std::string attName = pInfo->getString(1);
380 unsigned int attNum = pInfo->getInt16(0);
381 unsigned int attType = pInfo->getInt32(2);
382 bool attNotNull = pInfo->getBool(3);
383 std::string fmt = pInfo->getString(4);
384 bool attHasDefault = pInfo->getBool(5);
385 std::string attDefValue = pInfo->getString(6);
386 int ndims = pInfo->getInt32(7);
389 fmt.c_str(), attHasDefault, attDefValue.c_str(),
390 ndims, m_ds->getGeomTypeId(), m_ds->getRasterTypeId());
394 getGeometryInfo(datasetName, static_cast<te::gm::GeometryProperty*>(p));
398 getRasterInfo(datasetName, static_cast<te::rst::RasterProperty*>(p));
402 return std::auto_ptr<te::dt::Property>(p);
407 std::string fullDatasetName = getFullName(datasetName);
409 boost::ptr_vector<te::dt::Property> properties = getProperties(fullDatasetName);
411 assert(propertyPos < properties.size());
413 return std::auto_ptr<te::dt::Property>(properties[propertyPos].clone());
418 std::string fullDatasetName = getFullName(datasetName);
420 boost::ptr_vector<te::dt::Property> properties = getProperties(fullDatasetName);
422 std::size_t numProperties = properties.size();
424 std::vector<std::string> pNames(numProperties);
426 for(std::size_t i = 0; i < numProperties; ++i)
427 pNames[i] = properties[i].getName();
434 std::string fullDatasetName = getFullName(datasetName);
435 return getProperties(fullDatasetName).size();
440 std::string fullDatasetName = getFullName(datasetName);
442 std::vector<std::string> pNames = getPropertyNames(fullDatasetName);
444 if(std::find(pNames.begin(), pNames.end(), name) != pNames.end())
452 std::string fullDatasetName = getFullName(datasetName);
454 std::string pName = p->
getName();
463 sql =
"SELECT AddGeometryColumn('";
466 std::size_t pos = fullDatasetName.find(
".");
468 if(pos == std::string::npos)
498 sql =
"ALTER TABLE ";
499 sql += fullDatasetName;
500 sql +=
" ADD COLUMN ";
512 std::string fullDatasetName = getFullName(datasetName);
514 std::auto_ptr<te::dt::Property> p = getProperty(fullDatasetName, name);
520 sql =
"SELECT DropGeometryColumn('";
523 std::size_t pos = fullDatasetName.find(
".");
525 if(pos == std::string::npos)
527 sql += m_ds->getCurrentSchema();
544 sql =
" ALTER TABLE ";
545 sql += fullDatasetName;
546 sql +=
" DROP COLUMN ";
554 const std::string& name,
555 const std::string& newName)
557 std::string fullDatasetName = getFullName(datasetName);
559 std::auto_ptr<te::dt::Property> p = getProperty(fullDatasetName, name);
561 std::string sql(
"ALTER TABLE ");
562 sql += fullDatasetName;
563 sql +=
" RENAME COLUMN ";
564 sql += name +
" TO ";
571 sql =
"UPDATE geometry_columns SET f_geometry_column = '" + newName +
"'";
572 sql +=
" WHERE f_table_name = '" ;
575 std::size_t pos = fullDatasetName.find(
".");
577 if(pos == std::string::npos)
579 sql += fullDatasetName;
580 sql +=
"' AND f_table_schema ='";
581 sql += m_ds->getCurrentSchema();
586 sql += fullDatasetName.substr(pos + 1);
587 sql +=
"' AND f_table_schema ='";
588 sql += fullDatasetName.substr(0, pos);
592 sql +=
" AND f_geometry_column = '" + name +
"'";
600 std::auto_ptr<te::dt::Property> prp(newProp);
604 type =
"NUMERIC USING " + propName+
"::numeric";
609 std::string sql(
"ALTER TABLE ");
610 sql += datasetName +
" ALTER COLUMN " + propName +
" TYPE " + type;
617 std::string fullDatasetName = getFullName(datasetName);
621 std::auto_ptr<te::da::DataSet> pkInfo = getConstraints(fullDatasetName,
'p');
623 while(pkInfo->moveNext())
625 unsigned int pkId = pkInfo->getInt32(0);
626 std::string pkName = pkInfo->getString(2);
630 std::auto_ptr<te::dt::Array> pkCols(pkInfo->getArray(8));
631 std::size_t size = pkCols->getDimensionSize(0);
633 std::vector<std::size_t> pos;
635 for(std::size_t i = 0; i < size; ++i)
641 std::auto_ptr<te::dt::Property> p = getProperty(static_cast<te::dt::Int16*>(pkCol)->getValue(), fullDatasetName);
642 pk->
add(p.release());
647 std::vector<std::string> idxNames = getIndexNames(fullDatasetName);
649 for(std::size_t i = 0; i < idxNames.size(); ++i)
651 if(pk->
getName() == idxNames[i])
658 return std::auto_ptr<te::da::PrimaryKey>(pk);
663 std::string fullDatasetName = getFullName(datasetName);
665 std::auto_ptr<te::da::PrimaryKey> pk = getPrimaryKey(fullDatasetName);
667 if(pk->getName() == name)
675 std::string fullDatasetName = getFullName(datasetName);
679 if(getPrimaryKey(fullDatasetName).
get() != 0)
680 dropPrimaryKey(fullDatasetName);
686 pkName = fullDatasetName +
"_pk";
688 boost::replace_all(pkName,
".",
"_");
695 std::string sql(
"ALTER TABLE ");
696 sql += fullDatasetName;
697 sql +=
" ADD CONSTRAINT ";
699 sql +=
" PRIMARY KEY (";
701 const std::vector<te::dt::Property*>& properties = pk->
getProperties();
703 std::size_t size = properties.size();
705 for(std::size_t i = 0; i < size; ++i)
710 sql += properties[i]->getName();
720 std::string fullDatasetName = getFullName(datasetName);
722 std::auto_ptr<te::da::PrimaryKey> pk = getPrimaryKey(fullDatasetName);
724 std::string pkName = pk->getName();
726 std::string sql(
"ALTER TABLE ");
727 sql += fullDatasetName;
728 sql +=
" DROP CONSTRAINT " + pkName;
735 std::string fullDatasetName = getFullName(datasetName);
739 std::auto_ptr<te::da::DataSet> fkInfo = getConstraints(fullDatasetName,
'f');
741 while(fkInfo->moveNext())
743 std::string fkName = fkInfo->getString(2);
748 unsigned int fkId = fkInfo->getInt32(0);
749 unsigned int refDatasetId = fkInfo->getInt32(4);
750 char onUpdate = fkInfo->getChar(5);
751 char onDeletion = fkInfo->getChar(6);
753 std::auto_ptr<te::dt::Array> fkCols(fkInfo->getArray(8));
754 std::auto_ptr<te::dt::Array> fkRefCols(fkInfo->getArray(9));
756 assert(fkCols->getDimension() == 1);
757 assert(fkCols->getDimension() == fkRefCols->getDimension());
758 assert(fkCols->getDimensionSize(0) == fkRefCols->getDimensionSize(0));
760 std::string refName = getDataSetName(refDatasetId);
761 std::auto_ptr<te::da::DataSetType> refdt = getDataSetType(refName);
768 std::size_t size = fkCols->getDimensionSize(0);
770 std::vector<std::size_t> pos;
773 for(std::size_t i = 0; i < size; ++i)
778 fk->
addRefProperty(refdt->getPropertyById(static_cast<te::dt::Int16*>(fkRefCol)->getValue()));
781 fk->
add(getProperty(static_cast<te::dt::Int16*>(fkCol)->getValue(), datasetName).release());
785 return std::auto_ptr<te::da::ForeignKey>(fk);
790 std::string fullDatasetName = getFullName(datasetName);
792 std::vector<std::string> fkNames;
794 std::auto_ptr<te::da::DataSet> fkInfo = getConstraints(fullDatasetName,
'f');
796 while(fkInfo->moveNext())
798 std::string fkName = fkInfo->getString(2);
799 fkNames.push_back(fkName);
807 std::string fullDatasetName = getFullName(datasetName);
809 std::vector<std::string> fkNames = getForeignKeyNames(fullDatasetName);
810 if(std::find(fkNames.begin(), fkNames.end(), name) != fkNames.end())
818 std::string fullDatasetName = getFullName(datasetName);
820 std::string fkName = fk->
getName();
822 std::string sql(
"ALTER TABLE ");
823 sql += fullDatasetName;
824 sql +=
" ADD CONSTRAINT ";
826 sql +=
" FOREIGN KEY (";
830 for(std::size_t i = 0; i < size; ++i)
842 for(
size_t i = 0; i < size; ++i)
850 sql +=
") ON DELETE ";
855 sql +=
" NO ACTION ";
872 sql +=
"SET DEFAULT ";
876 sql +=
" ON UPDATE ";
881 sql +=
" NO ACTION ";
898 sql +=
"SET DEFAULT ";
907 std::string fullDatasetName = getFullName(datasetName);
909 std::string sql(
"ALTER TABLE ");
910 sql += fullDatasetName;
911 sql +=
" DROP CONSTRAINT ";
919 std::string fullDatasetName = getFullName(datasetName);
923 std::auto_ptr<te::da::DataSet> ukInfo = getConstraints(fullDatasetName,
'u');
925 while(ukInfo->moveNext())
927 std::string ukName = ukInfo->getString(2);
932 unsigned int ukId = ukInfo->getInt32(0);
934 std::auto_ptr<te::dt::Array> ukCols(ukInfo->getArray(8));
938 std::size_t size = ukCols->getDimensionSize(0);
940 std::vector<std::size_t> pos;
943 for(std::size_t i = 0; i < size; ++i)
949 std::auto_ptr<te::dt::Property> p = getProperty(static_cast<te::dt::Int16*>(ukCol)->getValue(), fullDatasetName);
951 uk->add(p.release());
956 std::vector<std::string> idxNames = getIndexNames(fullDatasetName);
958 for(std::size_t i = 0; i < idxNames.size(); ++i)
960 if(uk->
getName() == idxNames[i])
967 return std::auto_ptr<te::da::UniqueKey>(uk);
972 std::string fullDatasetName = getFullName(datasetName);
974 std::vector<std::string> ukNames;
976 std::auto_ptr<te::da::DataSet> ukInfo = getConstraints(fullDatasetName,
'u');
978 while(ukInfo->moveNext())
980 std::string ukName = ukInfo->getString(2);
981 ukNames.push_back(ukName);
989 std::string fullDatasetName = getFullName(datasetName);
991 std::vector<std::string> ukNames = getUniqueKeyNames(fullDatasetName);
993 if(std::find(ukNames.begin(), ukNames.end(), name) != ukNames.end())
1001 std::string fullDatasetName = getFullName(datasetName);
1003 std::string ukName = uk->
getName();
1005 std::string sql(
"ALTER TABLE ");
1006 sql += fullDatasetName;
1007 sql +=
" ADD CONSTRAINT ";
1011 const std::vector<te::dt::Property*>& properties = uk->
getProperties();
1013 std::size_t size = properties.size();
1015 for(std::size_t i = 0; i < size; ++i)
1020 sql += properties[i]->getName();
1030 std::string fullDatasetName = getFullName(datasetName);
1032 std::string sql(
"ALTER TABLE ");
1033 sql += fullDatasetName;
1034 sql +=
" DROP CONSTRAINT ";
1040 if(indexExists(fullDatasetName, name))
1041 dropIndex(fullDatasetName, name);
1046 std::string fullDatasetName = getFullName(datasetName);
1050 std::auto_ptr<te::da::DataSet> ccInfo = getConstraints(datasetName,
'c');
1052 while(ccInfo->moveNext())
1054 std::string ccName = ccInfo->getString(2);
1059 unsigned int ccId = ccInfo->getInt32(0);
1066 return std::auto_ptr<te::da::CheckConstraint>(cc);
1071 std::string fullDatasetName = getFullName(datasetName);
1073 std::vector<std::string> ccNames;
1075 std::auto_ptr<te::da::DataSet> ccInfo = getConstraints(fullDatasetName,
'c');
1077 while(ccInfo->moveNext())
1079 std::string ccName = ccInfo->getString(2);
1081 ccNames.push_back(ccName);
1089 std::string fullDatasetName = getFullName(datasetName);
1091 std::vector<std::string> ccNames = getCheckConstraintNames(fullDatasetName);
1093 if(std::find(ccNames.begin(), ccNames.end(), name) != ccNames.end())
1101 std::string fullDatasetName = getFullName(datasetName);
1103 std::string ccName = cc->
getName();
1105 std::string sql(
"ALTER TABLE ");
1106 sql += fullDatasetName;
1107 sql +=
" ADD CONSTRAINT ";
1118 std::string fullDatasetName = getFullName(datasetName);
1120 std::string sql(
"ALTER TABLE ");
1121 sql += fullDatasetName;
1122 sql +=
" DROP CONSTRAINT ";
1130 std::string fullDatasetName = getFullName(datasetName);
1134 unsigned int dtid = getDataSetId(fullDatasetName);
1136 std::string sql(
"SELECT idx_table.oid, s.nspname, idx_table.relname, pg_index.indkey, pg_am.amname, pg_index.indisunique, pg_index.indisprimary "
1137 "FROM pg_index, pg_class idx_table, pg_am, pg_namespace s "
1138 "WHERE s.oid = idx_table.relnamespace "
1139 "AND pg_index.indexrelid = idx_table.oid "
1140 "AND idx_table.relam = pg_am.oid "
1141 "AND pg_index.indrelid = ");
1144 std::auto_ptr<te::da::DataSet> idxInfo = query(sql);
1146 while(idxInfo->moveNext())
1148 std::string idxName = idxInfo->getString(2);
1153 unsigned int idxId = idxInfo->getInt32(0);
1155 std::auto_ptr<te::dt::Array> idxCols(idxInfo->getArray(3));
1157 std::string idxType = idxInfo->getString(4);
1161 std::size_t size = idxCols->getDimensionSize(0);
1163 std::vector<std::size_t> pos;
1166 for(std::size_t i = 0; i < size; ++i)
1171 std::auto_ptr<te::dt::Property> p = getProperty(static_cast<te::dt::Int16*>(idxCol)->getValue(), fullDatasetName);
1173 idx->
add(p.release());
1177 return std::auto_ptr<te::da::Index>(idx);
1182 std::string fullDatasetName = getFullName(datasetName);
1184 std::vector<std::string> idxNames;
1186 unsigned int dtid = getDataSetId(fullDatasetName);
1188 std::string sql(
"SELECT idx_table.oid, s.nspname, idx_table.relname, pg_index.indkey, pg_am.amname, pg_index.indisunique, pg_index.indisprimary "
1189 "FROM pg_index, pg_class idx_table, pg_am, pg_namespace s "
1190 "WHERE s.oid = idx_table.relnamespace "
1191 "AND pg_index.indexrelid = idx_table.oid "
1192 "AND idx_table.relam = pg_am.oid "
1193 "AND pg_index.indrelid = ");
1196 std::auto_ptr<te::da::DataSet> idxInfo = query(sql);
1198 while(idxInfo->moveNext())
1200 std::string idxName = idxInfo->getString(2);
1202 idxNames.push_back(idxName);
1210 std::string fullDatasetName = getFullName(datasetName);
1212 std::vector<std::string> idxNames = getIndexNames(fullDatasetName);
1214 if(std::find(idxNames.begin(), idxNames.end(), name) != idxNames.end())
1221 const std::map<std::string, std::string>& options)
1223 std::string fullDatasetName = getFullName(datasetName);
1225 std::string idxName = idx->
getName();
1228 std::auto_ptr<te::da::PrimaryKey> pk = getPrimaryKey(fullDatasetName);
1230 if(pk.get() && (pk->getAssociatedIndex() == idx))
1233 std::vector<std::string> ukNames = getUniqueKeyNames(datasetName);
1235 for(std::size_t i = 0; i < ukNames.size(); ++i)
1236 if(getUniqueKey(datasetName, ukNames[i])->getAssociatedIndex() == idx)
1240 std::string sql(
"CREATE INDEX ");
1243 sql += fullDatasetName;
1246 sql +=
" USING HASH (";
1248 sql +=
" USING GIST (";
1250 sql +=
" USING BTREE (";
1252 throw Exception(
TE_TR(
"The index type is not supported!"));
1256 for(
size_t i = 0; i < numProperties; ++i)
1271 std::string fullDatasetName = getFullName(datasetName);
1273 std::string sql(
"DROP INDEX ");
1284 std::vector<std::string> seqNames;
1286 std::string sql(
"SELECT c.oid, n.nspname, c.relname, c.relkind "
1287 "FROM pg_class c, pg_namespace n "
1288 "WHERE c.relname !~ '^pg_' "
1289 "AND c.relkind = 'S' "
1290 "AND c.relnamespace = n.oid "
1291 "AND n.nspname NOT IN ('information_schema', 'pg_toast', 'pg_temp_1', 'pg_catalog')");
1293 std::auto_ptr<te::da::DataSet> seqNamesInfo = query(sql);
1295 while(seqNamesInfo->moveNext())
1297 std::string seqName(seqNamesInfo->getString(2));
1302 std::string sql(
"SELECT * FROM ");
1305 std::auto_ptr<te::da::DataSet> result(query(sql));
1307 if(result->moveNext())
1309 unsigned int seqId = getDataSetId(seqName);
1314 if(result->getBool(8))
1326 return std::auto_ptr<te::da::Sequence>(seq);
1331 std::vector<std::string> seqNames;
1333 std::string sql(
"SELECT c.oid, n.nspname, c.relname, c.relkind "
1334 "FROM pg_class c, pg_namespace n "
1335 "WHERE c.relname !~ '^pg_' "
1336 "AND c.relkind = 'S' "
1337 "AND c.relnamespace = n.oid "
1338 "AND n.nspname NOT IN ('information_schema', 'pg_toast', 'pg_temp_1', 'pg_catalog')");
1340 std::auto_ptr<te::da::DataSet> seqNamesInfo = query(sql);
1342 while(seqNamesInfo->moveNext())
1344 std::string seqName(seqNamesInfo->getString(2));
1345 seqNames.push_back(seqName);
1353 std::vector<std::string> seqNames = getSequenceNames();
1355 if(std::find(seqNames.begin(), seqNames.end(), name) != seqNames.end())
1363 std::string seqName = sequence->
getName();
1365 std::string sql(
"CREATE SEQUENCE ");
1367 sql +=
" INCREMENT BY ";
1369 sql +=
" MINVALUE ";
1371 sql +=
" MAXVALUE ";
1373 sql +=
" START WITH ";
1385 sql +=
" OWNED BY ";
1393 unsigned int seqId = getDataSetId(seqName);
1395 sequence->
setId(seqId);
1400 std::auto_ptr<te::da::Sequence> seq = getSequence(name);
1402 std::string sql(
"DROP SEQUENCE ");
1410 std::string sql(
"SELECT ST_Extent(");
1411 sql += propertyName;
1415 PGresult* result = PQexec(m_conn->getConn(), sql.c_str());
1417 if(PQresultStatus(result) != PGRES_TUPLES_OK)
1419 std::string errmsg(
TE_TR(
"Could not find the envelope for the given geometry property due to the following error: "));
1420 errmsg += PQerrorMessage(m_conn->getConn());
1424 throw Exception(errmsg);
1427 const char* boxStr = PQgetvalue(result, 0, 0);
1435 return std::auto_ptr<te::gm::Envelope>(mbr);
1440 std::auto_ptr<te::dt::Property> p = getProperty(datasetName, propertyPos);
1442 std::string sql(
"SELECT ST_Extent(");
1443 sql += p->getName();
1447 PGresult* result = PQexec(m_conn->getConn(), sql.c_str());
1449 if(PQresultStatus(result) != PGRES_TUPLES_OK)
1451 std::string errmsg(
TE_TR(
"Could not find the envelope for the given geometry property due to the following error: "));
1452 errmsg += PQerrorMessage(m_conn->getConn());
1456 throw Exception(errmsg);
1459 const char* boxStr = PQgetvalue(result, 0, 0);
1467 return std::auto_ptr<te::gm::Envelope>(mbr);
1472 std::auto_ptr<te::da::DataSet> result = getDataSet(datasetName);
1473 return result->size();
1478 std::vector<std::string> datasetNames = getDataSetNames();
1480 if(datasetNames.empty())
1488 std::string datasetName = getFullName(name);
1490 std::vector<std::string> datasetNames = getDataSetNames();
1492 if(std::find(datasetNames.begin(), datasetNames.end(), datasetName) != datasetNames.end())
1500 std::string datasetName = dt->
getName();
1501 datasetName = getFullName(datasetName);
1503 std::string sql =
"CREATE TABLE ";
1510 unsigned int dtid = getDataSetId(datasetName);
1515 std::size_t nCols = dt->
size();
1516 for(std::size_t i = 0; i < nCols; ++i)
1525 for(std::size_t i = 0; i < nUKs; ++i)
1530 for(std::size_t i = 0; i < nIdxs; ++i)
1531 addIndex(datasetName, dt->
getIndex(i), options);
1535 for(std::size_t i = 0; i < nFKs; ++i)
1541 for(std::size_t i = 0; i < nCCs; ++i)
1545 std::vector<std::string> indexNames = getIndexNames(datasetName);
1550 for(std::size_t i = 0; i < indexNames.size(); ++i)
1552 if(pk->
getName() == indexNames[i])
1563 for(std::size_t i = 0; i < numUKs; ++i)
1567 for(std::size_t j = 0; j < indexNames.size(); ++j)
1569 if(uk->
getName() == indexNames[j])
1579 const std::string& ,
1580 const std::map<std::string, std::string>& )
1582 throw Exception(
TE_TR(
"Not implemented yet!"));
1587 std::auto_ptr<te::da::DataSetType> dt = getDataSetType(name);
1593 std::string tSchema, tName;
1594 SplitTableName(dt->getName(), &(m_ds->getCurrentSchema()), tSchema, tName);
1596 sql =
"SELECT DropGeometryTable('";
1604 sql +=
"DROP TABLE ";
1605 sql += dt->getName();
1613 std::string newTableName, newTableSchema, oldTableName, oldTableSchema;
1615 std::string sql(
"ALTER TABLE ");
1617 sql +=
" RENAME TO ";
1619 SplitTableName(newName, &(m_ds->getCurrentSchema()), newTableSchema, newTableName);
1621 sql += newTableName;
1626 std::auto_ptr<te::da::DataSetType> dt = getDataSetType(name);
1630 SplitTableName(name, &(m_ds->getCurrentSchema()), oldTableSchema, oldTableName);
1632 sql =
"UPDATE geometry_columns SET f_table_name = '";
1633 sql += newTableName;
1634 sql +=
"' WHERE f_table_name = '";
1635 sql += oldTableName;
1636 sql +=
"' AND f_table_schema ='";
1637 sql += oldTableSchema;
1646 const std::map<std::string, std::string>& options,
1650 limit = std::string::npos;
1653 std::string sql =
"INSERT INTO ";
1659 std::auto_ptr<PreparedQuery> pq(
new PreparedQuery(
this,
"a" + boost::lexical_cast<std::string>((intptr_t)(
this))));
1665 std::size_t nProcessedRows = 0;
1667 pq->prepare(sql, paramTypes);
1669 while(d->
moveNext() && (nProcessedRows != limit))
1683 throw Exception(
TE_TR(
"Not implemented yet!"));
1763 const std::vector<std::size_t>& ,
1765 const std::map<std::string, std::string>& ,
1768 throw Exception(
TE_TR(
"Not implemented yet!"));
1821 const std::vector< std::set<int> >& properties,
1822 const std::vector<size_t>& ids)
1828 std::set<int>::iterator it;
1836 std::string sql =
"UPDATE " + datasetName +
" SET ";
1837 plst = properties[i];
1843 for(it = plst.begin(); it != plst.end(); ++it)
1861 for(
size_t j=0; j<ids.size(); ++j)
1874 sql +=
"(" + pName +
")=(" + value +
") WHERE " + id;
1883 catch(te::pgis::Exception& e)
1893 throw Exception(
TE_TR(
"Not implemented yet!"));
1898 std::string sql(
"SELECT oid FROM pg_type WHERE typname = 'geometry'");
1900 std::auto_ptr<te::da::DataSet> result(query(sql));
1902 unsigned int id = 0;
1904 if(result->moveNext())
1905 id = result->getInt32(0);
1912 std::string sql(
"SELECT oid FROM pg_type WHERE typname = 'raster'");
1914 std::auto_ptr<te::da::DataSet> result(query(sql));
1916 unsigned int id = 0;
1918 if(result->moveNext())
1919 id = result->getInt32(0);
1926 std::string sql(
"SELECT current_schema()");
1928 std::auto_ptr<te::da::DataSet> result(query(sql));
1930 if(!result->moveNext())
1931 Exception(
TE_TR(
"Could not get information about PostgreSQL database backend!"));
1933 currentSchema = result->getString(0);
1938 std::string sql =
"SELECT g.coord_dimension, g.srid, g.type "
1939 "FROM geometry_columns g "
1940 "WHERE lower(g.f_table_name) = '";
1942 std::string tname, sname;
1944 SplitTableName(datasetName, &(m_ds->getCurrentSchema()), sname, tname);
1947 sql +=
"' AND g.f_table_schema = '";
1949 sql +=
"' AND f_geometry_column = '";
1953 std::auto_ptr<te::da::DataSet> result(query(sql));
1955 if(result->moveNext())
1958 int srid = result->getInt32(1);
1978 std::string sql =
"SELECT * FROM raster_columns as r WHERE r.r_table_name = '";
1980 std::string tname, sname;
1982 SplitTableName(datasetName, &(m_ds->getCurrentSchema()), sname, tname);
1985 sql +=
"' AND r.r_table_schema = '";
1987 sql +=
"' AND r_raster_column = '";
1991 std::auto_ptr<te::da::DataSet> result(query(sql));
1993 if(result->moveNext())
1995 int srid = result->getInt32(
"srid");
2000 double scale_x = result->getDouble(
"scale_x");
2002 double scale_y = result->getDouble(
"scale_y");
2004 int blocksize_x = result->getInt32(
"blocksize_x");
2006 int blocksize_y = result->getInt32(
"blocksize_y");
2010 int nbands = result->getInt32(
"num_bands");
2012 std::auto_ptr<te::dt::Array> pixel_types(result->getArray(
"pixel_types"));
2014 std::auto_ptr<te::dt::Array> nodata_values(result->getArray(
"nodata_values"));
2016 std::auto_ptr<te::gm::Geometry> g(result->getGeometry(
"extent"));
2022 rp->
set(grid.release());
2024 for(
int i = 0; i != nbands; ++i)
2026 std::vector<std::size_t> pos(1, i);
2028 std::string st = pixel_types->getData(pos)->toString();
2034 else if(st ==
"8BUI")
2036 else if(st ==
"16BI")
2038 else if(st ==
"16BUI")
2040 else if(st ==
"32BI")
2042 else if(st ==
"32BUI")
2044 else if(st ==
"32BF")
2046 else if(st ==
"64BF")
2049 throw Exception(
TE_TR(
"Band data type not supported by PostGIS driver!"));
2053 bp->
m_blkh = blocksize_y;
2055 bp->
m_blkw = blocksize_x;
2073 std::string fullName = name;
2075 if(fullName.find(
".") == std::string::npos)
2076 fullName = m_ds->getCurrentSchema() +
"." + name;
2085 std::string tname, sname;
2087 SplitTableName(tableName, &(m_ds->getCurrentSchema()), sname, tname);
2089 std::string sql(
"SELECT pg_class.oid "
2090 "FROM pg_class, pg_namespace "
2091 "WHERE pg_class.relnamespace = pg_namespace.oid "
2092 "AND lower(pg_class.relname) = '");
2095 sql +=
"' AND lower(pg_namespace.nspname) = '";
2099 std::auto_ptr<te::da::DataSet> result(query(sql));
2101 if(result->moveNext() ==
false)
2102 throw Exception(
TE_TR(
"Could not find the table oid!"));
2104 unsigned int tableid = result->getInt32(0);
2111 std::string sql(
"SELECT pg_namespace.nspname, pg_class.relname "
2112 "FROM pg_class, pg_namespace "
2113 "WHERE pg_class.relnamespace = pg_namespace.oid "
2114 "AND pg_class.oid = ");
2118 std::auto_ptr<te::da::DataSet> result(query(sql));
2120 if(result->moveNext() ==
false)
2121 throw Exception(
TE_TR(
"Could not find the dataset name!"));
2123 std::string tname = result->getString(0);
2125 tname += result->getString(1);
2132 std::string fullDatasetName = getFullName(datasetName);
2134 unsigned int dtid = getDataSetId(fullDatasetName);
2136 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 "
2137 "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) "
2138 "WHERE a.attrelid = ");
2140 sql +=
" AND a.attisdropped = false"
2142 " ORDER BY a.attnum";
2150 throw Exception(
TE_TR(
"The informed property is not valid!"));
2152 std::string sql(
"SELECT attnum "
2153 "FROM pg_attribute WHERE attrelid = ");
2155 sql +=
" AND attisdropped = false "
2160 std::auto_ptr<te::da::DataSet> result(query(sql));
2162 if(result->moveNext() ==
false)
2163 throw Exception(
TE_TR(
"Could not find the property ID!"));
2165 unsigned int id = result->getInt32(0);
2171 unsigned int dtid = getDataSetId(datasetName);
2173 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 "
2174 "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) "
2175 "WHERE a.attrelid = ");
2177 sql +=
" AND a.attnum = ";
2179 sql +=
" AND a.attisdropped = false"
2180 " AND a.attnum > 0";
2182 std::auto_ptr<te::da::DataSet> result(query(sql));
2184 std::auto_ptr<te::dt::Property> p(0);
2186 if(result->moveNext())
2188 unsigned int attNum = result->getInt16(0);
2189 std::string attName = result->getString(1);
2190 unsigned int attType = result->getInt32(2);
2191 bool attNotNull = result->getBool(3);
2192 std::string fmt = result->getString(4);
2193 bool attHasDefault = result->getBool(5);
2194 std::string attDefValue = result->getString(6);
2195 int ndims = result->getInt32(7);
2197 p.reset(
Convert2TerraLib(attNum, attName.c_str(), attType, attNotNull, fmt.c_str(), attHasDefault,
2198 attDefValue.c_str(),ndims, m_ds->getGeomTypeId(), m_ds->getRasterTypeId()));
2201 getGeometryInfo(datasetName, static_cast<te::gm::GeometryProperty*>(p.get()));
2209 unsigned int dtid = getDataSetId(datasetName);
2211 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) "
2212 "FROM pg_constraint c, pg_namespace n "
2213 "WHERE c.connamespace = n.oid "
2214 "AND c.conrelid = ");
2219 sql +=
" AND c.contype = '";
2229 std::string datasetName = dt->
getName();
2230 unsigned int dtid = dt->
getId();
2232 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) "
2233 "FROM pg_constraint c, pg_namespace n "
2234 "WHERE c.connamespace = n.oid "
2235 "AND c.conrelid = ");
2238 std::auto_ptr<te::da::DataSet> cInfo = query(sql);
2240 while(cInfo->moveNext())
2242 char cType = cInfo->getChar(3);
2246 unsigned int pkId = cInfo->getInt32(0);
2247 std::string pkName = cInfo->getString(2);
2251 std::auto_ptr<te::dt::Array> pkCols(cInfo->getArray(8));
2252 std::size_t size = pkCols->getDimensionSize(0);
2254 std::vector<std::size_t> pos;
2256 for(std::size_t i = 0; i < size; ++i)
2267 std::vector<std::string> idxNames = getIndexNames(datasetName);
2269 for(std::size_t i = 0; i < idxNames.size(); ++i)
2271 if(pk->
getName() == idxNames[i])
2282 else if (cType ==
'f')
2285 unsigned int fkId = cInfo->getInt32(0);
2286 unsigned int refDatasetId = cInfo->getInt32(4);
2287 char onUpdate = cInfo->getChar(5);
2288 char onDeletion = cInfo->getChar(6);
2290 std::auto_ptr<te::dt::Array> fkCols(cInfo->getArray(8));
2291 std::auto_ptr<te::dt::Array> fkRefCols(cInfo->getArray(9));
2293 assert(fkCols->getDimension() == 1);
2294 assert(fkCols->getDimension() == fkRefCols->getDimension());
2295 assert(fkCols->getDimensionSize(0) == fkRefCols->getDimensionSize(0));
2297 std::string refName = getDataSetName(refDatasetId);
2299 std::auto_ptr<te::da::DataSetType> refDatasetType = getDataSetType(refName);
2301 std::string fkName = cInfo->getString(2);
2308 std::size_t size = fkCols->getDimensionSize(0);
2310 std::vector<std::size_t> pos;
2313 for(std::size_t i = 0; i < size; ++i)
2318 fk->
addRefProperty(refDatasetType->getPropertyById(static_cast<te::dt::Int16*>(fkRefCol)->getValue()));
2321 fk->
add(getProperty(static_cast<te::dt::Int16*>(fkCol)->getValue(), datasetName).release());
2328 else if(cType ==
'u')
2331 unsigned int ukId = cInfo->getInt32(0);
2332 std::string ukName = cInfo->getString(2);
2334 std::auto_ptr<te::dt::Array> ukCols(cInfo->getArray(8));
2338 std::size_t size = ukCols->getDimensionSize(0);
2340 std::vector<std::size_t> pos;
2343 for(std::size_t i = 0; i < size; ++i)
2349 std::auto_ptr<te::dt::Property> p = getProperty(static_cast<te::dt::Int16*>(ukCol)->getValue(), datasetName);
2350 uk->add(p.release());
2354 std::vector<std::string> idxNames = getIndexNames(datasetName);
2356 for(std::size_t i = 0; i < idxNames.size(); ++i)
2358 if(uk->getName() == idxNames[i])
2360 uk->setAssociatedIndex(getIndex(datasetName, idxNames[i]).
get());
2369 else if(cType ==
'c')
2372 std::string ccName = cInfo->getString(2);
2374 unsigned int ccId = cInfo->getInt32(0);
2389 std::string datasetName = dt->
getName();
2390 unsigned int dtid = dt->
getId();
2392 std::string sql(
"SELECT idx_table.oid, s.nspname, idx_table.relname, pg_index.indkey, pg_am.amname, pg_index.indisunique, pg_index.indisprimary "
2393 "FROM pg_index, pg_class idx_table, pg_am, pg_namespace s "
2394 "WHERE s.oid = idx_table.relnamespace "
2395 "AND pg_index.indexrelid = idx_table.oid "
2396 "AND idx_table.relam = pg_am.oid "
2397 "AND pg_index.indrelid = ");
2400 std::auto_ptr<te::da::DataSet> idxInfo = query(sql);
2402 while(idxInfo->moveNext())
2404 unsigned int idxId = idxInfo->getInt32(0);
2405 std::string idxName = idxInfo->getString(2);
2407 std::auto_ptr<te::dt::Array> idxCols(idxInfo->getArray(3));
2409 std::string idxType = idxInfo->getString(4);
2410 bool isUK = idxInfo->getBool(5);
2411 bool isPK = idxInfo->getBool(6);
2415 std::size_t size = idxCols->getDimensionSize(0);
2417 std::vector<std::size_t> pos;
2420 for(std::size_t i = 0; i < size; ++i)
2429 idxName = idxInfo->getString(2);
2446 std::vector<te::da::Sequence*> seqs;
2449 std::vector<std::string> seqNames;
2451 std::string sql(
"SELECT c.oid, n.nspname, c.relname, c.relkind "
2452 "FROM pg_class c, pg_namespace n "
2453 "WHERE c.relname !~ '^pg_' "
2454 "AND c.relkind = 'S' "
2455 "AND c.relnamespace = n.oid "
2456 "AND n.nspname NOT IN ('information_schema', 'pg_toast', 'pg_temp_1', 'pg_catalog')");
2458 std::auto_ptr<te::da::DataSet> seqNamesInfo = query(sql);
2460 while(seqNamesInfo->moveNext())
2462 std::string seqName(seqNamesInfo->getString(2));
2463 seqNames.push_back(seqName);
2466 for(std::size_t i = 0; i < seqNames.size(); ++i)
2468 std::string seqName = seqNames[i];
2470 std::string sql(
"SELECT * FROM ");
2473 std::auto_ptr<te::da::DataSet> result(query(sql));
2475 if(result->moveNext() ==
false)
2476 throw Exception((boost::format(
TE_TR(
"There is no information about the sequence \"%1%\"!")) % seqName).str());
2478 unsigned int seqId = getDataSetId(seqName);
2483 if(result->getBool(8))
2493 seqs.push_back(seq);
2501 int encodingId = PQclientEncoding(m_conn->getConn());
2502 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.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
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).
#define PGIS_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in PostGIS.
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.