AddingPrimaryKey.cpp
Go to the documentation of this file.
1 // Examples
2 #include "DataAccessExamples.h"
3 
4 te::da::PrimaryKey* AddPrimaryKey(const std::string& datasetname,
6 {
7  //te::da::DataSetType* datasettype = (transactor->getDataSetType(datasetname)).get(); //"public.br_munic_2001");
8  //te::dt::Property* gid_pk = datasettype->getProperty("gid");
9 
10  std::unique_ptr<te::dt::Property> gid_pk1 = transactor->getProperty(datasetname,"gid");
11  //Create the name of primary key and add the attribute
12  te::da::PrimaryKey* pk = new te::da::PrimaryKey("attribute6_int_pk");
13  pk->add(gid_pk1.get());
14 
15  transactor->addPrimaryKey(datasetname,pk);
16 
17  te::da::PrimaryKey* pk1 = (transactor->getPrimaryKey(datasetname)).get();
18 
19  return pk1;
20 }
21 
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
Definition: PrimaryKey.h:123
virtual std::unique_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName)=0
It retrieves the primary key of the dataset.
virtual void addPrimaryKey(const std::string &datasetName, PrimaryKey *pk)=0
It adds a primary key constraint to the dataset schema.
virtual std::unique_ptr< te::dt::Property > getProperty(const std::string &datasetName, const std::string &name)=0
It retrieves the property with the given name from the dataset.
te::da::PrimaryKey * AddPrimaryKey(const std::string &datasetname, te::da::DataSourceTransactor *transactor)
Examples on how to access/manipulate DataSources in TerraLib.
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52