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/Property.h"
43 #include "../datatype/SimpleData.h"
44 #include "../geometry/GeometryProperty.h"
45 #include "../geometry/Utils.h"
46 #include "../raster/Grid.h"
47 #include "../raster/BandProperty.h"
48 #include "../raster/RasterProperty.h"
49 #include "../geometry/Geometry.h"
66 #include <boost/format.hpp>
74 m_isInTransaction(false)
80 m_ds->getConnPool()->release(m_conn);
96 m_isInTransaction =
true;
101 m_isInTransaction =
false;
107 m_isInTransaction =
false;
113 return m_isInTransaction;
121 std::auto_ptr<std::string> sql(
new std::string(
"SELECT * FROM "));
124 PGresult* result = m_conn->query(*sql);
126 std::vector<int> ptypes;
127 Convert2TerraLib(result, m_ds->getGeomTypeId(), m_ds->getRasterTypeId(), ptypes);
129 return std::auto_ptr<te::da::DataSet>(
new DataSet(result, ptypes, m_ds->isTimeAnInteger()));
133 const std::string& propertyName,
141 throw Exception(
TR_PGIS(
"The envelope is missing!"));
143 std::auto_ptr<te::dt::Property> p = getProperty(name, propertyName);
149 std::string sql(
"SELECT * FROM ");
157 PGresult* result = m_conn->query(sql);
159 std::vector<int> ptypes;
160 Convert2TerraLib(result, m_ds->getGeomTypeId(), m_ds->getRasterTypeId(), ptypes);
162 return std::auto_ptr<te::da::DataSet>(
new DataSet(result, ptypes, m_ds->isTimeAnInteger()));
166 const std::string& propertyName,
174 throw Exception(
TR_PGIS(
"The geometry is missing!"));
178 std::string sql(
"SELECT * FROM ");
190 PGresult* result = m_conn->query(sql);
192 std::vector<int> ptypes;
193 Convert2TerraLib(result, m_ds->getGeomTypeId(), m_ds->getRasterTypeId(), ptypes);
195 return std::auto_ptr<te::da::DataSet>(
new DataSet(result, ptypes, m_ds->isTimeAnInteger()));
205 SQLVisitor visitor(*(m_ds->getDialect()), sql, m_conn->getConn());
208 return query(sql, travType, isConnected,accessPolicy);
216 PGresult* result = m_conn->query(query);
218 std::vector<int> ptypes;
219 Convert2TerraLib(result, m_ds->getGeomTypeId(), m_ds->getRasterTypeId(), ptypes);
221 return std::auto_ptr<te::da::DataSet>(
new DataSet(result, ptypes, m_ds->isTimeAnInteger()));
228 SQLVisitor visitor(*(m_ds->getDialect()), sql, m_conn->getConn());
236 m_conn->execute(command);
241 return std::auto_ptr<te::da::PreparedQuery>(
new PreparedQuery(
this, qName));
246 return std::auto_ptr<te::da::BatchExecutor>(0);
255 throw Exception(
TR_PGIS(
"Not implemented yet!"));
275 std::vector<std::string> datasetNames;
277 std::string sql(
"SELECT pg_class.oid, pg_namespace.nspname, pg_class.relname, pg_class.relkind "
278 "FROM pg_class, pg_namespace "
279 "WHERE pg_class.relname !~ '^pg_' "
280 "AND pg_class.relname NOT IN ('spatial_ref_sys', 'geometry_columns', 'geography_columns', 'raster_columns', 'raster_overviews') "
281 "AND pg_class.relkind in ('r','v') "
282 "AND pg_class.relnamespace = pg_namespace.oid "
283 "AND pg_namespace.nspname NOT IN ('information_schema', 'pg_toast', 'pg_temp_1', 'pg_catalog', 'topology')");
285 std::auto_ptr<te::da::DataSet> datasetInfo = query(sql);
287 while(datasetInfo->moveNext())
289 std::string datasetName = std::string(datasetInfo->getString(1) +
"." + datasetInfo->getString(2));
290 datasetNames.push_back(datasetName);
298 return getDataSetNames().size();
303 std::string datasetName = getFullName(name);
306 unsigned int dtid = getDataSetId(datasetName);
313 boost::ptr_vector<te::dt::Property> properties = getProperties(datasetName);
314 for(std::size_t i = 0; i < properties.size(); ++i)
326 return std::auto_ptr<te::da::DataSetType>(dt);
331 std::string fullDatasetName = getFullName(datasetName);
333 boost::ptr_vector<te::dt::Property> properties;
335 std::auto_ptr<te::da::DataSet> pInfo = getPropertiesInfo(fullDatasetName);
337 while(pInfo->moveNext())
339 unsigned int attNum = pInfo->getInt16(0);
340 std::string attName = pInfo->getString(1);
341 unsigned int attType = pInfo->getInt32(2);
342 bool attNotNull = pInfo->getBool(3);
343 std::string fmt = pInfo->getString(4);
344 bool attHasDefault = pInfo->getBool(5);
345 std::string attDefValue = pInfo->getString(6);
346 int ndims = pInfo->getInt32(7);
349 fmt.c_str(), attHasDefault, attDefValue.c_str(),
350 ndims, m_ds->getGeomTypeId(), m_ds->getRasterTypeId());
352 properties.push_back(p);
356 getGeometryInfo(datasetName, static_cast<te::gm::GeometryProperty*>(p));
360 getRasterInfo(datasetName, static_cast<te::rst::RasterProperty*>(p));
369 std::string fullDatasetName = getFullName(datasetName);
373 std::string pName = name;
376 std::size_t pos = pName.find_last_of(
".");
377 if(pos != std::string::npos)
378 pName = pName.substr(++pos);
380 std::auto_ptr<te::da::DataSet> pInfo = getPropertiesInfo(fullDatasetName);
381 while(pInfo->moveNext())
383 std::string attName = pInfo->getString(1);
387 unsigned int attNum = pInfo->getInt16(0);
388 unsigned int attType = pInfo->getInt32(2);
389 bool attNotNull = pInfo->getBool(3);
390 std::string fmt = pInfo->getString(4);
391 bool attHasDefault = pInfo->getBool(5);
392 std::string attDefValue = pInfo->getString(6);
393 int ndims = pInfo->getInt32(7);
396 fmt.c_str(), attHasDefault, attDefValue.c_str(),
397 ndims, m_ds->getGeomTypeId(), m_ds->getRasterTypeId());
401 getGeometryInfo(datasetName, static_cast<te::gm::GeometryProperty*>(p));
405 getRasterInfo(datasetName, static_cast<te::rst::RasterProperty*>(p));
409 return std::auto_ptr<te::dt::Property>(p);
414 std::string fullDatasetName = getFullName(datasetName);
416 boost::ptr_vector<te::dt::Property> properties = getProperties(fullDatasetName);
418 assert(propertyPos < properties.size());
420 return std::auto_ptr<te::dt::Property>(properties[propertyPos].clone());
425 std::string fullDatasetName = getFullName(datasetName);
427 boost::ptr_vector<te::dt::Property> properties = getProperties(fullDatasetName);
429 std::size_t numProperties = properties.size();
431 std::vector<std::string> pNames(numProperties);
433 for(std::size_t i = 0; i < numProperties; ++i)
434 pNames[i] = properties[i].getName();
441 std::string fullDatasetName = getFullName(datasetName);
442 return getProperties(fullDatasetName).size();
447 std::string fullDatasetName = getFullName(datasetName);
449 std::vector<std::string> pNames = getPropertyNames(fullDatasetName);
451 if(std::find(pNames.begin(), pNames.end(), name) != pNames.end())
459 std::string fullDatasetName = getFullName(datasetName);
461 std::string pName = p->
getName();
470 sql =
"SELECT AddGeometryColumn('";
473 std::size_t pos = fullDatasetName.find(
".");
475 if(pos == std::string::npos)
499 sql =
"ALTER TABLE ";
500 sql += fullDatasetName;
501 sql +=
" ADD COLUMN ";
513 std::string fullDatasetName = getFullName(datasetName);
515 std::auto_ptr<te::dt::Property> p = getProperty(fullDatasetName, name);
521 sql =
"SELECT DropGeometryColumn('";
524 std::size_t pos = fullDatasetName.find(
".");
526 if(pos == std::string::npos)
528 sql += m_ds->getCurrentSchema();
545 sql =
" ALTER TABLE ";
546 sql += fullDatasetName;
547 sql +=
" DROP COLUMN ";
555 const std::string& name,
556 const std::string& newName)
558 std::string fullDatasetName = getFullName(datasetName);
560 std::auto_ptr<te::dt::Property> p = getProperty(fullDatasetName, name);
562 std::string sql(
"ALTER TABLE ");
563 sql += fullDatasetName;
564 sql +=
" RENAME COLUMN ";
565 sql += name +
" TO ";
572 sql =
"UPDATE geometry_columns SET f_geometry_column = '" + newName +
"'";
573 sql +=
" WHERE f_table_name = '" ;
576 std::size_t pos = fullDatasetName.find(
".");
578 if(pos == std::string::npos)
580 sql += fullDatasetName;
581 sql +=
"' AND f_table_schema ='";
582 sql += m_ds->getCurrentSchema();
587 sql += fullDatasetName.substr(pos + 1);
588 sql +=
"' AND f_table_schema ='";
589 sql += fullDatasetName.substr(0, pos);
593 sql +=
" AND f_geometry_column = '" + name +
"'";
601 std::string fullDatasetName = getFullName(datasetName);
605 std::auto_ptr<te::da::DataSet> pkInfo = getConstraints(fullDatasetName,
'p');
607 while(pkInfo->moveNext())
609 unsigned int pkId = pkInfo->getInt32(0);
610 std::string pkName = pkInfo->getString(2);
614 std::auto_ptr<te::dt::Array> pkCols(pkInfo->getArray(8));
615 std::size_t size = pkCols->getDimensionSize(0);
617 std::vector<std::size_t> pos;
619 for(std::size_t i = 0; i < size; ++i)
625 std::auto_ptr<te::dt::Property> p = getProperty(static_cast<te::dt::Int16*>(pkCol)->getValue(), fullDatasetName);
626 pk->
add(p.release());
631 std::vector<std::string> idxNames = getIndexNames(fullDatasetName);
633 for(std::size_t i = 0; i < idxNames.size(); ++i)
635 if(pk->
getName() == idxNames[i])
642 return std::auto_ptr<te::da::PrimaryKey>(pk);
647 std::string fullDatasetName = getFullName(datasetName);
649 std::auto_ptr<te::da::PrimaryKey> pk = getPrimaryKey(fullDatasetName);
651 if(pk->getName() == name)
659 std::string fullDatasetName = getFullName(datasetName);
663 if(getPrimaryKey(fullDatasetName).
get() != 0)
664 dropPrimaryKey(fullDatasetName);
670 pkName = fullDatasetName +
"_pk";
672 boost::replace_all(pkName,
".",
"_");
679 std::string sql(
"ALTER TABLE ");
680 sql += fullDatasetName;
681 sql +=
" ADD CONSTRAINT ";
683 sql +=
" PRIMARY KEY (";
685 const std::vector<te::dt::Property*>& properties = pk->
getProperties();
687 std::size_t size = properties.size();
689 for(std::size_t i = 0; i < size; ++i)
694 sql += properties[i]->getName();
704 std::string fullDatasetName = getFullName(datasetName);
706 std::auto_ptr<te::da::PrimaryKey> pk = getPrimaryKey(fullDatasetName);
708 std::string pkName = pk->getName();
710 std::string sql(
"ALTER TABLE ");
711 sql += fullDatasetName;
712 sql +=
" DROP CONSTRAINT " + pkName;
719 std::string fullDatasetName = getFullName(datasetName);
723 std::auto_ptr<te::da::DataSet> fkInfo = getConstraints(fullDatasetName,
'f');
725 while(fkInfo->moveNext())
727 std::string fkName = fkInfo->getString(2);
732 unsigned int fkId = fkInfo->getInt32(0);
733 unsigned int refDatasetId = fkInfo->getInt32(4);
734 char onUpdate = fkInfo->getChar(5);
735 char onDeletion = fkInfo->getChar(6);
737 std::auto_ptr<te::dt::Array> fkCols(fkInfo->getArray(8));
738 std::auto_ptr<te::dt::Array> fkRefCols(fkInfo->getArray(9));
740 assert(fkCols->getDimension() == 1);
741 assert(fkCols->getDimension() == fkRefCols->getDimension());
742 assert(fkCols->getDimensionSize(0) == fkRefCols->getDimensionSize(0));
744 std::string refName = getDataSetName(refDatasetId);
745 std::auto_ptr<te::da::DataSetType> refdt = getDataSetType(refName);
752 std::size_t size = fkCols->getDimensionSize(0);
754 std::vector<std::size_t> pos;
757 for(std::size_t i = 0; i < size; ++i)
762 fk->
addRefProperty(refdt->getPropertyById(static_cast<te::dt::Int16*>(fkRefCol)->getValue()));
765 fk->
add(getProperty(static_cast<te::dt::Int16*>(fkCol)->getValue(), datasetName).release());
769 return std::auto_ptr<te::da::ForeignKey>(fk);
774 std::string fullDatasetName = getFullName(datasetName);
776 std::vector<std::string> fkNames;
778 std::auto_ptr<te::da::DataSet> fkInfo = getConstraints(fullDatasetName,
'f');
780 while(fkInfo->moveNext())
782 std::string fkName = fkInfo->getString(2);
783 fkNames.push_back(fkName);
791 std::string fullDatasetName = getFullName(datasetName);
793 std::vector<std::string> fkNames = getForeignKeyNames(fullDatasetName);
794 if(std::find(fkNames.begin(), fkNames.end(), name) != fkNames.end())
802 std::string fullDatasetName = getFullName(datasetName);
804 std::string fkName = fk->
getName();
806 std::string sql(
"ALTER TABLE ");
807 sql += fullDatasetName;
808 sql +=
" ADD CONSTRAINT ";
810 sql +=
" FOREIGN KEY (";
814 for(std::size_t i = 0; i < size; ++i)
826 for(
size_t i = 0; i < size; ++i)
834 sql +=
") ON DELETE ";
839 sql +=
" NO ACTION ";
856 sql +=
"SET DEFAULT ";
860 sql +=
" ON UPDATE ";
865 sql +=
" NO ACTION ";
882 sql +=
"SET DEFAULT ";
891 std::string fullDatasetName = getFullName(datasetName);
893 std::string sql(
"ALTER TABLE ");
894 sql += fullDatasetName;
895 sql +=
" DROP CONSTRAINT ";
903 std::string fullDatasetName = getFullName(datasetName);
907 std::auto_ptr<te::da::DataSet> ukInfo = getConstraints(fullDatasetName,
'u');
909 while(ukInfo->moveNext())
911 std::string ukName = ukInfo->getString(2);
916 unsigned int ukId = ukInfo->getInt32(0);
918 std::auto_ptr<te::dt::Array> ukCols(ukInfo->getArray(8));
922 std::size_t size = ukCols->getDimensionSize(0);
924 std::vector<std::size_t> pos;
927 for(std::size_t i = 0; i < size; ++i)
933 std::auto_ptr<te::dt::Property> p = getProperty(static_cast<te::dt::Int16*>(ukCol)->getValue(), fullDatasetName);
935 uk->add(p.release());
940 std::vector<std::string> idxNames = getIndexNames(fullDatasetName);
942 for(std::size_t i = 0; i < idxNames.size(); ++i)
944 if(uk->
getName() == idxNames[i])
951 return std::auto_ptr<te::da::UniqueKey>(uk);
956 std::string fullDatasetName = getFullName(datasetName);
958 std::vector<std::string> ukNames;
960 std::auto_ptr<te::da::DataSet> ukInfo = getConstraints(fullDatasetName,
'u');
962 while(ukInfo->moveNext())
964 std::string ukName = ukInfo->getString(2);
965 ukNames.push_back(ukName);
973 std::string fullDatasetName = getFullName(datasetName);
975 std::vector<std::string> ukNames = getUniqueKeyNames(fullDatasetName);
977 if(std::find(ukNames.begin(), ukNames.end(), name) != ukNames.end())
985 std::string fullDatasetName = getFullName(datasetName);
987 std::string ukName = uk->
getName();
989 std::string sql(
"ALTER TABLE ");
990 sql += fullDatasetName;
991 sql +=
" ADD CONSTRAINT ";
995 const std::vector<te::dt::Property*>& properties = uk->
getProperties();
997 std::size_t size = properties.size();
999 for(std::size_t i = 0; i < size; ++i)
1004 sql += properties[i]->getName();
1014 std::string fullDatasetName = getFullName(datasetName);
1016 std::string sql(
"ALTER TABLE ");
1017 sql += fullDatasetName;
1018 sql +=
" DROP CONSTRAINT ";
1024 if(indexExists(fullDatasetName, name))
1025 dropIndex(fullDatasetName, name);
1030 std::string fullDatasetName = getFullName(datasetName);
1034 std::auto_ptr<te::da::DataSet> ccInfo = getConstraints(datasetName,
'c');
1036 while(ccInfo->moveNext())
1038 std::string ccName = ccInfo->getString(2);
1043 unsigned int ccId = ccInfo->getInt32(0);
1050 return std::auto_ptr<te::da::CheckConstraint>(cc);
1055 std::string fullDatasetName = getFullName(datasetName);
1057 std::vector<std::string> ccNames;
1059 std::auto_ptr<te::da::DataSet> ccInfo = getConstraints(fullDatasetName,
'c');
1061 while(ccInfo->moveNext())
1063 std::string ccName = ccInfo->getString(2);
1065 ccNames.push_back(ccName);
1073 std::string fullDatasetName = getFullName(datasetName);
1075 std::vector<std::string> ccNames = getCheckConstraintNames(fullDatasetName);
1077 if(std::find(ccNames.begin(), ccNames.end(), name) != ccNames.end())
1085 std::string fullDatasetName = getFullName(datasetName);
1087 std::string ccName = cc->
getName();
1089 std::string sql(
"ALTER TABLE ");
1090 sql += fullDatasetName;
1091 sql +=
" ADD CONSTRAINT ";
1102 std::string fullDatasetName = getFullName(datasetName);
1104 std::string sql(
"ALTER TABLE ");
1105 sql += fullDatasetName;
1106 sql +=
" DROP CONSTRAINT ";
1114 std::string fullDatasetName = getFullName(datasetName);
1118 unsigned int dtid = getDataSetId(fullDatasetName);
1120 std::string sql(
"SELECT idx_table.oid, s.nspname, idx_table.relname, pg_index.indkey, pg_am.amname, pg_index.indisunique, pg_index.indisprimary "
1121 "FROM pg_index, pg_class idx_table, pg_am, pg_namespace s "
1122 "WHERE s.oid = idx_table.relnamespace "
1123 "AND pg_index.indexrelid = idx_table.oid "
1124 "AND idx_table.relam = pg_am.oid "
1125 "AND pg_index.indrelid = ");
1128 std::auto_ptr<te::da::DataSet> idxInfo = query(sql);
1130 while(idxInfo->moveNext())
1132 std::string idxName = idxInfo->getString(2);
1137 unsigned int idxId = idxInfo->getInt32(0);
1139 std::auto_ptr<te::dt::Array> idxCols(idxInfo->getArray(3));
1141 std::string idxType = idxInfo->getString(4);
1145 std::size_t size = idxCols->getDimensionSize(0);
1147 std::vector<std::size_t> pos;
1150 for(std::size_t i = 0; i < size; ++i)
1155 std::auto_ptr<te::dt::Property> p = getProperty(static_cast<te::dt::Int16*>(idxCol)->getValue(), fullDatasetName);
1157 idx->
add(p.release());
1161 return std::auto_ptr<te::da::Index>(idx);
1166 std::string fullDatasetName = getFullName(datasetName);
1168 std::vector<std::string> idxNames;
1170 unsigned int dtid = getDataSetId(fullDatasetName);
1172 std::string sql(
"SELECT idx_table.oid, s.nspname, idx_table.relname, pg_index.indkey, pg_am.amname, pg_index.indisunique, pg_index.indisprimary "
1173 "FROM pg_index, pg_class idx_table, pg_am, pg_namespace s "
1174 "WHERE s.oid = idx_table.relnamespace "
1175 "AND pg_index.indexrelid = idx_table.oid "
1176 "AND idx_table.relam = pg_am.oid "
1177 "AND pg_index.indrelid = ");
1180 std::auto_ptr<te::da::DataSet> idxInfo = query(sql);
1182 while(idxInfo->moveNext())
1184 std::string idxName = idxInfo->getString(2);
1186 idxNames.push_back(idxName);
1194 std::string fullDatasetName = getFullName(datasetName);
1196 std::vector<std::string> idxNames = getIndexNames(fullDatasetName);
1198 if(std::find(idxNames.begin(), idxNames.end(), name) != idxNames.end())
1205 const std::map<std::string, std::string>& options)
1207 std::string fullDatasetName = getFullName(datasetName);
1209 std::string idxName = idx->
getName();
1212 std::auto_ptr<te::da::PrimaryKey> pk = getPrimaryKey(fullDatasetName);
1214 if(pk.get() && (pk->getAssociatedIndex() == idx))
1217 std::vector<std::string> ukNames = getUniqueKeyNames(datasetName);
1219 for(std::size_t i = 0; i < ukNames.size(); ++i)
1220 if(getUniqueKey(datasetName, ukNames[i])->getAssociatedIndex() == idx)
1224 std::string sql(
"CREATE INDEX ");
1227 sql += fullDatasetName;
1230 sql +=
" USING HASH (";
1232 sql +=
" USING GIST (";
1234 sql +=
" USING BTREE (";
1236 throw Exception(
TR_PGIS(
"The index type is not supported!"));
1240 for(
size_t i = 0; i < numProperties; ++i)
1255 std::string fullDatasetName = getFullName(datasetName);
1257 std::string sql(
"DROP INDEX ");
1268 std::vector<std::string> seqNames;
1270 std::string sql(
"SELECT c.oid, n.nspname, c.relname, c.relkind "
1271 "FROM pg_class c, pg_namespace n "
1272 "WHERE c.relname !~ '^pg_' "
1273 "AND c.relkind = 'S' "
1274 "AND c.relnamespace = n.oid "
1275 "AND n.nspname NOT IN ('information_schema', 'pg_toast', 'pg_temp_1', 'pg_catalog')");
1277 std::auto_ptr<te::da::DataSet> seqNamesInfo = query(sql);
1279 while(seqNamesInfo->moveNext())
1281 std::string seqName(seqNamesInfo->getString(2));
1286 std::string sql(
"SELECT * FROM ");
1289 std::auto_ptr<te::da::DataSet> result(query(sql));
1291 if(result->moveNext())
1293 unsigned int seqId = getDataSetId(seqName);
1298 if(result->getBool(8))
1310 return std::auto_ptr<te::da::Sequence>(seq);
1315 std::vector<std::string> seqNames;
1317 std::string sql(
"SELECT c.oid, n.nspname, c.relname, c.relkind "
1318 "FROM pg_class c, pg_namespace n "
1319 "WHERE c.relname !~ '^pg_' "
1320 "AND c.relkind = 'S' "
1321 "AND c.relnamespace = n.oid "
1322 "AND n.nspname NOT IN ('information_schema', 'pg_toast', 'pg_temp_1', 'pg_catalog')");
1324 std::auto_ptr<te::da::DataSet> seqNamesInfo = query(sql);
1326 while(seqNamesInfo->moveNext())
1328 std::string seqName(seqNamesInfo->getString(2));
1329 seqNames.push_back(seqName);
1337 std::vector<std::string> seqNames = getSequenceNames();
1339 if(std::find(seqNames.begin(), seqNames.end(), name) != seqNames.end())
1347 std::string seqName = sequence->
getName();
1349 std::string sql(
"CREATE SEQUENCE ");
1351 sql +=
" INCREMENT BY ";
1353 sql +=
" MINVALUE ";
1355 sql +=
" MAXVALUE ";
1357 sql +=
" START WITH ";
1369 sql +=
" OWNED BY ";
1377 unsigned int seqId = getDataSetId(seqName);
1379 sequence->
setId(seqId);
1384 std::auto_ptr<te::da::Sequence> seq = getSequence(name);
1386 std::string sql(
"DROP SEQUENCE ");
1394 std::string sql(
"SELECT ST_Extent(");
1395 sql += propertyName;
1399 PGresult* result = PQexec(m_conn->getConn(), sql.c_str());
1401 if(PQresultStatus(result) != PGRES_TUPLES_OK)
1403 std::string errmsg(
TR_PGIS(
"Could not find the envelope for the given geometry property due to the following error: "));
1404 errmsg += PQerrorMessage(m_conn->getConn());
1408 throw Exception(errmsg);
1411 const char* boxStr = PQgetvalue(result, 0, 0);
1419 return std::auto_ptr<te::gm::Envelope>(mbr);
1424 std::auto_ptr<te::dt::Property> p = getProperty(datasetName, propertyPos);
1426 std::string sql(
"SELECT ST_Extent(");
1427 sql += p->getName();
1431 PGresult* result = PQexec(m_conn->getConn(), sql.c_str());
1433 if(PQresultStatus(result) != PGRES_TUPLES_OK)
1435 std::string errmsg(
TR_PGIS(
"Could not find the envelope for the given geometry property due to the following error: "));
1436 errmsg += PQerrorMessage(m_conn->getConn());
1440 throw Exception(errmsg);
1443 const char* boxStr = PQgetvalue(result, 0, 0);
1451 return std::auto_ptr<te::gm::Envelope>(mbr);
1456 std::auto_ptr<te::da::DataSet> result = getDataSet(datasetName);
1457 return result->size();
1462 std::vector<std::string> datasetNames = getDataSetNames();
1464 if(datasetNames.empty())
1472 std::string datasetName = getFullName(name);
1474 std::vector<std::string> datasetNames = getDataSetNames();
1476 if(std::find(datasetNames.begin(), datasetNames.end(), datasetName) != datasetNames.end())
1484 std::string datasetName = dt->
getName();
1485 datasetName = getFullName(datasetName);
1487 std::string sql =
"CREATE TABLE ";
1494 unsigned int dtid = getDataSetId(datasetName);
1499 std::size_t nCols = dt->
size();
1500 for(std::size_t i = 0; i < nCols; ++i)
1509 for(std::size_t i = 0; i < nUKs; ++i)
1514 for(std::size_t i = 0; i < nIdxs; ++i)
1515 addIndex(datasetName, dt->
getIndex(i), options);
1519 for(std::size_t i = 0; i < nFKs; ++i)
1525 for(std::size_t i = 0; i < nCCs; ++i)
1529 std::vector<std::string> indexNames = getIndexNames(datasetName);
1534 for(std::size_t i = 0; i < indexNames.size(); ++i)
1536 if(pk->
getName() == indexNames[i])
1547 for(std::size_t i = 0; i < numUKs; ++i)
1551 for(std::size_t j = 0; j < indexNames.size(); ++j)
1553 if(uk->
getName() == indexNames[j])
1563 const std::string& ,
1564 const std::map<std::string, std::string>& )
1566 throw Exception(
TR_PGIS(
"Not implemented yet!"));
1571 std::auto_ptr<te::da::DataSetType> dt = getDataSetType(name);
1577 std::string tSchema, tName;
1578 SplitTableName(dt->getName(), &(m_ds->getCurrentSchema()), tSchema, tName);
1580 sql =
"SELECT DropGeometryTable('";
1588 sql +=
"DROP TABLE ";
1589 sql += dt->getName();
1597 std::string newTableName, newTableSchema, oldTableName, oldTableSchema;
1599 std::string sql(
"ALTER TABLE ");
1601 sql +=
" RENAME TO ";
1603 SplitTableName(newName, &(m_ds->getCurrentSchema()), newTableSchema, newTableName);
1605 sql += newTableName;
1610 std::auto_ptr<te::da::DataSetType> dt = getDataSetType(name);
1614 SplitTableName(name, &(m_ds->getCurrentSchema()), oldTableSchema, oldTableName);
1616 sql =
"UPDATE geometry_columns SET f_table_name = '";
1617 sql += newTableName;
1618 sql +=
"' WHERE f_table_name = '";
1619 sql += oldTableName;
1620 sql +=
"' AND f_table_schema ='";
1621 sql += oldTableSchema;
1630 const std::map<std::string, std::string>& options,
1634 limit = std::string::npos;
1637 std::string sql =
"INSERT INTO ";
1643 std::auto_ptr<PreparedQuery> pq(
new PreparedQuery(
this,
"a" + boost::lexical_cast<std::string>((intptr_t)(
this))));
1649 std::size_t nProcessedRows = 0;
1651 pq->prepare(sql, paramTypes);
1653 while(d->
moveNext() && (nProcessedRows != limit))
1667 throw Exception(
TR_PGIS(
"Not implemented yet!"));
1747 const std::vector<std::size_t>& ,
1749 const std::map<std::string, std::string>& ,
1752 throw Exception(
TR_PGIS(
"Not implemented yet!"));
1805 throw Exception(
TR_PGIS(
"Not implemented yet!"));
1810 std::string sql(
"SELECT oid FROM pg_type WHERE typname = 'geometry'");
1812 std::auto_ptr<te::da::DataSet> result(query(sql));
1814 unsigned int id = 0;
1816 if(result->moveNext())
1817 id = result->getInt32(0);
1824 std::string sql(
"SELECT oid FROM pg_type WHERE typname = 'raster'");
1826 std::auto_ptr<te::da::DataSet> result(query(sql));
1828 unsigned int id = 0;
1830 if(result->moveNext())
1831 id = result->getInt32(0);
1838 std::string sql(
"SELECT current_schema()");
1840 std::auto_ptr<te::da::DataSet> result(query(sql));
1842 if(!result->moveNext())
1843 Exception(
TR_PGIS(
"Could not get information about PostgreSQL database backend!"));
1845 currentSchema = result->getString(0);
1850 std::string sql =
"SELECT g.coord_dimension, g.srid, g.type "
1851 "FROM geometry_columns g "
1852 "WHERE g.f_table_name = '";
1854 std::string tname, sname;
1856 SplitTableName(datasetName, &(m_ds->getCurrentSchema()), sname, tname);
1859 sql +=
"' AND g.f_table_schema = '";
1861 sql +=
"' AND f_geometry_column = '";
1865 std::auto_ptr<te::da::DataSet> result(query(sql));
1867 if(result->moveNext())
1870 int srid = result->getInt32(1);
1886 std::string sql =
"SELECT * FROM raster_columns as r WHERE r.r_table_name = '";
1888 std::string tname, sname;
1890 SplitTableName(datasetName, &(m_ds->getCurrentSchema()), sname, tname);
1893 sql +=
"' AND r.r_table_schema = '";
1895 sql +=
"' AND r_raster_column = '";
1899 std::auto_ptr<te::da::DataSet> result(query(sql));
1901 if(result->moveNext())
1903 int srid = result->getInt32(
"srid");
1905 double scale_x = result->getDouble(
"scale_x");
1907 double scale_y = result->getDouble(
"scale_y");
1909 int blocksize_x = result->getInt32(
"blocksize_x");
1911 int blocksize_y = result->getInt32(
"blocksize_y");
1915 int nbands = result->getInt32(
"num_bands");
1917 std::auto_ptr<te::dt::Array> pixel_types(result->getArray(
"pixel_types"));
1919 std::auto_ptr<te::dt::Array> nodata_values(result->getArray(
"nodata_values"));
1921 std::auto_ptr<te::gm::Geometry> g(result->getGeometry(
"extent"));
1927 rp->
set(grid.release());
1929 for(
int i = 0; i != nbands; ++i)
1931 std::vector<std::size_t> pos(1, i);
1933 std::string st = pixel_types->getData(pos)->toString();
1939 else if(st ==
"8BUI")
1941 else if(st ==
"16BI")
1943 else if(st ==
"16BUI")
1945 else if(st ==
"32BI")
1947 else if(st ==
"32BUI")
1949 else if(st ==
"32BF")
1951 else if(st ==
"64BF")
1954 throw Exception(
TR_PGIS(
"Band data type not supported by PostGIS driver!"));
1958 bp->
m_blkh = blocksize_y;
1960 bp->
m_blkw = blocksize_x;
1978 std::string fullName = name;
1980 if(fullName.find(
".") == std::string::npos)
1981 fullName = m_ds->getCurrentSchema() +
"." + name;
1990 std::string tname, sname;
1992 SplitTableName(tableName, &(m_ds->getCurrentSchema()), sname, tname);
1994 std::string sql(
"SELECT pg_class.oid "
1995 "FROM pg_class, pg_namespace "
1996 "WHERE pg_class.relnamespace = pg_namespace.oid "
1997 "AND lower(pg_class.relname) = '");
2000 sql +=
"' AND lower(pg_namespace.nspname) = '";
2004 std::auto_ptr<te::da::DataSet> result(query(sql));
2006 if(result->moveNext() ==
false)
2007 throw Exception(
TR_PGIS(
"Could not find the table oid!"));
2009 unsigned int tableid = result->getInt32(0);
2016 std::string sql(
"SELECT pg_namespace.nspname, pg_class.relname "
2017 "FROM pg_class, pg_namespace "
2018 "WHERE pg_class.relnamespace = pg_namespace.oid "
2019 "AND pg_class.oid = ");
2023 std::auto_ptr<te::da::DataSet> result(query(sql));
2025 if(result->moveNext() ==
false)
2026 throw Exception(
TR_PGIS(
"Could not find the dataset name!"));
2028 std::string tname = result->getString(0);
2030 tname += result->getString(1);
2037 std::string fullDatasetName = getFullName(datasetName);
2039 unsigned int dtid = getDataSetId(fullDatasetName);
2041 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 "
2042 "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) "
2043 "WHERE a.attrelid = ");
2045 sql +=
" AND a.attisdropped = false"
2047 " ORDER BY a.attnum";
2055 throw Exception(
TR_PGIS(
"The informed property is not valid!"));
2057 std::string sql(
"SELECT attnum "
2058 "FROM pg_attribute WHERE attrelid = ");
2060 sql +=
" AND attisdropped = false "
2065 std::auto_ptr<te::da::DataSet> result(query(sql));
2067 if(result->moveNext() ==
false)
2068 throw Exception(
TR_PGIS(
"Could not find the property ID!"));
2070 unsigned int id = result->getInt32(0);
2076 unsigned int dtid = getDataSetId(datasetName);
2078 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 "
2079 "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) "
2080 "WHERE a.attrelid = ");
2082 sql +=
" AND a.attnum = ";
2084 sql +=
" AND a.attisdropped = false"
2085 " AND a.attnum > 0";
2087 std::auto_ptr<te::da::DataSet> result(query(sql));
2089 std::auto_ptr<te::dt::Property> p(0);
2091 if(result->moveNext())
2093 unsigned int attNum = result->getInt16(0);
2094 std::string attName = result->getString(1);
2095 unsigned int attType = result->getInt32(2);
2096 bool attNotNull = result->getBool(3);
2097 std::string fmt = result->getString(4);
2098 bool attHasDefault = result->getBool(5);
2099 std::string attDefValue = result->getString(6);
2100 int ndims = result->getInt32(7);
2102 p.reset(
Convert2TerraLib(attNum, attName.c_str(), attType, attNotNull, fmt.c_str(), attHasDefault,
2103 attDefValue.c_str(),ndims, m_ds->getGeomTypeId(), m_ds->getRasterTypeId()));
2106 getGeometryInfo(datasetName, static_cast<te::gm::GeometryProperty*>(p.get()));
2114 unsigned int dtid = getDataSetId(datasetName);
2116 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) "
2117 "FROM pg_constraint c, pg_namespace n "
2118 "WHERE c.connamespace = n.oid "
2119 "AND c.conrelid = ");
2124 sql +=
" AND c.contype = '";
2134 std::string datasetName = dt->
getName();
2135 unsigned int dtid = dt->
getId();
2137 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) "
2138 "FROM pg_constraint c, pg_namespace n "
2139 "WHERE c.connamespace = n.oid "
2140 "AND c.conrelid = ");
2143 std::auto_ptr<te::da::DataSet> cInfo = query(sql);
2145 while(cInfo->moveNext())
2147 char cType = cInfo->getChar(3);
2151 unsigned int pkId = cInfo->getInt32(0);
2152 std::string pkName = cInfo->getString(2);
2156 std::auto_ptr<te::dt::Array> pkCols(cInfo->getArray(8));
2157 std::size_t size = pkCols->getDimensionSize(0);
2159 std::vector<std::size_t> pos;
2161 for(std::size_t i = 0; i < size; ++i)
2172 std::vector<std::string> idxNames = getIndexNames(datasetName);
2174 for(std::size_t i = 0; i < idxNames.size(); ++i)
2176 if(pk->
getName() == idxNames[i])
2187 else if (cType ==
'f')
2190 unsigned int fkId = cInfo->getInt32(0);
2191 unsigned int refDatasetId = cInfo->getInt32(4);
2192 char onUpdate = cInfo->getChar(5);
2193 char onDeletion = cInfo->getChar(6);
2195 std::auto_ptr<te::dt::Array> fkCols(cInfo->getArray(8));
2196 std::auto_ptr<te::dt::Array> fkRefCols(cInfo->getArray(9));
2198 assert(fkCols->getDimension() == 1);
2199 assert(fkCols->getDimension() == fkRefCols->getDimension());
2200 assert(fkCols->getDimensionSize(0) == fkRefCols->getDimensionSize(0));
2202 std::string refName = getDataSetName(refDatasetId);
2204 std::auto_ptr<te::da::DataSetType> refDatasetType = getDataSetType(refName);
2206 std::string fkName = cInfo->getString(2);
2213 std::size_t size = fkCols->getDimensionSize(0);
2215 std::vector<std::size_t> pos;
2218 for(std::size_t i = 0; i < size; ++i)
2223 fk->
addRefProperty(refDatasetType->getPropertyById(static_cast<te::dt::Int16*>(fkRefCol)->getValue()));
2226 fk->
add(getProperty(static_cast<te::dt::Int16*>(fkCol)->getValue(), datasetName).release());
2233 else if(cType ==
'u')
2236 unsigned int ukId = cInfo->getInt32(0);
2237 std::string ukName = cInfo->getString(2);
2239 std::auto_ptr<te::dt::Array> ukCols(cInfo->getArray(8));
2243 std::size_t size = ukCols->getDimensionSize(0);
2245 std::vector<std::size_t> pos;
2248 for(std::size_t i = 0; i < size; ++i)
2254 std::auto_ptr<te::dt::Property> p = getProperty(static_cast<te::dt::Int16*>(ukCol)->getValue(), datasetName);
2255 uk->add(p.release());
2259 std::vector<std::string> idxNames = getIndexNames(datasetName);
2261 for(std::size_t i = 0; i < idxNames.size(); ++i)
2263 if(uk->getName() == idxNames[i])
2265 uk->setAssociatedIndex(getIndex(datasetName, idxNames[i]).
get());
2274 else if(cType ==
'c')
2277 std::string ccName = cInfo->getString(2);
2279 unsigned int ccId = cInfo->getInt32(0);
2294 std::string datasetName = dt->
getName();
2295 unsigned int dtid = dt->
getId();
2297 std::string sql(
"SELECT idx_table.oid, s.nspname, idx_table.relname, pg_index.indkey, pg_am.amname, pg_index.indisunique, pg_index.indisprimary "
2298 "FROM pg_index, pg_class idx_table, pg_am, pg_namespace s "
2299 "WHERE s.oid = idx_table.relnamespace "
2300 "AND pg_index.indexrelid = idx_table.oid "
2301 "AND idx_table.relam = pg_am.oid "
2302 "AND pg_index.indrelid = ");
2305 std::auto_ptr<te::da::DataSet> idxInfo = query(sql);
2307 while(idxInfo->moveNext())
2309 unsigned int idxId = idxInfo->getInt32(0);
2310 std::string idxName = idxInfo->getString(2);
2312 std::auto_ptr<te::dt::Array> idxCols(idxInfo->getArray(3));
2314 std::string idxType = idxInfo->getString(4);
2315 bool isUK = idxInfo->getBool(5);
2316 bool isPK = idxInfo->getBool(6);
2320 std::size_t size = idxCols->getDimensionSize(0);
2322 std::vector<std::size_t> pos;
2325 for(std::size_t i = 0; i < size; ++i)
2334 idxName = idxInfo->getString(2);
2351 std::vector<te::da::Sequence*> seqs;
2354 std::vector<std::string> seqNames;
2356 std::string sql(
"SELECT c.oid, n.nspname, c.relname, c.relkind "
2357 "FROM pg_class c, pg_namespace n "
2358 "WHERE c.relname !~ '^pg_' "
2359 "AND c.relkind = 'S' "
2360 "AND c.relnamespace = n.oid "
2361 "AND n.nspname NOT IN ('information_schema', 'pg_toast', 'pg_temp_1', 'pg_catalog')");
2363 std::auto_ptr<te::da::DataSet> seqNamesInfo = query(sql);
2365 while(seqNamesInfo->moveNext())
2367 std::string seqName(seqNamesInfo->getString(2));
2368 seqNames.push_back(seqName);
2371 for(std::size_t i = 0; i < seqNames.size(); ++i)
2373 std::string seqName = seqNames[i];
2375 std::string sql(
"SELECT * FROM ");
2378 std::auto_ptr<te::da::DataSet> result(query(sql));
2380 if(result->moveNext() ==
false)
2381 throw Exception((boost::format(
TR_PGIS(
"There is no information about the sequence \"%1%\"!")) % seqName).str());
2383 unsigned int seqId = getDataSetId(seqName);
2388 if(result->getBool(8))
2398 seqs.push_back(seq);
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::PrimaryKey > getPrimaryKey(const std::string &datasetName)
It retrieves the primary key of the dataset.
void setGeometryType(GeomType t)
It sets the geometry subtype.
Property * getPropertyById(unsigned int id) const
It searches for a property with the given ID.
int m_blkh
Block height (pixels).
std::string Convert2LCase(const std::string &value)
It converts a string to lower case.
A class that implements a prepared query for PostgreSQL data access driver.
It describes an index associated to a DataSetType.
Index * getIndex(std::size_t i) const
It returns the i-th index associated to the dataset type.
unsigned int getRasterTypeId()
It will check in the database catalog the number that identifies the PostGIS Raster type...
void addUniqueKey(const std::string &datasetName, te::da::UniqueKey *uk)
It adds a unique key constraint to the dataset.
void dropSequence(const std::string &name)
It removes the sequence from the data source.
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
Transactor(DataSource *ds, Connection *conn)
Constructor.
void addForeignKey(const std::string &datasetName, te::da::ForeignKey *fk)
It adds a foreign key constraint to a dataset.
bool isCycled() const
It returns true if the sequence can wrap, otherwise it returns false.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
An static class with global definitions.
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema.
void getGeometryInfo(const std::string &datasetName, te::gm::GeometryProperty *gp)
It loads information about a given geometry column.
std::string GetSpatialRelation(te::gm::SpatialRelation rel)
It converts the spatial relationship to PostGIS dialect.
Property * getProperty(std::size_t i) const
It returns the i-th property.
std::size_t size() const
It returns the number of properties of the CompositeProperty.
void setMinValue(boost::int64_t value)
It sets the minimum value that the sequence can generate.
void Convert2PostGIS(const te::gm::Envelope *e, int srid, std::string &output)
It converts the envelope into a PostGIS BOX3D.
void addCheckConstraint(const std::string &datasetName, te::da::CheckConstraint *cc)
It adds a check constraint to the dataset.
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.
bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source.
std::string GetBoxSpatialRelation(te::gm::SpatialRelation rel)
It converts the spatial relationship to PostGIS dialect.
A Select models a query to be used when retrieving data from a DataSource.
bool indexExists(const std::string &datasetName, const std::string &name)
It checks if an index with the given name exists in the dataset.
int getSRID() const
It returns the spatial reference system identifier associated to this property.
void setExpression(const std::string &e)
It sets the check constraint expression.
void setAsNoCycle()
It sets the sequence as not cycled (it can't wrap).
void setMaxValue(boost::int64_t value)
It sets the maximum value that the sequence can generate.
An utility class to coordinate transactions.
A class that implements a connection pool for PostGIS.
void addPrimaryKey(const std::string &datasetName, te::da::PrimaryKey *pk)
It adds a primary key constraint to the dataset schema.
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...
void setAsCycle()
It sets the sequence as cycled (it can wrap).
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.
void setOnUpdateAction(FKActionType a)
It sets the action to be performed when a referenced element value in the referenced DataSetType is b...
std::string getDataSetName(unsigned int id)
It looks for a dataset name with the given id in the PostgreSQL.
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.
ForeignKey * getForeignKey(std::size_t i) const
It returns the i-th foreign key associated to the dataset type.
A template for atomic data types (integers, floats, strings and others).
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
It describes a primary key (pk) constraint.
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
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.
const std::string & getName() const
It returns the property name.
void add(Constraint *c)
It adds a new constraint.
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
boost::int64_t getIncrement() const
It returns the increment value.
void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema.
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.
It describes a sequence (a number generator).
UniqueKey * getUniqueKey(std::size_t i) const
It returns the i-th unique key.
boost::int64_t getStartValue() const
It returns the initial value of the sequence.
void commit()
It commits the transaction.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the index.
void setId(unsigned int id)
It sets the property identifier.
void setIncrement(boost::int64_t n)
It sets the increment value.
void commit()
It commits the transaction.
SpatialRelation
Spatial relations between geometric objects.
void dropCheckConstraint(const std::string &datasetName, const std::string &name)
It removes the check constraint from the dataset.
It models a foreign key constraint for a DataSetType.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
An exception class for the PostGIS driver.
boost::int64_t getMinValue() const
It returns the minimum value that the sequence can generate.
FKActionType getOnDeleteAction() const
It returns the action performed when a referenced element value in the referenced DataSetType is bein...
AccessPolicy
Supported data access policies (can be used as bitfield).
virtual void setName(const std::string &name)
It sets the constraint name.
void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the dataset schema.
#define TR_PGIS(message)
It marks a string in order to get translated. This is a special mark used in the DataAccess module of...
std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
void getIndexes(te::da::DataSetType *dt)
It gets all the indexes of the given dataset and adds them to the dummy schema.
bool isDataSetNameValid(const std::string &datasetName)
It returns true if the given string is a valid dataset name.
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
void execute(const te::da::Query &command)
It executes the specified command using a generic query representation.
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.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
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...
Connection * getConnection() const
It returns the underlying connection.
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
A rectified grid is the spatial support for raster data.
bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
std::size_t getNumberOfForeignKeys() const
It returns the number of foreign keys defined for the dataset type.
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.
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.
int m_blkw
Block width (pixels).
A class that implements a prepared query for PostgreSQL data access driver.
std::vector< std::string > getUniqueKeyNames(const std::string &datasetName)
It gets the unique key names of the given dataset.
Utility functions for the data access module.
bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset.
A Query is independent from the data source language/dialect.
std::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset.
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids=0)
It removes all the informed items from the dataset.
A visitor for building an SQL statement using PostGIS dialect.
const std::string & GetGeometryName(te::gm::GeomType t)
It returns the geometry names as usual for PostGIS.
void renameProperty(const std::string &datasetName, const std::string &propertyName, const std::string &newPropertyName)
It renames a property of the given dataset.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
std::string getFullName(const std::string &name)
It gets the full name of the given name including the schema name.
std::auto_ptr< te::da::Sequence > getSequence(const std::string &name)
It gets the sequence with the given name in the data source.
unsigned int getGeomTypeId()
It will check in the database catalog the number that identifies the PostGIS Geometry type...
Property * getParent() const
It returns the parent of this property, or NULL, if it doesn't have one.
void setCachedValues(boost::int64_t value)
It sets how many sequence numbers are to be preallocated.
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::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
void begin()
It starts a new transaction.
te::da::IndexType GetIndexType(const char *t)
It converts the PostgreSQL index string to a TerraLib index type.
const std::string & getName() const
It returns the index name.
std::vector< std::string > getCheckConstraintNames(const std::string &datasetName)
It gets the check constraint names of the given dataset.
TEDATAACCESSEXPORT std::vector< int > GetPropertyDataTypes(const te::da::DataSet *dataset)
A class that implements a connection to a PostgreSQL database.
It describes a unique key (uk) constraint.
std::string GetSQLBindValues(std::size_t nproperties)
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
void getPropertyId(te::dt::Property *p)
It sets the property id from the PostgreSQL system.
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.
void set(te::rst::Grid *grid)
Sets the definition of the raster grid support.
void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset.
std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset.
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
std::size_t getNumberOfIndexes() const
It returns the number of indexes defined for the dataset type.
void setAssociatedIndex(Index *idx)
It sets the associated index.
virtual const std::string & getName() const
It returns the constraint name.
bool isPropertyNameValid(const std::string &propertyName)
It checks if the given property name is valid.
void add(te::dt::Property *p)
It adds the property to the list of properties of the index.
std::string Convert2String(boost::int16_t value)
It converts a short integer value to a string.
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...
boost::int64_t getCachedValues() const
It returns how many sequence numbers are preallocated.
A class that implements a connection to a PostgreSQL database.
TraverseType
A dataset can be traversed in two ways:
struct pg_result PGresult
FKActionType getOnUpdateAction() const
It returns the action performed when a referenced element value in the referenced DataSetType is bein...
IndexType getIndexType() const
It gets the index type.
const std::string & getExpression() const
It returns the check constraint expression.
A Transactor can be viewed as a connection to the data source for reading/writing things into it...
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::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
void cancel()
It requests that the data source stop the processing of the current command.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the foreign key constraint.
A base class for values that can be retrieved from the data access module.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
unsigned int getDataSetId(const std::string &datasetName)
It looks for the dataset id in the PostgreSQL system.
A raster band description.
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
void add(te::rst::BandProperty *b)
It adds a new band information to the property.
void addSequence(te::da::Sequence *sequence)
It creates a new sequence in the data source.
A class that models the description of a dataset.
void add(te::dt::Property *p)
It adds a property to the foreign key constraint.
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits<double>::max().
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.
Implementation of a dataset for the PostGIS driver.
CheckConstraint * getCheckConstraint(std::size_t i) const
It returns the i-th check-constraint associated to the dataset type.
virtual void setId(unsigned int id)
It sets the constraint identifier.
std::vector< te::da::Sequence * > getSequences()
It gets information about all the sequences in the datasource.
bool SetColumnDef(std::string &s, const std::string &tname, const te::dt::SimpleProperty *p, bool justDataType=false)
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.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
It models a property definition.
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
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 getRasterInfo(const std::string &datasetName, te::rst::RasterProperty *rp)
It loads information about a given raster column.
boost::int64_t getMaxValue() const
It returns the maximum value that the sequence can generate.
bool isInTransaction() const
It returns true if a transaction is in progress, otherwise, it returns false.
int getType() const
It returns the property data type.
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.
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
const std::string & getName() const
It returns the sequence name.
void SplitTableName(const std::string &fullName, const std::string *defaultSchema, std::string &schemaName, std::string &tableName)
void setReferencedDataSetType(DataSetType *refDt)
It sets the referenced DataSetType of this foreign key constraint.
TEDATAACCESSEXPORT std::string GetSQLValueNames(const DataSetType *dt)
void addRefProperty(te::dt::Property *p)
It adds a reference property (on the referenced DataSetType) of this foreign key constraint.
void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset.
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.
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::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source.
const std::vector< te::dt::Property * > & getReferencedProperties() const
It returns the referenced properties (on the referenced DataSetType) of this foreign key constraint...
void setTitle(const std::string &title)
It sets a human descriptive title for the DataSetType.
PrimaryKey * getPrimaryKey() const
It returns the primary key associated to the dataset type.
unsigned int getId() const
It returns the property identifier.
void setOnDeleteAction(FKActionType a)
It sets the action to be performed when a referenced element value in the referenced DataSetType is b...
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
A class that describes a check constraint.
std::auto_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
An Envelope defines a 2D rectangular region.
A visitor for building an SQL statement using PostGIS dialect.
te::dt::Property * getOwner() const
It returns the property type associated to the sequence.
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
void setId(unsigned int id)
It sets the sequence identifier.
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
A dataset is the unit of information manipulated by the data access module of TerraLib.
DataSetType * getReferencedDataSetType() const
It returns the referenced DataSetType of this foreign key constraint.
te::gm::Envelope * GetEnvelope(const char *str)
It converts the pgType to a valid TerraLib data type.
virtual Property * clone() const =0
It returns a clone of the object.
te::da::FKActionType GetAction(char a)
It converts the PostgreSQL foreign key modifier to a TerraLib data type.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that form the unique key.
bool hasDataSets()
It checks if the data source has any dataset.
std::size_t getNumberOfUniqueKeys() const
It returns the number of unique keys defined for the dataset type.
A dataset is the unit of information manipulated by the data access module of TerraLib.
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
void getDatabaseInfo(std::string ¤tSchema)
It retrieves some information about the database such as the default schema used when no one is provi...
~Transactor()
The destructor will automatically release the connection to the pool.
std::auto_ptr< te::da::DataSet > getPropertiesInfo(const std::string &datasetName)
It gets the information about the given dataset.
Implementation of the data source for the PostGIS driver.
std::size_t getNumberOfCheckConstraints() const
It returns the number of check-constraints defined over the dataset type.
void setAssociatedIndex(Index *idx)
It sets the associated index.