All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Transactor.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/ado/Transactor.cpp
22 
23  \brief DataSourceTransactor class implementation for Microsoft Access driver.
24 */
25 
26 // TerraLib
27 #include "../common/Translator.h"
28 #include "../dataaccess/dataset/CheckConstraint.h"
29 #include "../dataaccess/dataset/DataSet.h"
30 #include "../dataaccess/dataset/ForeignKey.h"
31 #include "../dataaccess/dataset/Index.h"
32 #include "../dataaccess/dataset/ObjectIdSet.h"
33 #include "../dataaccess/dataset/PrimaryKey.h"
34 #include "../dataaccess/dataset/Sequence.h"
35 #include "../dataaccess/dataset/UniqueKey.h"
36 #include "../dataaccess/datasource/DataSourceCatalog.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/Date.h"
43 #include "../datatype/DateTimeProperty.h"
44 #include "../datatype/Property.h"
45 #include "../datatype/SimpleData.h"
46 #include "../datatype/StringProperty.h"
47 #include "../geometry/Envelope.h"
48 #include "../geometry/GeometryProperty.h"
49 #include "../geometry/Utils.h"
50 #include "../geometry/Geometry.h"
51 #include "../memory/DataSet.h"
52 #include "Connection.h"
53 #include "DataSet.h"
54 #include "DataSource.h"
55 #include "Exception.h"
56 #include "Globals.h"
57 #include "SQLVisitor.h"
58 #include "Transactor.h"
59 #include "Utils.h"
60 
61 // STL
62 #include <cassert>
63 #include <memory>
64 #include <iostream>
65 
66 // Boost
67 #include <boost/format.hpp>
68 #include <boost/lexical_cast.hpp>
69 
70 // ADO
71 #import "msado15.dll" \
72  no_namespace rename("EOF", "EndOfFile")
73 #import "msadox.dll"
74 
75 inline void TESTHR(HRESULT hr)
76 {
77  if(FAILED(hr))
78  _com_issue_error(hr);
79 }
80 
82  : m_ds(ds),
83  m_conn(0),
84  m_isInTransaction(false)
85 {
86  std::string connInfoAux = MakeConnectionStr(ds->getConnectionInfo());
87 
88  m_conn = new te::ado::Connection(connInfoAux);
89 }
90 
92 {
93  delete m_conn;
94 }
95 
97 {
98  return m_ds;
99 }
100 
102 {
103  try
104  {
105  m_conn->getConn()->BeginTrans();
106  m_isInTransaction = true;
107  }
108  catch(_com_error& e)
109  {
110  throw Exception(TR_ADO(e.Description()));
111  }
112 }
113 
115 {
116  try
117  {
118  m_conn->getConn()->CommitTrans();
119  m_isInTransaction = false;
120  }
121  catch(_com_error& e)
122  {
123  throw Exception(TR_ADO(e.Description()));
124  }
125 }
126 
128 {
129  try
130  {
131  m_conn->getConn()->RollbackTrans();
132  m_isInTransaction = false;
133  }
134  catch(_com_error& e)
135  {
136  throw Exception(TR_ADO(e.Description()));
137  }
138 }
139 
141 {
142  return m_isInTransaction;
143 }
144 
145 std::auto_ptr<te::da::DataSet> te::ado::Transactor::getDataSet(const std::string& name,
146  te::common::TraverseType travType,
147  bool connected,
148  const te::common::AccessPolicy accessPolicy)
149 {
150  std::string sql("SELECT * FROM ");
151  sql += name;
152 
153  return query(sql, travType, connected, accessPolicy);
154 }
155 
156 std::auto_ptr<te::da::DataSet> te::ado::Transactor::getDataSet(const std::string& name,
157  const std::string& propertyName,
158  const te::gm::Envelope* e,
160  te::common::TraverseType travType,
161  bool connected,
162  const te::common::AccessPolicy accessPolicy)
163 {
164  if(e == 0)
165  throw Exception(TR_ADO("The envelope is missing!"));
166 
167  std::string lowerX = "lower_x";
168  std::string upperX = "upper_x";
169  std::string lowerY = "lower_y";
170  std::string upperY = "upper_y";
171 
172  std::string q("SELECT * FROM " + name + " WHERE ");
173 
174  q += "NOT("+ lowerX +" > " + boost::lexical_cast<std::string>(e->m_urx) + " OR ";
175  q += upperX +" < " + boost::lexical_cast<std::string>(e->m_llx) + " OR ";
176  q += lowerY +" > " + boost::lexical_cast<std::string>(e->m_ury) + " OR ";
177  q += upperY +" < " + boost::lexical_cast<std::string>(e->m_lly) + ")";
178 
179  return query(q, travType, connected, accessPolicy);
180 }
181 
182 std::auto_ptr<te::da::DataSet> te::ado::Transactor::getDataSet(const std::string& /*name*/,
183  const std::string& /*propertyName*/,
184  const te::gm::Geometry* /*g*/,
186  te::common::TraverseType /*travType*/,
187  bool /*connected*/,
188  const te::common::AccessPolicy /*accessPolicy*/)
189 {
190  throw Exception(TR_ADO("Method getDataSet by geometry filter: not implemented yet!"));
191 }
192 
193 std::auto_ptr<te::da::DataSet> te::ado::Transactor::getDataSet(const std::string& /*name*/,
194  const ObjectIdSet* /*oids*/,
195  te::common::TraverseType /*travType*/,
196  bool /*connected*/,
197  const te::common::AccessPolicy /*accessPolicy*/)
198 {
199  throw Exception(TR_ADO("Method getDataSet by oids: not implemented yet!"));
200 }
201 
202 std::auto_ptr<te::da::DataSet> te::ado::Transactor::query(const te::da::Select& q,
203  te::common::TraverseType travType,
204  bool connected,
205  const te::common::AccessPolicy accessPolicy)
206 {
207  std::string sql;
208 
209  SQLVisitor visitor(*(m_ds->getDialect()), sql, m_conn->getConn());
210 
211  q.accept(visitor);
212 
213  return query(sql, travType);
214 }
215 
216 std::auto_ptr<te::da::DataSet> te::ado::Transactor::query(const std::string& query,
217  te::common::TraverseType travType,
218  bool connected,
219  const te::common::AccessPolicy accessPolicy)
220 {
221  _RecordsetPtr result = m_conn->query(query, connected);
222 
223  long i = result->GetRecordCount();
224 
225  std::auto_ptr<te::da::DataSet> dset(new DataSet(this, result));
226 
227  if(connected)
228  {
229  return dset;
230  }
231  else
232  {
233  std::auto_ptr<te::da::DataSet> mdset(new te::mem::DataSet(*dset));
234 
235  return mdset;
236  }
237 }
238 
240 {
241  std::string sql;
242 
243  SQLVisitor visitor(*(m_ds->getDialect()), sql, m_conn->getConn());
244 
245  command.accept(visitor);
246 
247  execute(sql);
248 }
249 
250 void te::ado::Transactor::execute(const std::string& command)
251 {
252  m_conn->execute(command);
253 }
254 
255 std::auto_ptr<te::da::PreparedQuery> te::ado::Transactor::getPrepared(const std::string& qName)
256 {
257  throw Exception(TR_ADO("Method getPrepared: not implemented yet!"));
258 }
259 
260 std::auto_ptr<te::da::BatchExecutor> te::ado::Transactor::getBatchExecutor()
261 {
262  throw Exception(TR_ADO("Method getBatchExecutor: not implemented yet!"));
263 }
264 
266 {
267 }
268 
270 {
271  throw Exception(TR_ADO("Method getLastGeneratedId: not implemented yet!"));
272 }
273 
274 std::string te::ado::Transactor::escape(const std::string& value)
275 {
276  return value;
277 }
278 
279 bool te::ado::Transactor::isDataSetNameValid(const std::string& /*datasetName*/)
280 {
281  return true;
282 }
283 
284 bool te::ado::Transactor::isPropertyNameValid(const std::string& /*propertyName*/)
285 {
286  return true;
287 }
288 
289 std::vector<std::string> te::ado::Transactor::getDataSetNames()
290 {
291  std::vector<std::string> datasets;
292 
293  ADOX::_CatalogPtr pCatalog = 0;
294 
295  TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
296 
297  try
298  {
299  pCatalog->PutActiveConnection(variant_t((IDispatch *)m_conn->getConn()));
300 
301  ADOX::TablesPtr tables = pCatalog->GetTables();
302 
303  for(long i = 0; i < tables->GetCount(); ++i)
304  {
305  ADOX::_TablePtr table = tables->GetItem(i);
306  std::string tableName = table->GetName();
307 
308  std::string tabletype = table->GetType();
309 
310  if(table->GetType() == _bstr_t("ACCESS TABLE") ||
311  table->GetType() == _bstr_t("LINK") ||
312  table->GetType() == _bstr_t("PASS-THROUGH") ||
313  table->GetType() == _bstr_t("SYSTEM TABLE") ||
314  table->GetType() == _bstr_t("VIEW") ||
315  tableName == "geometry_columns")
316  continue;
317 
318  datasets.push_back(std::string(table->GetName()));
319  }
320  }
321  catch(_com_error &e)
322  {
323  throw Exception(TR_ADO(e.ErrorMessage()));
324  }
325 
326  return datasets;
327 }
328 
330 {
331  return getDataSetNames().size();
332 }
333 
334 std::auto_ptr<te::da::DataSetType> te::ado::Transactor::getDataSetType(const std::string& name)
335 {
336  std::auto_ptr<te::da::DataSetType> dt(new te::da::DataSetType(name));
337 
338  dt->setTitle(name);
339 
340  getProperties(dt.get());
341 
342  getPrimaryKey(dt.get());
343 
344  getUniqueKeys(dt.get());
345 
346  getIndexes(dt.get());
347 
348  getCheckConstraints(dt.get());
349 
350  return dt;
351 }
352 
353 boost::ptr_vector<te::dt::Property> te::ado::Transactor::getProperties(const std::string& datasetName)
354 {
355  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
356 
357  std::vector<te::dt::Property*> dtProperties = dt->getProperties();
358 
359  boost::ptr_vector<te::dt::Property> properties;
360 
361  for(std::size_t i = 0; i < dtProperties.size(); ++i)
362  properties.push_back(dtProperties[i]->clone());
363 
364  return properties;
365 }
366 
367 std::auto_ptr<te::dt::Property> te::ado::Transactor::getProperty(const std::string& datasetName, const std::string& name)
368 {
369  if(!propertyExists(datasetName, name))
370  throw Exception((boost::format(TR_ADO("The dataset \"%1%\" has no property with this name \"%2%\"!")) % datasetName % name).str());
371 
372  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
373 
374  return std::auto_ptr<te::dt::Property>(dt->getProperty(name)->clone());
375 }
376 
377 std::auto_ptr<te::dt::Property> te::ado::Transactor::getProperty(const std::string& datasetName, std::size_t propertyPos)
378 {
379  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
380 
381  assert(propertyPos < dt->size());
382 
383  return std::auto_ptr<te::dt::Property>(dt->getProperty(propertyPos)->clone());
384 }
385 
386 std::vector<std::string> te::ado::Transactor::getPropertyNames(const std::string& datasetName)
387 {
388  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
389 
390  std::vector<std::string> pNames;
391 
392  std::size_t numProperties = dt->size();
393 
394  for(std::size_t i = 0; i < numProperties; ++i)
395  pNames.push_back(dt->getProperty(i)->getName());
396 
397  return pNames;
398 }
399 
400 std::size_t te::ado::Transactor::getNumberOfProperties(const std::string& datasetName)
401 {
402  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
403 
404  return dt->size();
405 }
406 
407 bool te::ado::Transactor::propertyExists(const std::string& datasetName, const std::string& name)
408 {
409  std::vector<std::string> datasets;
410 
411  ADOX::_CatalogPtr pCatalog = 0;
412 
413  TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
414 
415  try
416  {
417  pCatalog->PutActiveConnection(variant_t((IDispatch *)m_conn->getConn()));
418 
419  ADOX::TablesPtr tables = pCatalog->GetTables();
420 
421  ADOX::_TablePtr table;
422 
423  for(long i = 0; i < tables->GetCount(); ++i)
424  {
425  table = 0;
426  table = tables->GetItem(i);
427  std::string tableName = table->GetName();
428 
429  if(tableName == datasetName)
430  {
431  break;
432  }
433  }
434 
435  if(table)
436  {
437  ADOX::ColumnsPtr cols = table->GetColumns();
438 
439  for(int i = 0; i < cols->Count; ++i)
440  {
441  ADOX::_ColumnPtr col = cols->GetItem((long)i);
442 
443  if(((LPCSTR)(_bstr_t)col->GetName()) == name)
444  return true;
445  }
446  }
447 
448  return false;
449 
450  }
451  catch(_com_error &e)
452  {
453  throw Exception(TR_ADO(e.ErrorMessage()));
454  }
455 }
456 
457 void te::ado::Transactor::addProperty(const std::string& datasetName, te::dt::Property* p)
458 {
459  const std::string& propertyName = p->getName();
460 
461  if(propertyExists(datasetName, propertyName))
462  throw Exception((boost::format(TR_ADO("The dataset already \"%1%\" has a property with this name \"%2%\"!")) % datasetName % propertyName).str());
463 
464  ADOX::_CatalogPtr pCatalog = 0;
465 
466  ADOX::_TablePtr pTable = 0;
467 
468  TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
469 
470  try
471  {
472  pCatalog->PutActiveConnection(variant_t((IDispatch *)m_conn->getConn()));
473 
474  pTable = pCatalog->Tables->GetItem(datasetName.c_str());
475 
476  ADOX::_ColumnPtr newColumn = 0;
477 
478  TESTHR(newColumn.CreateInstance(__uuidof(ADOX::Column)));
479 
480  newColumn->PutName(propertyName.c_str());
481 
482  newColumn->PutType(te::ado::Convert2Ado(p->getType()));
483 
484  ADOX::DataTypeEnum ado_type = te::ado::Convert2Ado(p->getType());
485 
486  switch(p->getType())
487  {
488  case te::dt::CHAR_TYPE:
489  case te::dt::UCHAR_TYPE:
490  case te::dt::INT16_TYPE:
491  case te::dt::INT32_TYPE:
492  case te::dt::INT64_TYPE:
493  case te::dt::FLOAT_TYPE:
494  case te::dt::DOUBLE_TYPE:
497  case te::dt::ARRAY_TYPE:
500  {
501  const te::dt::SimpleProperty* simple = static_cast<const te::dt::SimpleProperty*>(p);
502 
503  if(!simple->isRequired())
504  newColumn->PutAttributes(ADOX::adColNullable);
505 
506  pTable->Columns->Append(_variant_t ((IDispatch*)newColumn), ado_type, 0);
507 
508  break;
509  }
510 
511  case te::dt::STRING_TYPE:
512  {
513  const te::dt::StringProperty* sp = static_cast<const te::dt::StringProperty*>(p);
514 
515  long ssize = 0;
516 
517  if(sp->size() != 0)
518  ssize = sp->size();
519 
520  newColumn->DefinedSize = ssize;
521 
522  if(!sp->isRequired())
523  newColumn->PutAttributes(ADOX::adColNullable);
524 
525  pTable->Columns->Append(_variant_t ((IDispatch*)newColumn), ado_type, ssize);
526 
527  break;
528  }
529 
531  {
532  const te::dt::SimpleProperty* simple = static_cast<const te::dt::SimpleProperty*>(p);
533 
534  if(!simple->isRequired())
535  newColumn->PutAttributes(ADOX::adColNullable);
536 
537  pTable->Columns->Append(_variant_t ((IDispatch*)newColumn), ado_type, 0);
538 
539 // update geometry columns and metadata cache
540  std::auto_ptr<te::dt::SimpleProperty> lowerX(new te::dt::SimpleProperty("lower_x", te::dt::DOUBLE_TYPE));
541  std::auto_ptr<te::dt::SimpleProperty> lowerY(new te::dt::SimpleProperty("lower_y", te::dt::DOUBLE_TYPE));
542  std::auto_ptr<te::dt::SimpleProperty> upperX(new te::dt::SimpleProperty("upper_x", te::dt::DOUBLE_TYPE));
543  std::auto_ptr<te::dt::SimpleProperty> upperY(new te::dt::SimpleProperty("upper_y", te::dt::DOUBLE_TYPE));
544 
545  addProperty(datasetName, lowerX.get());
546  addProperty(datasetName, lowerY.get());
547  addProperty(datasetName, upperX.get());
548  addProperty(datasetName, upperY.get());
549 
550  insertIntoGeometryColumns(datasetName, static_cast<te::gm::GeometryProperty*>(p));
551 
552  break;
553  }
554 
555  default:
556  throw te::ado::Exception(TR_ADO("The informed type could not be mapped to ADO type system!"));
557  break;
558  }
559  }
560  catch(_com_error& e)
561  {
562  throw Exception(TR_ADO(e.Description()));
563  }
564 }
565 
566 void te::ado::Transactor::dropProperty(const std::string& datasetName, const std::string& name)
567 {
568  if(!propertyExists(datasetName, name))
569  throw Exception((boost::format(TR_ADO("The dataset \"%1%\" has no property with this name \"%2%\"!")) % datasetName % name).str());
570 
571  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
572 
573  te::dt::Property* p = dt->getProperty(name);
574 
575  ADOX::_CatalogPtr pCatalog = 0;
576 
577  ADOX::_TablePtr pTable = 0;
578 
579  TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
580 
581  try
582  {
583  pCatalog->PutActiveConnection(variant_t((IDispatch *)m_conn->getConn()));
584 
585  pTable = pCatalog->Tables->GetItem(p->getParent()->getName().c_str());
586 
587  TESTHR(pTable->GetColumns()->Delete(p->getName().c_str()));
588 
589  if(p->getType() == te::dt::GEOMETRY_TYPE)
590  {
591  std::string sql = "delete from geometry_columns where f_geometry_column = '";
592  sql += p->getName();
593  sql += "' AND f_table_name = '";
594  sql += datasetName;
595  sql +="'";
596 
597  m_conn->execute(sql);
598  }
599  }
600  catch(_com_error& e)
601  {
602  throw Exception(TR_ADO(e.Description()));
603  }
604 }
605 
606 void te::ado::Transactor::renameProperty(const std::string& datasetName,
607  const std::string& propertyName,
608  const std::string& newPropertyName)
609 {
610  ADOX::_CatalogPtr pCatalog = 0;
611 
612  ADOX::_TablePtr pTable = 0;
613 
614  TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
615 
616  try
617  {
618  pCatalog->PutActiveConnection(variant_t((IDispatch *)m_conn->getConn()));
619 
620  pTable = pCatalog->Tables->GetItem(datasetName.c_str());
621 
622  ADOX::_ColumnPtr col = pTable->GetColumns()->GetItem(propertyName.c_str());
623 
624  col->PutName(newPropertyName.c_str());
625 
626  pCatalog->GetTables()->Refresh();
627  }
628  catch(_com_error& e)
629  {
630  throw Exception(TR_ADO(e.Description()));
631  }
632 }
633 
634 std::auto_ptr<te::da::PrimaryKey> te::ado::Transactor::getPrimaryKey(const std::string& datasetName)
635 {
636  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
637 
638  return std::auto_ptr<te::da::PrimaryKey>(static_cast<te::da::PrimaryKey*>(dt->getPrimaryKey()->clone()));
639 }
640 
641 bool te::ado::Transactor::primaryKeyExists(const std::string& datasetName, const std::string& name)
642 {
643  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
644 
645  if(dt->getPrimaryKey()->getName() == name)
646  return true;
647 
648  return false;
649 }
650 
651 void te::ado::Transactor::addPrimaryKey(const std::string& datasetName, te::da::PrimaryKey* pk)
652 {
653  _variant_t vOptional;
654  vOptional.vt = VT_ERROR;
655  vOptional.scode = DISP_E_PARAMNOTFOUND;
656 
657  ADOX::_KeyPtr pKey = 0;
658  ADOX::_TablePtr pTable = 0;
659  ADOX::_CatalogPtr pCatalog = 0;
660 
661  TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
662  TESTHR(pKey.CreateInstance(__uuidof(ADOX::Key)));
663 
664  try
665  {
666  pCatalog->PutActiveConnection(variant_t((IDispatch *)m_conn->getConn()));
667 
668  pTable = pCatalog->Tables->GetItem(datasetName.c_str());
669 
670  pKey->Name = pTable->Name + "_pk";
671  pKey->Type = ADOX::adKeyPrimary;
672 
673  for(size_t i = 0; i < pk->getProperties().size(); i++)
674  {
675  te::dt::Property* p = pk->getProperties()[i];
676  TESTHR(pKey->Columns->Append(p->getName().c_str(), te::ado::Convert2Ado(p->getType()), 256));
677 
678  }
679 
680  TESTHR(pTable->Keys->Append(_variant_t((IDispatch *)pKey),ADOX::adKeyPrimary,vOptional,L"",L""));
681  pCatalog->Tables->Refresh();
682  }
683  catch(_com_error& e)
684  {
685  throw Exception(TR_ADO(e.Description()));
686  }
687 }
688 
689 void te::ado::Transactor::dropPrimaryKey(const std::string& datasetName)
690 {
691  ADOX::_KeyPtr pKey = 0;
692  ADOX::_TablePtr pTable = 0;
693  ADOX::_CatalogPtr pCatalog = 0;
694 
695  std::auto_ptr<te::da::PrimaryKey> pk(getPrimaryKey(datasetName));
696 
697  try
698  {
699  pCatalog->PutActiveConnection(variant_t((IDispatch *)m_conn->getConn()));
700 
701  pTable = pCatalog->Tables->GetItem(datasetName.c_str());
702 
703  pKey = pTable->Keys->GetItem(pk->getName().c_str());
704 
705  TESTHR(pTable->GetKeys()->Delete(_variant_t((IDispatch *)pKey)));
706  }
707  catch(_com_error& e)
708  {
709  throw Exception(TR_ADO(e.Description()));
710  }
711 }
712 
713 std::auto_ptr<te::da::ForeignKey> te::ado::Transactor::getForeignKey(const std::string& datasetName, const std::string& name)
714 {
715  if(!foreignKeyExists(datasetName, name))
716  throw Exception((boost::format(TR_ADO("The dataset \"%1%\" has no foreign key with this name \"%2%\"!")) % datasetName % name).str());
717 
718  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
719 
720  return std::auto_ptr<te::da::ForeignKey>(static_cast<te::da::ForeignKey*>(dt->getForeignKey(name)->clone()));
721 }
722 
723 std::vector<std::string> te::ado::Transactor::getForeignKeyNames(const std::string& datasetName)
724 {
725  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
726 
727  std::vector<std::string> fkNames;
728 
729  std::size_t numFK = dt->getNumberOfForeignKeys();
730 
731  for(std::size_t i = 0; i < numFK; ++i)
732  fkNames.push_back(dt->getForeignKey(i)->getName());
733 
734  return fkNames;
735 }
736 
737 bool te::ado::Transactor::foreignKeyExists(const std::string& datasetName, const std::string& name)
738 {
739  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
740 
741  std::vector<std::string> fkNames = getForeignKeyNames(datasetName);
742 
743  if(std::find(fkNames.begin(), fkNames.end(), name) != fkNames.end())
744  return true;
745 
746  return false;
747 }
748 
749 void te::ado::Transactor::addForeignKey(const std::string& datasetName, te::da::ForeignKey* fk)
750 {
751  _variant_t vOptional;
752  vOptional.vt = VT_ERROR;
753  vOptional.scode = DISP_E_PARAMNOTFOUND;
754 
755  ADOX::_KeyPtr pKey = 0;
756  ADOX::_TablePtr pTable = 0;
757  ADOX::_CatalogPtr pCatalog = 0;
758 
759  try
760  {
761  pCatalog->PutActiveConnection(variant_t((IDispatch *)m_conn->getConn()));
762 
763  pTable = pCatalog->Tables->GetItem(datasetName.c_str());
764 
765  TESTHR(pKey.CreateInstance(__uuidof(ADOX::Key)));
766 
767  pKey->Name = pTable->Name + "_fk";
768  pKey->Type = ADOX::adKeyForeign;
769  pKey->RelatedTable = fk->getReferencedDataSetType()->getName().c_str();
770 
771  for(size_t i = 0; i < fk->getProperties().size(); i++)
772  {
773 
774  te::dt::Property* p = fk->getProperties()[i];
775 
776  TESTHR(pKey->Columns->Append(p->getName().c_str(), te::ado::Convert2Ado(p->getType()), 256));
777  pKey->Columns->GetItem(p->getName().c_str())->RelatedColumn = fk->getReferencedProperties()[i]->getName().c_str();
778 
779  }
780 
781  TESTHR(pTable->Keys->Append(_variant_t((IDispatch *)pKey),ADOX::adKeyPrimary,vOptional,L"",L""));
782 
783  pCatalog->Tables->Refresh();
784  }
785  catch(_com_error& e)
786  {
787  throw Exception(TR_ADO(e.Description()));
788  }
789 }
790 
791 void te::ado::Transactor::dropForeignKey(const std::string& datasetName, const std::string& fkName)
792 {
793  ADOX::_KeyPtr pKey = 0;
794  ADOX::_TablePtr pTable = 0;
795  ADOX::_CatalogPtr pCatalog = 0;
796 
797  try
798  {
799 
800  pCatalog->PutActiveConnection(variant_t((IDispatch *)m_conn->getConn()));
801 
802  pTable = pCatalog->Tables->GetItem(datasetName.c_str());
803 
804  pKey = pTable->Keys->GetItem(fkName.c_str());
805 
806  TESTHR(pTable->GetKeys()->Delete(_variant_t((IDispatch *)pKey)));
807  }
808  catch(_com_error& e)
809  {
810  throw Exception(TR_ADO(e.Description()));
811  }
812 }
813 
814 std::auto_ptr<te::da::UniqueKey> te::ado::Transactor::getUniqueKey(const std::string& datasetName, const std::string& name)
815 {
816  if(!uniqueKeyExists(datasetName, name))
817  throw Exception((boost::format(TR_ADO("The dataset \"%1%\" has no unique key with this name \"%2%\"!")) % datasetName % name).str());
818 
819  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
820 
821  return std::auto_ptr<te::da::UniqueKey>(static_cast<te::da::UniqueKey*>(dt->getUniqueKey(name)->clone()));
822 }
823 
824 std::vector<std::string> te::ado::Transactor::getUniqueKeyNames(const std::string& datasetName)
825 {
826  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
827 
828  std::vector<std::string> ukNames;
829 
830  std::size_t numUKs = dt->getNumberOfUniqueKeys();
831 
832  for(std::size_t i = 0; i < numUKs; ++i)
833  ukNames.push_back(dt->getUniqueKey(i)->getName());
834 
835  return ukNames;
836 }
837 
838 bool te::ado::Transactor::uniqueKeyExists(const std::string& datasetName, const std::string& name)
839 {
840  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
841 
842  std::vector<std::string> ukNames = getUniqueKeyNames(datasetName);
843 
844  if(std::find(ukNames.begin(), ukNames.end(), name) != ukNames.end())
845  return true;
846 
847  return false;
848 }
849 
850 void te::ado::Transactor::addUniqueKey(const std::string& datasetName, te::da::UniqueKey* uk)
851 {
852  _variant_t vOptional;
853  vOptional.vt = VT_ERROR;
854  vOptional.scode = DISP_E_PARAMNOTFOUND;
855 
856  ADOX::_KeyPtr pKey = 0;
857  ADOX::_TablePtr pTable = 0;
858  ADOX::_CatalogPtr pCatalog = 0;
859 
860  TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
861  TESTHR(pKey.CreateInstance(__uuidof(ADOX::Key)));
862 
863  try
864  {
865  pCatalog->PutActiveConnection(variant_t((IDispatch *)m_conn->getConn()));
866 
867  pTable = pCatalog->Tables->GetItem(datasetName.c_str());
868 
869  pKey->Name = pTable->Name + "_uk";
870  pKey->Type = ADOX::adKeyUnique;
871 
872  for(size_t i = 0; i < uk->getProperties().size(); i++)
873  {
874  te::dt::Property* p = uk->getProperties()[i];
875 
876  TESTHR(pKey->Columns->Append(p->getName().c_str(), te::ado::Convert2Ado(p->getType()), 256));
877  }
878 
879  TESTHR(pTable->Keys->Append(_variant_t((IDispatch *)pKey),ADOX::adKeyUnique,vOptional,L"",L""));
880 
881  pCatalog->Tables->Refresh();
882  }
883  catch(_com_error& e)
884  {
885  throw Exception(TR_ADO(e.Description()));
886  }
887 }
888 
889 void te::ado::Transactor::dropUniqueKey(const std::string& datasetName, const std::string& name)
890 {
891  ADOX::_KeyPtr pKey = 0;
892  ADOX::_TablePtr pTable = 0;
893  ADOX::_CatalogPtr pCatalog = 0;
894 
895  try
896  {
897  pCatalog->PutActiveConnection(variant_t((IDispatch *)m_conn->getConn()));
898 
899  pTable = pCatalog->Tables->GetItem(datasetName.c_str());
900 
901  pKey = pTable->Keys->GetItem(name.c_str());
902 
903  TESTHR(pTable->GetKeys()->Delete(_variant_t((IDispatch *)pKey)));
904  }
905  catch(_com_error& e)
906  {
907  throw Exception(TR_ADO(e.Description()));
908  }
909 }
910 
911 std::auto_ptr<te::da::CheckConstraint> te::ado::Transactor::getCheckConstraint(const std::string& datasetName, const std::string& name)
912 {
913  if(!checkConstraintExists(datasetName, name))
914  throw Exception((boost::format(TR_ADO("The dataset \"%1%\" has no check constraint with this name \"%2%\"!")) % datasetName % name).str());
915 
916  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
917 
918  return std::auto_ptr<te::da::CheckConstraint>(static_cast<te::da::CheckConstraint*>(dt->getCheckConstraint(name)->clone()));
919 }
920 
921 std::vector<std::string> te::ado::Transactor::getCheckConstraintNames(const std::string& datasetName)
922 {
923  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
924 
925  std::vector<std::string> ccNames;
926 
927  std::size_t numCCs = dt->getNumberOfCheckConstraints();
928 
929  for(std::size_t i = 0; i < numCCs; ++i)
930  ccNames.push_back(dt->getCheckConstraint(i)->getName());
931 
932  return ccNames;
933 }
934 
935 bool te::ado::Transactor::checkConstraintExists(const std::string& datasetName, const std::string& name)
936 {
937  std::vector<std::string> ccNames = getCheckConstraintNames(datasetName);
938 
939  if(std::find(ccNames.begin(), ccNames.end(), name) != ccNames.end())
940  return true;
941 
942  return false;
943 }
944 
945 void te::ado::Transactor::addCheckConstraint(const std::string& /*datasetName*/, te::da::CheckConstraint* /*cc*/)
946 {
947  throw Exception(TR_ADO("Method addCheckConstraint: not implemented yet!"));
948 }
949 
950 void te::ado::Transactor::dropCheckConstraint(const std::string& /*datasetName*/, const std::string& /*name*/)
951 {
952  throw Exception(TR_ADO("Method dropCheckConstraint: not implemented yet!"));
953 }
954 
955 std::auto_ptr<te::da::Index> te::ado::Transactor::getIndex(const std::string& datasetName, const std::string& name)
956 {
957  if(!indexExists(datasetName, name))
958  throw Exception((boost::format(TR_ADO("The dataset \"%1%\" has no index with this name \"%2%\"!")) % datasetName % name).str());
959 
960  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
961 
962  return std::auto_ptr<te::da::Index>(dt->getIndex(name)->clone());
963 }
964 
965 std::vector<std::string> te::ado::Transactor::getIndexNames(const std::string& datasetName)
966 {
967  std::vector<std::string> idxNames;
968 
969  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
970 
971  std::size_t numIdxs = dt->getNumberOfIndexes();
972 
973  for(std::size_t i = 0; i < numIdxs; ++i)
974  idxNames.push_back(dt->getIndex(i)->getName());
975 
976  return idxNames;
977 }
978 
979 bool te::ado::Transactor::indexExists(const std::string& datasetName, const std::string& name)
980 {
981  std::vector<std::string> idxNames = getIndexNames(datasetName);
982 
983  if(std::find(idxNames.begin(), idxNames.end(), name) != idxNames.end())
984  return true;
985 
986  return false;
987 }
988 
989 void te::ado::Transactor::addIndex(const std::string& datasetName, te::da::Index* idx,
990  const std::map<std::string, std::string>& options)
991 {
992  ADOX::_IndexPtr pIndex = 0;
993  ADOX::_TablePtr pTable = 0;
994  ADOX::_CatalogPtr pCatalog = 0;
995 
996  TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
997  TESTHR(pIndex.CreateInstance(__uuidof(ADOX::Index)));
998 
999  try
1000  {
1001  pCatalog->PutActiveConnection(variant_t((IDispatch *)m_conn->getConn()));
1002 
1003  pTable = pCatalog->Tables->GetItem(datasetName.c_str());
1004 
1005  pIndex->Name = idx->getName().c_str();
1006 
1007  std::vector<te::dt::Property*> idxProps = idx->getProperties();
1008  for(size_t i = 0; i < idxProps.size(); i++)
1009  {
1010  long size = 0;
1011  if(idxProps[i]->getType() == te::dt::STRING_TYPE)
1012  size = (long)((te::dt::StringProperty*)idxProps[i])->size();
1013 
1014  TESTHR(pIndex->Columns->Append(idxProps[i]->getName().c_str(), te::ado::Convert2Ado(idxProps[i]->getType()), size));
1015  }
1016 
1017  TESTHR(pTable->Indexes->Append(_variant_t((IDispatch *)pIndex)));
1018  }
1019  catch(_com_error& e)
1020  {
1021  throw Exception(TR_ADO(e.Description()));
1022  }
1023 }
1024 
1025 void te::ado::Transactor::dropIndex(const std::string& datasetName, const std::string& idxName)
1026 {
1027  if(!indexExists(datasetName, idxName))
1028  throw Exception((boost::format(TR_ADO("The dataset \"%1%\" has no index with this name: \"%2%\"!")) % datasetName % idxName).str());
1029 
1030  std::string sql("DROP INDEX ");
1031  sql += idxName;
1032 
1033  execute(sql);
1034 
1035  std::auto_ptr<te::da::DataSetType> dt(getDataSetType(datasetName));
1036 
1037  te::da::Index* idx = dt->getIndex(idxName);
1038 
1039  dt->remove(idx);
1040 }
1041 
1042 std::auto_ptr<te::da::Sequence> te::ado::Transactor::getSequence(const std::string& name)
1043 {
1044  throw Exception(TR_ADO("Method getSequence: not implemented yet!"));
1045 }
1046 
1047 std::vector<std::string> te::ado::Transactor::getSequenceNames()
1048 {
1049  throw Exception(TR_ADO("Method getSequenceNames: not implemented yet!"));
1050 }
1051 
1052 bool te::ado::Transactor::sequenceExists(const std::string& /*name*/)
1053 {
1054  throw Exception(TR_ADO("Method sequenceExists: not implemented yet!"));
1055 }
1056 
1058 {
1059  throw Exception(TR_ADO("Method addSequence: not implemented yet!"));
1060 }
1061 
1062 void te::ado::Transactor::dropSequence(const std::string& /*name*/)
1063 {
1064  throw Exception(TR_ADO("Method dropSequence: not implemented yet!"));
1065 }
1066 
1067 std::auto_ptr<te::gm::Envelope> te::ado::Transactor::getExtent(const std::string& datasetName,
1068  const std::string& /*propertyName*/)
1069 {
1070  if(!dataSetExists(datasetName))
1071  throw Exception(TR_ADO("The Data Set Type does not exist!"));
1072 
1073  std::string sql = "SELECT MIN(lower_x), MIN(lower_y), MAX(upper_x), MAX(upper_y) from " + datasetName;
1074 
1075  std::auto_ptr<te::da::DataSet> resultBox(query(sql));
1076 
1077  std::auto_ptr<te::gm::Envelope> env(new te::gm::Envelope());
1078 
1079  if(resultBox.get())
1080  {
1081  resultBox->moveFirst();
1082  env->m_llx = resultBox->getDouble(0);
1083  env->m_lly = resultBox->getDouble(1);
1084  env->m_urx = resultBox->getDouble(2);
1085  env->m_ury = resultBox->getDouble(3);
1086  }
1087  else
1088  {
1089  throw Exception(TR_ADO("Error when calculating the envelope!"));
1090  }
1091 
1092  return env;
1093 }
1094 
1095 std::auto_ptr<te::gm::Envelope> te::ado::Transactor::getExtent(const std::string& datasetName,
1096  std::size_t /*propertyPos*/)
1097 {
1098  return getExtent(datasetName, 0);
1099 }
1100 
1101 std::size_t te::ado::Transactor::getNumberOfItems(const std::string& datasetName)
1102 {
1103  std::auto_ptr<te::da::DataSet> result(getDataSet(datasetName));
1104 
1105  return result->size();
1106 }
1107 
1109 {
1110  std::vector<std::string> datasetNames = getDataSetNames();
1111 
1112  if(datasetNames.empty())
1113  return false;
1114 
1115  return true;
1116 }
1117 
1118 bool te::ado::Transactor::dataSetExists(const std::string& name)
1119 {
1120  std::vector<std::string> datasetNames = getDataSetNames();
1121 
1122  if(std::find(datasetNames.begin(), datasetNames.end(), name) != datasetNames.end())
1123  return true;
1124 
1125  return false;
1126 }
1127 
1128 void te::ado::Transactor::createDataSet(te::da::DataSetType* dt, const std::map<std::string, std::string>& options)
1129 {
1130  ADOX::_TablePtr pTable = 0;
1131  ADOX::_CatalogPtr pCatalog = 0;
1132 
1133  TESTHR(pTable.CreateInstance(__uuidof (ADOX::Table)));
1134  TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
1135 
1136  try
1137  {
1138  pCatalog->PutActiveConnection(variant_t((IDispatch *)m_conn->getConn()));
1139 
1140  pTable->Name = dt->getName().c_str();
1141 
1142  TESTHR(pCatalog->Tables->Append(_variant_t((IDispatch*)pTable)));
1143 
1144  }
1145  catch(_com_error &e)
1146  {
1147  throw Exception(TR_ADO(e.ErrorMessage()));
1148  }
1149 
1150  std::size_t ncols = dt->size();
1151 
1152  for(std::size_t i = 0; i < ncols; ++i)
1153  addProperty(dt->getName(), dt->getProperty(i));
1154 
1155  if(dt->getPrimaryKey())
1156  addPrimaryKey(dt->getName(), dt->getPrimaryKey());
1157 }
1158 
1159 void te::ado::Transactor::cloneDataSet(const std::string& /*name*/,
1160  const std::string& /*cloneName*/,
1161  const std::map<std::string, std::string>& /*options*/)
1162 {
1163  throw Exception(TR_ADO("Method cloneDataSet: not implemented yet!"));
1164 }
1165 
1166 void te::ado::Transactor::dropDataSet(const std::string& name)
1167 {
1168  ADOX::_CatalogPtr pCatalog = 0;
1169 
1170  TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
1171 
1172  try
1173  {
1174  pCatalog->PutActiveConnection(variant_t((IDispatch *)m_conn->getConn()));
1175 
1176  TESTHR(pCatalog->Tables->Delete(name.c_str()));
1177  }
1178  catch(_com_error& e)
1179  {
1180  throw Exception(TR_ADO(e.Description()));
1181  }
1182 }
1183 
1184 void te::ado::Transactor::renameDataSet(const std::string& name, const std::string& newName)
1185 {
1186  ADOX::_CatalogPtr pCatalog = 0;
1187 
1188  TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
1189 
1190  try
1191  {
1192  pCatalog->Tables->GetItem(name.c_str())->PutName(newName.c_str());
1193  }
1194  catch(_com_error& e)
1195  {
1196  throw Exception(TR_ADO(e.Description()));
1197  }
1198 }
1199 
1200 void te::ado::Transactor::add(const std::string& datasetName,
1201  te::da::DataSet* d,
1202  const std::map<std::string, std::string>& options,
1203  std::size_t limit)
1204 {
1205  _RecordsetPtr recset;
1206  TESTHR(recset.CreateInstance(__uuidof(Recordset)));
1207 
1208  try
1209  {
1210  TESTHR(recset->Open(_bstr_t(datasetName.c_str()),
1211  _variant_t((IDispatch*)m_conn->getConn(),true), adOpenKeyset, adLockOptimistic, adCmdTable));
1212 
1213  while(d->moveNext())
1214  {
1215  TESTHR(recset->AddNew());
1216 
1217  for(std::size_t i = 0; i < d->getNumProperties(); ++i)
1218  {
1219 
1220  std::string pname = d->getPropertyName(i);
1221  int pType = d->getPropertyDataType(i);
1222 
1223  if(d->isNull(i))
1224  continue;
1225  //{
1226  // _variant_t var;
1227  // var.ChangeType(VT_NULL, NULL);
1228  // recset->GetFields()->GetItem(pname.c_str())->PutValue(var);
1229  //}
1230 
1231 
1232  switch(pType)
1233  {
1234  case te::dt::CHAR_TYPE:
1235  recset->GetFields()->GetItem(pname.c_str())->Value = (_bstr_t)d->getChar(pname.c_str());
1236  break;
1237 
1238  case te::dt::UCHAR_TYPE:
1239  recset->GetFields()->GetItem(pname.c_str())->Value = (_bstr_t)d->getUChar(pname.c_str());
1240  break;
1241 
1242  case te::dt::INT16_TYPE:
1243  recset->GetFields()->GetItem(pname.c_str())->Value = (_variant_t)d->getInt16(pname.c_str());
1244  break;
1245 
1246  case te::dt::INT32_TYPE:
1247  recset->GetFields()->GetItem(pname.c_str())->Value = (_variant_t)d->getInt32(pname.c_str());
1248  break;
1249 
1250  case te::dt::INT64_TYPE:
1251  recset->GetFields()->GetItem(pname.c_str())->Value = (_variant_t)d->getInt64(pname.c_str());
1252  break;
1253 
1254  case te::dt::NUMERIC_TYPE:
1255  {
1256  std::string sval = d->getNumeric(pname);
1257  if(sval.empty())
1258  sval = "0.0";
1259 
1260  double dval = boost::lexical_cast<double>(sval);
1261  recset->GetFields()->GetItem(pname.c_str())->Value = (_variant_t)(dval);
1262  }
1263  break;
1264 
1265  case te::dt::DATETIME_TYPE:
1266  {
1267  std::auto_ptr<te::dt::DateTime> dtm(d->getDateTime(i));
1268 
1269  std::string dtt = te::ado::GetFormattedDateTime(dtm.get());
1270 
1271  recset->GetFields()->GetItem(pname.c_str())->Value = (_bstr_t)dtt.c_str();
1272 
1273  break;
1274  }
1275 
1276  case te::dt::FLOAT_TYPE:
1277  recset->GetFields()->GetItem(pname.c_str())->Value = (_variant_t)d->getFloat(pname.c_str());
1278  break;
1279 
1280  case te::dt::DOUBLE_TYPE:
1281  recset->GetFields()->GetItem(pname.c_str())->Value = (_variant_t)d->getDouble(pname.c_str());
1282  break;
1283 
1284  case te::dt::STRING_TYPE:
1285  recset->GetFields()->GetItem(pname.c_str())->Value = (_bstr_t)d->getString(pname.c_str()).c_str();
1286  break;
1287 
1288  case te::dt::BOOLEAN_TYPE:
1289  recset->GetFields()->GetItem(pname.c_str())->Value = (_variant_t)d->getBool(pname.c_str());
1290  break;
1291 
1293  {
1294  /*char * data = ((te::dt::ByteArray*)props[i])->getData();
1295 
1296  _variant_t var;
1297  te::ado::Blob2Variant(data, ((te::dt::ByteArray*)props[i])->bytesUsed(), var);
1298 
1299  recset->Fields->GetItem(props[i]->getName().c_str())->AppendChunk (var);
1300 
1301  break;*/
1302  }
1303 
1304  //case te::dt::ARRAY_TYPE:
1305  case te::dt::GEOMETRY_TYPE:
1306  {
1307  std::auto_ptr<te::gm::Geometry> geometry(d->getGeometry(pname));
1308  const te::gm::Envelope* env = geometry->getMBR();
1309 
1310  recset->GetFields()->GetItem("lower_x")->Value = (_variant_t)env->m_llx;
1311  recset->GetFields()->GetItem("lower_y")->Value = (_variant_t)env->m_lly;
1312  recset->GetFields()->GetItem("upper_x")->Value = (_variant_t)env->m_urx;
1313  recset->GetFields()->GetItem("upper_y")->Value = (_variant_t)env->m_ury;
1314 
1315  _variant_t var;
1316  Convert2Ado(geometry.get(), var);
1317 
1318  recset->Fields->GetItem(pname.c_str())->AppendChunk (var);
1319 
1320  break;
1321  }
1322 
1323  default:
1324  throw te::ado::Exception(TR_ADO("The informed type could not be mapped to ADO type system!"));
1325  break;
1326  }
1327  }
1328 
1329  TESTHR(recset->Update());
1330 
1331  }
1332  }
1333  catch(_com_error& e)
1334  {
1335  throw Exception(TR_ADO(e.Description()));
1336  }
1337 }
1338 
1339 void te::ado::Transactor::remove(const std::string& datasetName, const te::da::ObjectIdSet* oids)
1340 {
1341  ADOX::_CatalogPtr pCatalog = 0;
1342 
1343  TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
1344 
1345  try
1346  {
1347  pCatalog->PutActiveConnection(variant_t((IDispatch *)m_conn->getConn()));
1348 
1349  TESTHR(pCatalog->Tables->Delete(datasetName.c_str()));
1350  }
1351  catch(_com_error& e)
1352  {
1353  throw Exception(TR_ADO(e.Description()));
1354  }
1355 }
1356 
1357 void te::ado::Transactor::update(const std::string& datasetName,
1358  te::da::DataSet* dataset,
1359  const std::vector<std::size_t>& properties,
1360  const te::da::ObjectIdSet* oids,
1361  const std::map<std::string, std::string>& options,
1362  std::size_t limit)
1363 {
1364  //TODO
1365 }
1366 
1367 void te::ado::Transactor::optimize(const std::map<std::string, std::string>& opInfo)
1368 {
1369 
1370 }
1371 
1373 {
1374  _ConnectionPtr adoConn = m_conn->getConn();
1375 
1376  ADOX::_CatalogPtr pCatalog = 0;
1377 
1378  TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
1379 
1380  try
1381  {
1382  pCatalog->PutActiveConnection(variant_t((IDispatch *)adoConn));
1383  }
1384  catch(_com_error& e)
1385  {
1386  throw Exception(TR_ADO(e.Description()));
1387  }
1388  ADOX::TablesPtr tables = pCatalog->GetTables();
1389 
1390  ADOX::_TablePtr t = tables->GetItem(dt->getName().c_str());
1391 
1392  ADOX::KeysPtr keys = t->GetKeys();
1393 
1394  ADOX::_KeyPtr pk = 0;
1395 
1396  for(long i = 0; i < keys->Count; i++)
1397  {
1398  if(keys->GetItem(i)->GetType() == ADOX::adKeyPrimary)
1399  pk = keys->GetItem(i);
1400  }
1401 
1402  if(pk == 0)
1403  {
1404  dt->setPrimaryKey(0);
1405  return;
1406  }
1407 
1408  ADOX::ColumnsPtr cols = pk->GetColumns();
1409 
1410  te::da::PrimaryKey* tlPk = new te::da::PrimaryKey(std::string(pk->GetName()), dt);
1411 
1412  for(long i = 0; i < cols->GetCount(); i++)
1413  tlPk->add(dt->getProperty(std::string(cols->GetItem(i)->GetName())));
1414 }
1415 
1417 {
1418  std::string dsName = dt->getName();
1419  int numCols = 0;
1420 
1421  ADOX::DataTypeEnum colType;
1422  std::map<int, std::string> colNamesMap;
1423  std::map<int, ADOX::DataTypeEnum> colTypesMap;
1424  std::map<int, int> charLengthMap;
1425  std::map<int, bool> isRequiredMap;
1426  std::map<int, bool> hasDefaultMap;
1427  std::map<int, std::string> defaultValueMap;
1428 
1429  _ConnectionPtr conn = 0;
1430 
1431  try
1432  {
1433  HRESULT hr = S_OK;
1434 
1435  conn = m_conn->getConn();
1436 
1437  _RecordsetPtr rs = NULL;
1438 
1439  TESTHR(rs.CreateInstance(__uuidof(Recordset)));
1440 
1441  // Create a safearray which takes three elements,and pass it as
1442  // the second parameter in the OpenSchema method.
1443  SAFEARRAY FAR* psa = NULL;
1444  SAFEARRAYBOUND rgsabound;
1445  _variant_t var[3];
1446 
1447  _variant_t Array;
1448  rgsabound.lLbound = 0;
1449  rgsabound.cElements = 3;
1450  psa = SafeArrayCreate(VT_VARIANT, 1, &rgsabound);
1451 
1452  var[0].vt = VT_EMPTY;
1453  var[1].vt = VT_EMPTY;
1454  var[2] = dsName.c_str();
1455 
1456  // Fill the safe array.
1457  for(LONG i = 0; i < 3; ++i)
1458  hr = SafeArrayPutElement(psa, &i, &var[i]);
1459 
1460  Array.vt = VT_ARRAY | VT_VARIANT;
1461  Array.parray = psa;
1462 
1463  rs = conn->OpenSchema(adSchemaColumns, &Array, vtMissing);
1464 
1465  int pos;
1466  while (!(rs->EndOfFile))
1467  {
1468  // Get the column name
1469  _bstr_t columnName = rs->Fields->GetItem("COLUMN_NAME")->Value;
1470  pos = rs->Fields->GetItem("ORDINAL_POSITION")->Value;
1471  pos = pos - 1;
1472  colNamesMap[pos] = (LPCSTR)columnName;
1473 
1474  // Get the data type of the column
1475  colType = ADOX::DataTypeEnum(int(rs->Fields->GetItem("DATA_TYPE")->Value));
1476  colTypesMap[pos] = colType;
1477 
1478  // Get the length of the column
1479  _variant_t length = rs->Fields->GetItem("CHARACTER_MAXIMUM_LENGTH")->Value;
1480  int charLength = 0;
1481  if(length.vt != VT_NULL)
1482  charLength = (int)length.dblVal;
1483  charLengthMap[pos] = charLength;
1484 
1485  // Get the columns that accept null values
1486  bool nullVal = rs->Fields->GetItem("IS_NULLABLE")->Value;
1487  isRequiredMap[pos] = !nullVal;
1488 
1489  // Get the columns that has default values
1490  bool hasDefault = rs->Fields->GetItem("COLUMN_HASDEFAULT")->Value;
1491  hasDefaultMap[pos] = !hasDefault;
1492 
1493  // Get the default value
1494  std::string defaultStr;
1495  if(hasDefault)
1496  {
1497  _bstr_t defaultValue = rs->Fields->GetItem("COLUMN_DEFAULT")->Value;
1498  defaultStr = (LPSTR)defaultValue;
1499  }
1500 
1501  defaultValueMap[pos] = defaultStr;
1502 
1503  rs->MoveNext();
1504  ++numCols;
1505  }
1506  }
1507  catch (_com_error& e)
1508  {
1509  std::cout << "Error = " << (char*) e.ErrorMessage() << std::endl;
1510  }
1511 
1512  // Create the dataset properties
1513  for(int i = 0; i < numCols; ++i)
1514  {
1515  te::dt::Property* p = 0;
1516  ADOX::DataTypeEnum colType = colTypesMap[i];
1517  std::string colName = colNamesMap[i];
1518 
1519  switch(colType)
1520  {
1521  case ::adBoolean:
1522  {
1523  p = new te::dt::SimpleProperty(colName, Convert2Terralib(colType));
1525 
1526  sp->setRequired(isRequiredMap[i]);
1527  break;
1528  }
1529 
1530  case ::adVarWChar:
1531  case ::adWChar:
1532  case ::adVarChar:
1533  case ::adLongVarChar:
1534  case ::adLongVarWChar:
1535  case ::adBSTR:
1536  case ::adChar:
1537  {
1538  p = new te::dt::StringProperty(colName, (te::dt::StringType)Convert2Terralib(colType), charLengthMap[i]);
1540 
1541  sp->setRequired(isRequiredMap[i]);
1542  sp->setSize(charLengthMap[i]);
1543 
1544  break;
1545  }
1546 
1547  case ADOX::adTinyInt:
1548  case ADOX::adSmallInt:
1549  case ADOX::adInteger:
1550  case ADOX::adBigInt:
1551  case ADOX::adSingle:
1552  case ADOX::adDouble:
1553  case ADOX::adDecimal:
1554  case ::adUnsignedBigInt:
1555  case ::adUnsignedInt:
1556  case ::adUnsignedSmallInt:
1557  case ::adUnsignedTinyInt:
1558  {
1559  p = new te::dt::SimpleProperty(colName, Convert2Terralib(colType));
1561 
1562  sp->setRequired(isRequiredMap[i]);
1563  break;
1564  }
1565 
1566  case ADOX::adBinary:
1567  case ADOX::adLongVarBinary:
1568  {
1569 
1570  std::map<std::string, std::string> geomColumns = m_ds->getGeomColumns();
1571  std::map<std::string, std::string>::iterator it = geomColumns.find(dsName);
1572 
1573  if(it != geomColumns.end())
1574  {
1575  if(it->second == colName)
1576  {
1577  p = new te::gm::GeometryProperty(colName, te::ado::GetSRID(conn, dsName, colName), te::ado::GetType(conn, dsName, colName));
1578  }
1579  }
1580  else
1581  {
1582  p = new te::dt::SimpleProperty(colName, Convert2Terralib(colType));
1583  }
1584 
1585  break;
1586  }
1587 
1588  case ADOX::adDate:
1589  case ADOX::adDBDate:
1590  case ADOX::adDBTime:
1591  case ADOX::adDBTimeStamp:
1593  break;
1594 
1595  default:
1596  p = new te::dt::SimpleProperty(colName, te::dt::UNKNOWN_TYPE);
1597  break;
1598  }
1599 
1600  dt->add(p);
1601  }
1602 }
1603 
1605 {
1606  _ConnectionPtr adoConn = m_conn->getConn();
1607 
1608  ADOX::_CatalogPtr pCatalog = 0;
1609 
1610  TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
1611 
1612  try
1613  {
1614  pCatalog->PutActiveConnection(variant_t((IDispatch *)adoConn));
1615  }
1616  catch(_com_error& e)
1617  {
1618  throw Exception(TR_ADO(e.Description()));
1619  }
1620 
1621  ADOX::TablesPtr tables = pCatalog->GetTables();
1622 
1623  ADOX::_TablePtr t = tables->GetItem(dt->getName().c_str());
1624 
1625  ADOX::KeysPtr keys = t->GetKeys();
1626 
1627  for(long i = 0; i < keys->Count; i++)
1628  {
1629  if(keys->GetItem(i)->GetType() == ADOX::adKeyUnique)
1630  {
1631  ADOX::_KeyPtr uk = keys->GetItem(i);
1632 
1633  te::da::UniqueKey* tlUk = new te::da::UniqueKey(std::string(uk->GetName()), dt);
1634 
1635  ADOX::ColumnsPtr cols = uk->GetColumns();
1636 
1637  for(long j = 0; j < cols->Count; j++)
1638  tlUk->add(dt->getProperty(std::string(cols->GetItem(i)->GetName())));
1639  }
1640  }
1641 }
1642 
1644 {
1645  _ConnectionPtr adoConn = m_conn->getConn();
1646 
1647  ADOX::_CatalogPtr pCatalog = 0;
1648 
1649  TESTHR((pCatalog.CreateInstance(__uuidof(ADOX::Catalog))));
1650 
1651  try
1652  {
1653  pCatalog->PutActiveConnection(variant_t((IDispatch *)adoConn));
1654  }
1655  catch(_com_error& e)
1656  {
1657  throw Exception(TR_ADO(e.Description()));
1658  }
1659 
1660  ADOX::TablesPtr tables = pCatalog->GetTables();
1661 
1662  ADOX::_TablePtr t = tables->GetItem(dt->getName().c_str());
1663 
1664  ADOX::IndexesPtr idxs = t->GetIndexes();
1665 
1666  for(long i = 0; i < idxs->GetCount(); i++)
1667  {
1668  ADOX::_IndexPtr idx = idxs->GetItem(i);
1669 
1670  te::da::Index* tlIdx = new te::da::Index();
1671  tlIdx->setName(std::string(idx->GetName()));
1672 
1673  std::vector<te::dt::Property*> props;
1674 
1675  ADOX::ColumnsPtr cols = idx->GetColumns();
1676  for(long i = 0; i < cols->GetCount(); i++)
1677  props.push_back(dt->getProperty(std::string(cols->GetItem(i)->GetName())));
1678 
1679  tlIdx->setProperties(props);
1680 
1681  dt->add(tlIdx);
1682  }
1683 }
1684 
1686 {
1687  _RecordsetPtr rs = NULL;
1688 
1689  std::string dtName = dt->getName();
1690 
1691  std::string str = "[" + dtName + "]";
1692 
1693  try
1694  {
1695  HRESULT hr = S_OK;
1696 
1697  _ConnectionPtr adoConn = m_conn->getConn();
1698 
1699  TESTHR(rs.CreateInstance(__uuidof(Recordset)));
1700 
1701  rs = adoConn->OpenSchema(adSchemaCheckConstraints);
1702 
1703  while (!(rs->EndOfFile))
1704  {
1705  std::string constraintName = (LPCSTR)(bstr_t)(rs->Fields->GetItem("CONSTRAINT_NAME")->GetValue());
1706 
1707  if(constraintName.find(str) != std::string::npos)
1708  {
1709  te::da::CheckConstraint* cc = new te::da::CheckConstraint(constraintName, dt);
1710  std::string checkClause = (LPCSTR)(bstr_t)(rs->Fields->GetItem("CHECK_CLAUSE")->GetValue());
1711  cc->setExpression(checkClause);
1712  }
1713 
1714  rs->MoveNext();
1715  }
1716  }
1717  catch(_com_error& e)
1718  {
1719  throw Exception(TR_ADO(e.Description()));
1720  }
1721 
1722  // Clean up objects before exit.
1723  if(rs && rs->State == adStateOpen)
1724  rs->Close();
1725 }
1726 
1727 void te::ado::Transactor::insertIntoGeometryColumns(const std::string& datasetName,
1728  te::gm::GeometryProperty* geomProp)
1729 {
1730  _ConnectionPtr adoConn = m_conn->getConn();
1731 
1732  int coord_dimension = 2;
1733 
1734  if(te::ado::IsZProperty(geomProp->getGeometryType()))
1735  coord_dimension = 3;
1736 
1737  _RecordsetPtr recset;
1738  TESTHR(recset.CreateInstance(__uuidof(Recordset)));
1739 
1740  try
1741  {
1742  TESTHR(recset->Open(_bstr_t("geometry_columns"),
1743  _variant_t((IDispatch*)adoConn,true), adOpenKeyset, adLockOptimistic, adCmdTable));
1744 
1745  TESTHR(recset->AddNew());
1746 
1747  recset->GetFields()->GetItem("f_table_catalog")->Value = (_bstr_t)std::string("''").c_str();
1748  recset->GetFields()->GetItem("f_table_schema")->Value = (_bstr_t)std::string("public").c_str();
1749  recset->GetFields()->GetItem("f_table_name")->Value = (_bstr_t)datasetName.c_str();
1750  recset->GetFields()->GetItem("f_geometry_column")->Value = (_bstr_t)geomProp->getName().c_str();
1751  recset->GetFields()->GetItem("coord_dimension")->Value = (_variant_t)coord_dimension;
1752  recset->GetFields()->GetItem("srid")->Value = (_variant_t)geomProp->getSRID();
1753  recset->GetFields()->GetItem("type")->Value = (_bstr_t)te::ado::GetGeometryName(geomProp->getGeometryType()).c_str();
1754 
1755  recset->Update();
1756  }
1757  catch(_com_error& e)
1758  {
1759  throw Exception(TR_ADO(e.Description()));
1760  }
1761 
1762  m_ds->registerGeometryColumn(datasetName, geomProp->getName());
1763 }
1764 
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos.
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
int Convert2Terralib(ADOX::DataTypeEnum adoType)
Bind ADOX Type to TerraLib Type.
Definition: Utils.cpp:202
void setRequired(bool r)
It tells if the property is required or not.
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.
Definition: Transactor.cpp:935
void addForeignKey(const std::string &datasetName, te::da::ForeignKey *fk)
It adds a foreign key constraint to a dataset.
Definition: Transactor.cpp:749
Utility functions for ADO.
bool isRequired() const
It returns true if the attribute is required, otherwise it returns false.
It describes an index associated to a DataSetType.
Definition: Index.h:54
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.
Definition: Transactor.cpp:989
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
Definition: Transactor.cpp:96
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
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::gm::GeomType GetType(_ConnectionPtr adoConn, std::string tableName, std::string geomPropName)
Read the geometry_columns table end return a geometry type.
Definition: Utils.cpp:825
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:53
void add(te::dt::Property *p)
It adds the property to the list of properties that participates in the unique key.
Definition: UniqueKey.h:124
Transactor(DataSource *ds)
Definition: Transactor.cpp:81
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.
bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset.
Definition: Transactor.cpp:641
An atomic property like an integer or double.
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.
DataSet class implementation for Microsoft Access driver.
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
Definition: DataSet.h:64
bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source.
void getUniqueKeys(te::da::DataSetType *dt)
It update the DataSetType about the Unique Keys.
virtual float getFloat(std::size_t i) const =0
Method for retrieving a float attribute value.
The type for date and time types: date, date period, date duration, time duration, time instant, time period, time instant with time zone or time period with time zone.
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
virtual bool getBool(std::size_t i) const =0
Method for retrieving a boolean attribute value.
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
int getSRID() const
It returns the spatial reference system identifier associated to this property.
void setName(const std::string &name)
It sets the index name.
Definition: Index.h:162
void setExpression(const std::string &e)
It sets the check constraint expression.
void commit()
It commits the transaction.
Definition: Transactor.cpp:114
virtual std::auto_ptr< te::dt::DateTime > getDateTime(std::size_t i) const =0
Method for retrieving a date and time attribute value.
The type for string types: FIXED_STRING, VAR_STRING or STRING.
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source.
Definition: Transactor.cpp:289
std::string GetFormattedDateTime(te::dt::DateTime *dateTime)
It gets a formatted DateTime string for ADO.
Definition: Utils.cpp:1228
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
void setProperties(const std::vector< te::dt::Property * > &properties)
It sets the properties that take part of the index.
Definition: Index.h:190
void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset.
Definition: Transactor.cpp:889
virtual unsigned char getUChar(std::size_t i) const =0
Method for retrieving an unsigned character attribute value (1 byte long).
virtual std::string getString(std::size_t i) const =0
Method for retrieving a string value attribute.
void addCheckConstraint(const std::string &datasetName, te::da::CheckConstraint *cc)
It adds a check constraint to the dataset.
Definition: Transactor.cpp:945
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
bool hasDataSets()
It checks if the data source has any dataset.
const std::string & getName() const
It returns the property name.
Definition: Property.h:126
void add(Constraint *c)
It adds a new constraint.
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...
Definition: Transactor.cpp:202
virtual std::string getNumeric(std::size_t i) const =0
Method for retrieving a numeric attribute value.
void setSize(std::size_t s)
It sets the maximum number of characters for a varying string, or the number of characters for a fixe...
void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset.
Definition: Transactor.cpp:566
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
It describes a sequence (a number generator).
Definition: Sequence.h:56
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the index.
Definition: Index.h:183
ADOX::DataTypeEnum Convert2Ado(int terralib)
Bind TerraLib Type to ADO Type.
Definition: Utils.cpp:128
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.
Definition: Transactor.cpp:911
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:50
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
Definition: PrimaryKey.h:109
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 indexExists(const std::string &datasetName, const std::string &name)
It checks if an index with the given name exists in the dataset.
Definition: Transactor.cpp:979
A class that implements a connection to a ADO database.
std::auto_ptr< te::da::Sequence > getSequence(const std::string &name)
It gets the sequence with the given name in the data source.
Implementation of a dataset for the ADO driver.
Definition: DataSet.h:56
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
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.
Definition: Transactor.cpp:955
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids=0)
It removes all the informed items from the dataset.
std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset.
Definition: Transactor.cpp:723
bool isDataSetNameValid(const std::string &datasetName)
It returns true if the given string is a valid dataset name.
Definition: Transactor.cpp:279
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.
Definition: Transactor.cpp:255
void addPrimaryKey(const std::string &datasetName, te::da::PrimaryKey *pk)
It adds a primary key constraint to the dataset schema.
Definition: Transactor.cpp:651
bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
Definition: Transactor.cpp:407
DataSourceTransactor class implementation for Microsoft Access driver.
void setPrimaryKey(PrimaryKey *pk)
It sets the primary key constraint.
virtual boost::int16_t getInt16(std::size_t i) const =0
Method for retrieving a 16-bit integer attribute value (2 bytes long).
void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema.
Definition: Transactor.cpp:689
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
A visitor for building an SQL statement using ADO dialect.
int GetSRID(_ConnectionPtr adoConn, std::string tableName, std::string geomPropName)
Read the geometry_columns table end return a SRID.
Definition: Utils.cpp:801
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
void addSequence(te::da::Sequence *sequence)
It creates a new sequence in the data source.
void cancel()
It requests that the data source stop the processing of the current command.
Definition: Transactor.cpp:265
A Query is independent from the data source language/dialect.
Definition: Query.h:46
void execute(const te::da::Query &command)
It executes the specified command using a generic query representation.
Definition: Transactor.cpp:239
void getCheckConstraints(te::da::DataSetType *dt)
It update the DataSetType about the Check Constraints.
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
Implementation of the data source class for the ADO driver.
Property * getParent() const
It returns the parent of this property, or NULL, if it doesn&#39;t have one.
Definition: Property.h:150
std::string MakeConnectionStr(const std::map< std::string, std::string > &dsInfo)
Create a connection string based on a map.
Definition: Utils.cpp:82
A visitor for building an SQL statement using ADO dialect.
Definition: SQLVisitor.h:49
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
const std::string & getName() const
It returns the index name.
Definition: Index.h:155
void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema.
Definition: Transactor.cpp:791
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
std::auto_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName)
It retrieves the primary key of the dataset.
Definition: Transactor.cpp:634
void getIndexes(te::da::DataSetType *dt)
It update the DataSetType about the Indexes.
virtual char getChar(std::size_t i) const =0
Method for retrieving a signed character attribute value (1 byte long).
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
Definition: Transactor.cpp:353
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.
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
virtual boost::int64_t getInt64(std::size_t i) const =0
Method for retrieving a 64-bit integer attribute value (8 bytes long).
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
Definition: Transactor.cpp:400
std::auto_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
Definition: Transactor.cpp:260
void dropSequence(const std::string &name)
It removes the sequence from the data source.
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.
Definition: Transactor.cpp:814
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.
Definition: Transactor.cpp:367
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
std::size_t size() const
It returns the maximum number of characters for a varying string, or the number of characters for a f...
bool uniqueKeyExists(const std::string &datasetName, const std::string &name)
It checks if a unique key with the given name exists in the dataset.
Definition: Transactor.cpp:838
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the foreign key constraint.
Definition: ForeignKey.h:103
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:116
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
Definition: Transactor.cpp:386
std::vector< std::string > getUniqueKeyNames(const std::string &datasetName)
It gets the unique key names of the given dataset.
Definition: Transactor.cpp:824
A class that models the description of a dataset.
Definition: DataSetType.h:72
StringType
The subtype of string property.
Definition: Enums.h:107
void renameProperty(const std::string &datasetName, const std::string &propertyName, const std::string &newPropertyName)
It renames a property of the given dataset.
Definition: Transactor.cpp:606
void dropCheckConstraint(const std::string &datasetName, const std::string &name)
It removes the check constraint from the dataset.
Definition: Transactor.cpp:950
void insertIntoGeometryColumns(const std::string &datasetName, te::gm::GeometryProperty *geomProp)
It insert a geometry property in the geometry_clumns (SFS Schema).
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
std::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset.
Definition: Transactor.cpp:965
void addUniqueKey(const std::string &datasetName, te::da::UniqueKey *uk)
It adds a unique key constraint to the dataset.
Definition: Transactor.cpp:850
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.
Definition: PrimaryKey.h:123
It models a property definition.
Definition: Property.h:59
An static class with global definitions.
bool isInTransaction() const
It returns true if a transaction is in progress, otherwise, it returns false.
Definition: Transactor.cpp:140
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...
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
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.
Definition: Transactor.cpp:737
bool IsZProperty(te::gm::GeomType type)
Verifies whether Z property.
Definition: Utils.cpp:890
Connection * m_conn
The connection used by this transactor.
Definition: Transactor.h:324
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
Definition: Transactor.cpp:329
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
Definition: Transactor.cpp:457
void TESTHR(HRESULT hr)
Definition: Connection.cpp:38
int getType() const
It returns the property data type.
Definition: Property.h:143
std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
Definition: Transactor.cpp:274
std::auto_ptr< te::da::ForeignKey > getForeignKey(const std::string &datasetName, const std::string &name)
It retrieves the foreign key from the given dataset.
Definition: Transactor.cpp:713
bool isPropertyNameValid(const std::string &propertyName)
It checks if the given property name is valid.
Definition: Transactor.cpp:284
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
Definition: Transactor.cpp:269
const std::vector< te::dt::Property * > & getReferencedProperties() const
It returns the referenced properties (on the referenced DataSetType) of this foreign key constraint...
Definition: ForeignKey.h:128
virtual std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
PrimaryKey * getPrimaryKey() const
It returns the primary key associated to the dataset type.
Definition: DataSetType.h:214
A class that describes a check constraint.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the dataset schema.
The ADO driver.
Definition: DataSource.h:61
Geometric property.
DataSetType * getReferencedDataSetType() const
It returns the referenced DataSetType of this foreign key constraint.
Definition: ForeignKey.h:153
void begin()
It starts a new transaction.
Definition: Transactor.cpp:101
std::vector< std::string > getCheckConstraintNames(const std::string &datasetName)
It gets the check constraint names of the given dataset.
Definition: Transactor.cpp:921
An exception class for ADO.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that form the unique key.
Definition: UniqueKey.h:110
const std::string & GetGeometryName(te::gm::GeomType t)
It returns the geometry OGC names.
Definition: Utils.cpp:498
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:111
const std::map< std::string, std::string > & getConnectionInfo() const
It returns the set of parameters used to set up the access channel to the underlying repository...
Definition: DataSource.cpp:84
std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
Definition: Transactor.cpp:334
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
Definition: Transactor.cpp:127
A class that implements a connection to a ADO database.
Definition: Connection.h:60
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.
Definition: Transactor.cpp:145
#define TR_ADO(message)
It marks a string in order to get translated. This is a special mark used in the DataAccess module of...
Definition: Config.h:126