All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DataSourceTransactor.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 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/sqlite/DataSourceTransactor.cpp
22 
23  \brief An implementation of DataSourceTransactor class for the TerraLib SQLite Data Access Driver.
24 */
25 
26 // TerraLib
27 #include "../common/Globals.h"
28 #include "../common/Translator.h"
29 #include "../dataaccess/dataset/PrimaryKey.h"
30 #include "../dataaccess/datasource/ScopedTransaction.h"
31 #include "../dataaccess/query/Select.h"
32 #include "../dataaccess/utils/Utils.h"
33 #include "../geometry/Envelope.h"
34 #include "../geometry/GeometryProperty.h"
35 #include "../memory/DataSet.h"
36 #include "BatchExecutor.h"
37 #include "DataSource.h"
39 #include "DataSourceTransactor.h"
40 #include "EWKBSize.h"
41 #include "EWKBWriter.h"
42 #include "FwDataSet.h"
43 #include "PreparedQuery.h"
44 #include "SQLVisitor.h"
45 #include "Utils.h"
46 
47 // Boost
48 #include <boost/algorithm/string/case_conv.hpp>
49 #include <boost/format.hpp>
50 #include <boost/lexical_cast.hpp>
51 
52 // SQLite
53 #include <sqlite3.h>
54 
56 {
57  public:
58 
59  Impl(DataSource* parent, sqlite3* db);
60 
61  sqlite3_stmt* queryLite(const std::string& query);
62 
66 };
67 
69  : m_parent(parent),
70  m_db(db),
71  m_isInTransaction(false)
72 {
73 }
74 
76 {
77  sqlite3_stmt* stmt = 0;
78 
79  int ret = sqlite3_prepare_v2(m_db, query.c_str(), -1, &stmt, 0);
80 
81  if(ret != SQLITE_OK)
82  {
83  if(stmt)
84  sqlite3_finalize(stmt);
85 
86  throw te::common::Exception((boost::format(TR_COMMON("Could not excute the given query due to the following error: %1%.")) % sqlite3_errmsg(m_db)).str());
87  }
88 
89  return stmt;
90 }
91 
93  : m_pImpl(0)
94 {
95  m_pImpl = new Impl(parent, db);
96 }
97 
99 {
100  delete m_pImpl;
101 }
102 
104 {
105  return m_pImpl->m_parent;
106 }
107 
109 {
110  execute("BEGIN TRANSACTION");
111  m_pImpl->m_isInTransaction = true;
112 }
113 
115 {
116  m_pImpl->m_isInTransaction = false;
117  execute("COMMIT TRANSACTION");
118 }
119 
121 {
122  m_pImpl->m_isInTransaction = false;
123 
124  char* errmsg = 0;
125 
126  sqlite3_exec(m_pImpl->m_db, "ROLLBACK TRANSACTION", 0, 0, &errmsg);
127 }
128 
130 {
131  return m_pImpl->m_isInTransaction;
132 }
133 
134 std::auto_ptr<te::da::DataSet>
136  te::common::TraverseType travType,
137  bool connected,
138  const te::common::AccessPolicy accessPolicy)
139 {
140  std::string sql("SELECT * FROM ");
141  sql += name;
142 
143  return query(sql, travType, connected, accessPolicy);
144 }
145 
146 std::auto_ptr<te::da::DataSet>
148  const std::string& propertyName,
149  const te::gm::Envelope* e,
151  te::common::TraverseType travType,
152  bool connected,
153  const te::common::AccessPolicy accessPolicy)
154 {
155  if(e == 0)
156  throw te::common::Exception(TR_COMMON("The envelope is missing!"));
157 
158  if(propertyName.empty())
159  throw te::common::Exception(TR_COMMON("The property is missing!"));
160 
161 // TODO: we need to check if table has an spatial index before using this code!
162  std::string sql ("SELECT * FROM ");
163  sql += name;
164  sql += " WHERE ROWID IN (SELECT rowid FROM SpatialIndex WHERE f_table_name = '";
165  sql += boost::to_lower_copy(name) + "' AND f_geometry_column = '";
166  sql += boost::to_lower_copy(propertyName) + "' AND ";
167  sql += "search_frame = BuildMbr(" + boost::lexical_cast<std::string>(e->m_llx);
168  sql += ", " + boost::lexical_cast<std::string>(e->m_lly);
169  sql += ", " + boost::lexical_cast<std::string>(e->m_urx);
170  sql += ", " + boost::lexical_cast<std::string>(e->m_ury);
171  sql += "))";
172 
173  return query(sql, travType, connected, accessPolicy);
174 }
175 
176 std::auto_ptr<te::da::DataSet>
178  const std::string& propertyName,
179  const te::gm::Geometry* g,
181  te::common::TraverseType travType,
182  bool /*connected*/,
183  const te::common::AccessPolicy /*accessPolicy*/)
184 {
185  if(g == 0)
186  throw te::common::Exception(TR_COMMON("The geometry is missing!"));
187 
188  if(propertyName.empty())
189  throw te::common::Exception(TR_COMMON("The property is missing!"));
190 
191  const te::gm::Envelope* e = g->getMBR();
192 
193 // TODO: we need to check if table has an spatial index before using this code!
194  std::string sql ("SELECT * FROM ");
195  sql += name;
196  sql += " WHERE ";
197  sql += GetBindableSpatialRelation(propertyName, r);
198  sql += " AND ROWID IN (SELECT rowid FROM SpatialIndex WHERE f_table_name = '";
199  sql += boost::to_lower_copy(name) + "' AND f_geometry_column = '";
200  sql += boost::to_lower_copy(propertyName) + "' AND ";
201  sql += "search_frame = BuildMbr(" + boost::lexical_cast<std::string>(e->m_llx);
202  sql += ", " + boost::lexical_cast<std::string>(e->m_lly);
203  sql += ", " + boost::lexical_cast<std::string>(e->m_urx);
204  sql += ", " + boost::lexical_cast<std::string>(e->m_ury);
205  sql += "))";
206 
207  sqlite3_stmt* stmt = m_pImpl->queryLite(sql);
208 
209  std::size_t ewkbSize = EWKBSize::getEWKBSize(g);
210 
211  unsigned char* ewkb = new unsigned char[ewkbSize];
212 
213  EWKBWriter::write(g, ewkb, te::common::Globals::sm_machineByteOrder);
214 
215  int retval = sqlite3_bind_blob(stmt, 1, ewkb, ewkbSize, SQLITE_TRANSIENT);
216 
217  delete [] ewkb;
218 
219  if(retval != SQLITE_OK)
220  {
221  sqlite3_finalize(stmt);
222 
223  throw te::common::Exception(TR_COMMON("Could not bind geometry in the spatial filter!"));
224  }
225 
226  std::auto_ptr<te::da::DataSet> litedataset(new FwDataSet(stmt, this));
227 
228  if(travType == te::common::FORWARDONLY)
229  return litedataset;
230 
231  std::auto_ptr<te::da::DataSet> fatdataset(new te::mem::DataSet(*litedataset, true));
232 
233  return fatdataset;
234 }
235 
236 std::auto_ptr<te::da::DataSet>
238  te::common::TraverseType travType,
239  bool connected,
240  const te::common::AccessPolicy /*accessPolicy*/)
241 {
242  std::string sql;
243 
244  SQLVisitor visitor(*(m_pImpl->m_parent->getDialect()), sql);
245  q.accept(visitor);
246 
247  return query(sql, travType, connected);
248 }
249 
250 std::auto_ptr<te::da::DataSet>
252  te::common::TraverseType travType,
253  bool connected,
254  const te::common::AccessPolicy /*accessPolicy*/)
255 {
256  sqlite3_stmt* result = m_pImpl->queryLite(query);
257 
258  std::auto_ptr<te::da::DataSet> litedataset(new FwDataSet(result, this));
259 
260  if(travType == te::common::FORWARDONLY)
261  return litedataset;
262 
263  std::auto_ptr<te::da::DataSet> fatdataset(new te::mem::DataSet(*litedataset, true));
264 
265  return fatdataset;
266 }
267 
269 {
270  std::string sql;
271 
272  SQLVisitor visitor(*(m_pImpl->m_parent->getDialect()), sql);
273  command.accept(visitor);
274 
275  execute(sql);
276 }
277 
278 void te::sqlite::DataSourceTransactor::execute(const std::string& command)
279 {
280  char* errmsg = 0;
281 
282  int rc = sqlite3_exec(m_pImpl->m_db, command.c_str(), 0, 0, &errmsg);
283 
284  if(rc != SQLITE_OK)
285  {
286  boost::format msg(TR_COMMON("Could not execute the SQL command due to the following error: %1%."));
287 
288  msg = msg % errmsg;
289 
290  sqlite3_free(errmsg);
291 
292  throw te::common::Exception(msg.str());
293  }
294 }
295 
296 std::auto_ptr<te::da::PreparedQuery>
298 {
299  return std::auto_ptr<te::da::PreparedQuery>(new PreparedQuery(this, m_pImpl->m_db));
300 }
301 
302 std::auto_ptr<te::da::BatchExecutor> te::sqlite::DataSourceTransactor::getBatchExecutor()
303 {
304  return std::auto_ptr<te::da::BatchExecutor>(new BatchExecutor(this));
305 }
306 
308 {
309  sqlite3_interrupt(m_pImpl->m_db);
310 }
311 
313 {
314  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
315 }
316 
317 std::string te::sqlite::DataSourceTransactor::escape(const std::string& value)
318 {
319  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
320 }
321 
322 bool te::sqlite::DataSourceTransactor::isDataSetNameValid(const std::string& datasetName)
323 {
324  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
325 }
326 
327 bool te::sqlite::DataSourceTransactor::isPropertyNameValid(const std::string& propertyName)
328 {
329  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
330 }
331 
332 std::vector<std::string>
334 {
335  DataSourceCatalogLoader cloader(this);
336 
337  return cloader.getDataSetNames();
338 }
339 
341 {
342  return getDataSetNames().size();
343 }
344 
345 std::auto_ptr<te::da::DataSetType>
347 {
348  DataSourceCatalogLoader cloader(this);
349 
350  return std::auto_ptr<te::da::DataSetType>(cloader.getDataSetType(name));
351 }
352 
353 boost::ptr_vector<te::dt::Property>
354 te::sqlite::DataSourceTransactor::getProperties(const std::string& datasetName)
355 {
356  DataSourceCatalogLoader cloader(this);
357 
358  return cloader.getProperties(datasetName);
359 }
360 
361 std::auto_ptr<te::dt::Property>
362 te::sqlite::DataSourceTransactor::getProperty(const std::string& datasetName,
363  const std::string& name)
364 {
365  DataSourceCatalogLoader cloader(this);
366 
367  std::auto_ptr<te::da::DataSetType> dt(cloader.getDataSetType(datasetName));
368 
369  te::dt::Property* p = dt->getProperty(name);
370 
371  return std::auto_ptr<te::dt::Property>(p->clone());
372 }
373 
374 std::auto_ptr<te::dt::Property> te::sqlite::DataSourceTransactor::getProperty(const std::string& datasetName, std::size_t propertyPos)
375 {
376  DataSourceCatalogLoader cloader(this);
377 
378  std::auto_ptr<te::da::DataSetType> dt(cloader.getDataSetType(datasetName));
379 
380  te::dt::Property* p = dt->getProperty(propertyPos);
381 
382  return std::auto_ptr<te::dt::Property>(p->clone());
383 }
384 
385 std::vector<std::string> te::sqlite::DataSourceTransactor::getPropertyNames(const std::string& datasetName)
386 {
387  DataSourceCatalogLoader cloader(this);
388 
389  std::auto_ptr<te::da::DataSetType> dt(cloader.getDataSetType(datasetName));
390 
391  std::vector<std::string> pnames;
392 
393  for(std::size_t i = 0; i != dt->size(); ++i)
394  pnames.push_back(dt->getProperty(i)->getName());
395 
396  return pnames;
397 }
398 
399 std::size_t te::sqlite::DataSourceTransactor::getNumberOfProperties(const std::string& datasetName)
400 {
401  DataSourceCatalogLoader cloader(this);
402 
403  std::auto_ptr<te::da::DataSetType> dt(cloader.getDataSetType(datasetName));
404 
405  return dt->size();
406 }
407 
408 bool te::sqlite::DataSourceTransactor::propertyExists(const std::string& datasetName, const std::string& name)
409 {
410  DataSourceCatalogLoader cloader(this);
411 
412  std::auto_ptr<te::da::DataSetType> dt(cloader.getDataSetType(datasetName));
413 
414  return dt->getProperty(name) != 0;
415 }
416 
417 void te::sqlite::DataSourceTransactor::addProperty(const std::string& datasetName, te::dt::Property* p)
418 {
419  std::string sql;
420 
421  if(p->getType() == te::dt::GEOMETRY_TYPE)
422  {
423  te::gm::GeometryProperty* gp = static_cast<te::gm::GeometryProperty*>(p);
424 
425  std::string gtype;
426  std::string cdim;
427 
428  Convert2SpatiaLiteGeom(gp->getGeometryType(), gtype, cdim);
429 
430  sql = "SELECT AddGeometryColumn('";
431 
432  sql += boost::to_lower_copy(datasetName);
433  sql += "', '";
434  sql += boost::to_lower_copy(p->getName());
435  sql += "', ";
436  sql += boost::lexical_cast<std::string>(gp->getSRID());
437  sql += ", '";
438  sql += gtype;
439  sql += "', '";
440  sql += cdim;
441 
442  if(gp->isRequired())
443  sql += "', 1)";
444  else
445  sql += "')";
446  }
447  else
448  {
449  sql = "ALTER TABLE ";
450  sql += boost::to_lower_copy(datasetName);
451  sql += " ADD COLUMN ";
452  sql += boost::to_lower_copy(p->getName());
453  sql += " ";
454  sql += GetSQLType(p);
455  }
456 
457  execute(sql);
458 }
459 
460 void te::sqlite::DataSourceTransactor::dropProperty(const std::string& datasetName, const std::string& name)
461 {
462  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
463 }
464 
465 void te::sqlite::DataSourceTransactor::renameProperty(const std::string& datasetName,
466  const std::string& propertyName,
467  const std::string& newPropertyName)
468 {
469  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
470 }
471 
472 std::auto_ptr<te::da::PrimaryKey> te::sqlite::DataSourceTransactor::getPrimaryKey(const std::string& datasetName)
473 {
474  DataSourceCatalogLoader cloader(this);
475 
476  std::auto_ptr<te::da::DataSetType> dt(cloader.getDataSetType(datasetName));
477 
478  return std::auto_ptr<te::da::PrimaryKey>(static_cast<te::da::PrimaryKey*>(dt->getPrimaryKey()->clone()));
479 }
480 
481 bool te::sqlite::DataSourceTransactor::primaryKeyExists(const std::string& datasetName, const std::string& name)
482 {
483  std::string sql = "PRAGMA table_info(";
484  sql += datasetName;
485  sql += ")";
486 
487  std::auto_ptr<te::da::DataSet> attributes(query(sql));
488 
489  while(attributes->moveNext())
490  {
491  bool isPK = attributes->getInt32(5) != 0;
492 
493  if(isPK)
494  return true;
495  }
496 
497  return false;
498 }
499 
501 {
502 // TO BE CONFIRMED: SQLite doesn't support to alter a table to add a primary key. This must be done during table creation!
503  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
504 }
505 
506 void te::sqlite::DataSourceTransactor::dropPrimaryKey(const std::string& datasetName)
507 {
508  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
509 }
510 
511 std::auto_ptr<te::da::ForeignKey> te::sqlite::DataSourceTransactor::getForeignKey(const std::string& datasetName, const std::string& name)
512 {
513  std::string sql("PRAGMA foreign_key_list(");
514  sql += datasetName;
515  sql += ")";
516 
517  std::auto_ptr<te::da::DataSet> result(query(sql));
518 
519  int id = boost::lexical_cast<int>(name);
520 
521  std::auto_ptr<te::da::ForeignKey> fk(new te::da::ForeignKey(name, id));
522 
523  while(result->moveNext())
524  {
525  if(id != result->getInt32(0))
526  continue;
527 
528  std::string onUpdate = result->getString(5);
529  std::string onDeletion = result->getString(6);
530 
531  fk->setOnUpdateAction(GetAction(onUpdate));
532  fk->setOnDeleteAction(GetAction(onDeletion));
533 
534  //std::string from = result->getString(3);
535  //std::string to = result->getString(4);
536 
537  //te::dt::Property* fromP = dt->getProperty(from);
538  //te::dt::Property* toP = dt->getProperty(to);
539 
540  //fk->add(fromP);
541  //fk->addRefProperty(toP);
542  }
543 
544  return fk;
545 }
546 
547 std::vector<std::string> te::sqlite::DataSourceTransactor::getForeignKeyNames(const std::string& datasetName)
548 {
549  std::string sql("PRAGMA foreign_key_list(");
550  sql += datasetName;
551  sql += ")";
552 
553  std::auto_ptr<te::da::DataSet> result(query(sql));
554 
555  int id = -1;
556 
557  std::vector<std::string> fkNames;
558 
559  while(result->moveNext())
560  {
561  int fkid = result->getInt32(0);
562 
563  if(fkid != id)
564  {
565  std::string fkname = boost::lexical_cast<std::string>(result->getInt32(0));
566 
567  fkNames.push_back(fkname);
568 
569  id = fkid;
570  }
571  }
572 
573  return fkNames;
574 }
575 
576 bool te::sqlite::DataSourceTransactor::foreignKeyExists(const std::string& datasetName, const std::string& name)
577 {
578  std::string sql("PRAGMA foreign_key_list(");
579  sql += datasetName;
580  sql += ")";
581 
582  std::auto_ptr<te::da::DataSet> result(query(sql));
583 
584  while(result->moveNext())
585  {
586  if(name == boost::lexical_cast<std::string>(result->getInt32(0)))
587  return true;
588  }
589 
590  return false;
591 }
592 
594 {
595  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
596 }
597 
598 void te::sqlite::DataSourceTransactor::dropForeignKey(const std::string& datasetName, const std::string& fkName)
599 {
600  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
601 }
602 
603 std::auto_ptr<te::da::UniqueKey> te::sqlite::DataSourceTransactor::getUniqueKey(const std::string& /*datasetName*/, const std::string& /*name*/)
604 {
605  throw te::common::Exception(TR_COMMON("SQLITE: not implementable yet!"));
606 
607 // std::string sql("PRAGMA index_info(");
608 // sql += name;
609 // sql += ")";
610 //
611 // std::auto_ptr<te::da::DataSet> indexInfo(query(sql));
612 //
613 // std::auto_ptr<te::da::UniqueKey> uk(new te::da::UniqueKey(name));
614 //
615 // while(indexInfo->moveNext())
616 // {
617 // int col = indexInfo->getInt32(1);
618 // //te::dt::Property* p = dt->getProperty(col);
619 // //uk->add(p);
620 // }
621 //
622 //// we need to check if uk is instead a primary key
623 // sql = "PRAGMA table_info(";
624 // sql += datasetName;
625 // sql += ")";
626 //
627 // std::auto_ptr<te::da::DataSet> attributes(query(sql));
628 //
629 // std::size_t nMatchAttributes = 0;
630 // bool mayBePK = true;
631 //
632 // while(mayBePK && attributes->moveNext())
633 // {
634 // bool isPK = attributes->getInt32(5) != 0;
635 //
636 // if(!isPK)
637 // continue;
638 //
639 // int col = attributes->getInt32(0);
640 // //te::dt::Property* p = dt->getProperty(col);
641 //
642 // //if(uk->has(p))
643 // // ++nMatchAttributes;
644 // //else
645 // // mayBePK = false; // we have find a key from pk that is not in uk!
646 // }
647 //
648 // if(mayBePK && (nMatchAttributes == uk->getProperties().size()))
649 // throw te::common::Exception(TR_COMMON("The searched key is not a unique key. It is the primary key."));
650 //
651 // return uk;
652 }
653 
654 std::vector<std::string> te::sqlite::DataSourceTransactor::getUniqueKeyNames(const std::string& datasetName)
655 {
656  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
657 }
658 
659 bool te::sqlite::DataSourceTransactor::uniqueKeyExists(const std::string& datasetName, const std::string& name)
660 {
661  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
662 }
663 
664 void te::sqlite::DataSourceTransactor::addUniqueKey(const std::string& datasetName, te::da::UniqueKey* uk)
665 {
666  std::string ukname = uk->getName();
667 
668  std::string sql = "CREATE UNIQUE INDEX IF NOT EXISTS ";
669  sql += ukname;
670  sql += " ON ";
671  sql += datasetName;
672  sql += "(";
673 
674  std::size_t size = uk->getProperties().size();
675 
676  for(std::size_t i = 0; i < size; ++i)
677  {
678  if(i != 0)
679  sql += ", ";
680 
681  sql += uk->getProperties()[i]->getName();
682  }
683 
684  sql += ")";
685 
686  execute(sql);
687 }
688 
689 void te::sqlite::DataSourceTransactor::dropUniqueKey(const std::string& datasetName, const std::string& name)
690 {
691  std::string ukname = name;
692 
693  std::size_t pos = ukname.find(".");
694 
695  if(pos != std::string::npos)
696  ukname = ukname.substr(pos + 1);
697 
698  std::string sql = "DROP INDEX IF EXISTS ";
699  sql += ukname;
700 
701  execute(sql);
702 }
703 
704 std::auto_ptr<te::da::CheckConstraint> te::sqlite::DataSourceTransactor::getCheckConstraint(const std::string& datasetName, const std::string& name)
705 {
706  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
707 }
708 
709 std::vector<std::string> te::sqlite::DataSourceTransactor::getCheckConstraintNames(const std::string& datasetName)
710 {
711  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
712 }
713 
714 bool te::sqlite::DataSourceTransactor::checkConstraintExists(const std::string& datasetName, const std::string& name)
715 {
716  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
717 }
718 
720 {
721  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
722 }
723 
724 void te::sqlite::DataSourceTransactor::dropCheckConstraint(const std::string& datasetName, const std::string& name)
725 {
726  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
727 }
728 
729 std::auto_ptr<te::da::Index> te::sqlite::DataSourceTransactor::getIndex(const std::string& datasetName, const std::string& name)
730 {
731  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
732 }
733 
734 std::vector<std::string> te::sqlite::DataSourceTransactor::getIndexNames(const std::string& datasetName)
735 {
736  throw;
737  //std::string sql("PRAGMA index_list(");
738  // sql += datasetName;
739  // sql += ")";
740 
741  //std::vector<std::string> idxs;
742 
743  //std::auto_ptr<te::da::DataSet> indexes(query(sql));
744 
745  //while(indexes->moveNext())
746  //{
747  // int idxId = indexes->getInt32(0);
748 
749  // std::string idxName = indexes->getString(1);
750 
751  // bool isUnique = indexes->getInt32(2) != 0;
752 
753  // if(isUnique && (idxName.find("sqlite_autoindex_") != std::string::npos))
754  // continue;
755 
756  // idxs.push_back(idxName);
757  //}
758 
759  //std::string sql = "SELECT f_table_name, f_geometry_column "
760  // "FROM views_geometry_columns "
761  // "WHERE view_name = '";
762  // sql += tname;
763  // sql += "' AND view_geometry = '";
764  // sql += gcol;
765  // sql += "'";
766 
767  // std::auto_ptr<te::da::DataSet> feature(m_t->query(sql));
768 
769  // if(!feature->moveNext())
770  // return;
771 
772  // tname = feature->getString(0);
773  // gcol = feature->getString(1);
774  // }
775 
776  // std::auto_ptr<te::da::DataSet> ftable(getGeometryInfo(tname, gcol));
777 
778  // if(!ftable->moveNext())
779  // continue;
780 
781  // bool hasSPIDX = ftable->getInt32(3) != 0;
782 
783  // if(hasSPIDX)
784  // {
785  // te::da::Index* idx = new te::da::Index(dt->getName() + ".idx_" + tname + "_" + gcol, te::da::R_TREE_TYPE, dt, 0);
786  // idx->add(dt->getProperty(i));
787  // }
788  // }
789  //}
790 }
791 
792 bool te::sqlite::DataSourceTransactor::indexExists(const std::string& datasetName, const std::string& name)
793 {
794  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
795 }
796 
797 void te::sqlite::DataSourceTransactor::addIndex(const std::string& datasetName,
798  te::da::Index* idx,
799  const std::map<std::string, std::string>& options)
800 {
801 // rename index if needed in order to preserve table name
802  std::string idxname = idx->getName();
803 
804  std::string sql;
805 
806  if(idx->getIndexType() == te::da::B_TREE_TYPE)
807  {
808  sql = "CREATE ";
809 
810  //if(isunique)
811  // sql += "UNIQUE ";
812 
813  sql += "INDEX IF NOT EXISTS ";
814  sql += idxname;
815  sql += " ON ";
816  sql += datasetName;
817  sql += "(";
818 
819  std::size_t size = idx->getProperties().size();
820 
821  for(std::size_t i = 0; i < size; ++i)
822  {
823  if(i != 0)
824  sql += ", ";
825 
826  sql += idx->getProperties()[i]->getName();
827  }
828 
829  sql += ")";
830  }
831  else if(idx->getIndexType() == te::da::R_TREE_TYPE)
832  {
833  if(idx->getProperties().size() != 1)
834  throw te::common::Exception(TR_COMMON("In order to create a spatial index you must inform just one spatial column in index definition!"));
835 
836  sql = "SELECT CreateSpatialIndex('";
837  sql += datasetName;
838  sql += "', '";
839  sql += idx->getProperties()[0]->getName();
840  sql += "')";
841  }
842 
843  execute(sql);
844 }
845 
846 void te::sqlite::DataSourceTransactor::dropIndex(const std::string& datasetName, const std::string& idxName)
847 {
848  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
849 // std::string sql;
850 //
851 // if(index->getIndexType() == te::da::R_TREE_TYPE)
852 // {
853 //// first we need to disable the index
854 // sql = "SELECT DisableSpatialIndex('";
855 // sql += dt->getName();
856 // sql += "', '";
857 // sql += index->getProperties()[0]->getName();
858 // sql += "')";
859 //
860 // m_t->execute(sql);
861 //
862 //// then we can drop it... but r-tree is a virtual table!
863 // sql = "DROP TABLE ";
864 // sql += idxname;
865 // }
866 // else
867 // {
868 // sql = "DROP INDEX ";
869 // sql += idxName;
870 // }
871 //
872 // execute(sql);
873 }
874 
875 std::auto_ptr<te::da::Sequence> te::sqlite::DataSourceTransactor::getSequence(const std::string& name)
876 {
877  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
878 }
879 
881 {
882  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
883 }
884 
886 {
887  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
888 }
889 
891 {
892  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
893 }
894 
896 {
897  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
898 }
899 
900 std::auto_ptr<te::gm::Envelope> te::sqlite::DataSourceTransactor::getExtent(const std::string& datasetName,
901  const std::string& propertyName)
902 {
903  DataSourceCatalogLoader cloader(this);
904 
905  return std::auto_ptr<te::gm::Envelope>(cloader.getExtent(datasetName, propertyName));
906 }
907 
908 std::auto_ptr<te::gm::Envelope> te::sqlite::DataSourceTransactor::getExtent(const std::string& datasetName,
909  std::size_t propertyPos)
910 {
911  DataSourceCatalogLoader cloader(this);
912 
913  std::auto_ptr<te::da::DataSetType> dt(cloader.getDataSetType(datasetName));
914 
915  return std::auto_ptr<te::gm::Envelope>(cloader.getExtent(datasetName, dt->getProperty(propertyPos)->getName()));
916 }
917 
918 std::size_t te::sqlite::DataSourceTransactor::getNumberOfItems(const std::string& datasetName)
919 {
920  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
921 }
922 
924 {
925  DataSourceCatalogLoader cloader(this);
926 
927  return cloader.hasDataSets();
928 }
929 
931 {
932  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
933 }
934 
936  const std::map<std::string, std::string>& options)
937 {
938  const std::size_t nproperties = dt->size();
939 
940  if(nproperties == 0)
941  throw te::common::Exception(TR_COMMON("SQLite doesn't support empty table definition!"));
942 
943  std::string sql = "CREATE TABLE ";
944  sql += dt->getName();
945  sql += "(";
946 
947  for(std::size_t i = 0; i < nproperties; ++i)
948  {
949  const te::dt::Property* p = dt->getProperty(i);
950 
951  if(i != 0)
952  sql += ", ";
953 
954  sql += Convert2SQLCreate(p);
955  }
956 
957 // we need to add compound primary keys
958  if(dt->getPrimaryKey() && (dt->getPrimaryKey()->getProperties().size() > 1))
959  {
960  sql += ", PRIMARY KEY(";
961 
962  const std::size_t nkeys = dt->getPrimaryKey()->getProperties().size();
963 
964  for(std::size_t i = 0; i < nkeys; ++i)
965  {
966  if(i != 0)
967  sql += ", ";
968 
969  sql += dt->getPrimaryKey()->getProperties()[i]->getName();
970  }
971 
972  sql += ")";
973  }
974 
975 // we need to add fks during table creation!
976  std::size_t nfks = dt->getNumberOfForeignKeys();
977 
978  for(std::size_t i = 0; i < nfks; ++i)
979  {
980  te::da::ForeignKey* fk = dt->getForeignKey(i);
981 
982  fk->setName(dt->getName() + "." + boost::lexical_cast<std::string>(i));
983 
984  if(i != 0)
985  sql += ", ";
986 
987  sql += "FOREIGN KEY(";
988 
989  const std::size_t nkeys = fk->getProperties().size();
990 
991  for(std::size_t j = 0; j < nkeys; ++j)
992  {
993  if(j != 0)
994  sql += ", ";
995 
996  sql += fk->getProperties()[j]->getName();
997  }
998 
999  sql += ") REFERENCES ";
1000 
1001  sql += fk->getReferencedDataSetType()->getName();
1002 
1003  sql += "(";
1004 
1005  for(std::size_t j = 0; j < nkeys; ++j)
1006  {
1007  if(j != 0)
1008  sql += ", ";
1009 
1010  sql += fk->getReferencedProperties()[j]->getName();
1011  }
1012 
1013  sql += ")";
1014  }
1015 
1016  sql += ")";
1017 
1018  execute(sql);
1019 
1020 // register geometry metadata
1021  for(std::size_t i = 0; i < nproperties; ++i)
1022  {
1023  const te::dt::Property* p = dt->getProperty(i);
1024 
1025  if(p->getType() != te::dt::GEOMETRY_TYPE)
1026  continue;
1027 
1028  const te::gm::GeometryProperty* gp = static_cast<const te::gm::GeometryProperty*>(p);
1029 
1030  std::string gtype;
1031  std::string cdim;
1032 
1033  Convert2SpatiaLiteGeom(gp->getGeometryType(), gtype, cdim);
1034 
1035  sql = "SELECT RecoverGeometryColumn('";
1036  sql += dt->getName();
1037  sql += "', '";
1038  sql += gp->getName();
1039  sql += "', ";
1040  sql += boost::lexical_cast<std::string>(gp->getSRID());
1041  sql += ", '";
1042  sql += gtype;
1043  sql += "', '";
1044  sql += cdim;
1045  sql += "')";
1046 
1047  execute(sql);
1048  }
1049 
1050 // add unique keys
1051  //std::size_t nukeys = dt->getNumberOfUniqueKeys();
1052 
1053  //for(std::size_t i = 0; i < nukeys; ++i)
1054  // add(dt->getName(), dt->getUniqueKey(i));
1055 
1056 // add indexes... just if no primary key or unique key with the same name exists!
1057  //std::size_t nidxs = dt->getNumberOfIndexes();
1058 
1059  //for(std::size_t i = 0; i < nidxs; ++i)
1060  // add(dt, dt->getIndex(i), options);
1061 
1062 //// add constraints
1063 // std::size_t nccs = dt->getNumberOfCheckConstraints();
1064 //
1065 // for(std::size_t i = 0; i < nccs; ++i)
1066 // add(dt, dt->getCheckConstraint(i));
1067 }
1068 
1070  const std::string& cloneName,
1071  const std::map<std::string, std::string>& options)
1072 {
1073  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
1074 }
1075 
1077 {
1078  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
1079 }
1080 
1081 void te::sqlite::DataSourceTransactor::renameDataSet(const std::string& name, const std::string& newName)
1082 {
1083  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
1084 }
1085 
1086 void te::sqlite::DataSourceTransactor::add(const std::string& datasetName,
1087  te::da::DataSet* d,
1088  const std::map<std::string, std::string>& options,
1089  std::size_t limit)
1090 {
1091  if(limit == 0)
1092  limit = std::string::npos;
1093 
1094  std::string sql = "INSERT INTO ";
1095  sql += datasetName;
1096  sql += te::da::GetSQLValueNames(d);
1097  sql += " VALUES";
1098  sql += GetSQLBindValues(d);
1099 
1100  te::da::ScopedTransaction st(*this);
1101 
1102  std::auto_ptr<PreparedQuery> pq(new PreparedQuery(this, m_pImpl->m_db));
1103 
1104  pq->prepare(sql);
1105 
1106  std::size_t nProcessedRows = 0;
1107 
1108  //do
1109  while(d->moveNext())
1110  {
1111  pq->bind(d);
1112  pq->execute();
1113 
1114  ++nProcessedRows;
1115 
1116  }//while(d->moveNext() && (nProcessedRows != limit));
1117 
1118  st.commit();
1119 }
1120 
1121 void te::sqlite::DataSourceTransactor::remove(const std::string& datasetName, const te::da::ObjectIdSet* oids)
1122 {
1123  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
1124 }
1125 
1126 void te::sqlite::DataSourceTransactor::update(const std::string& datasetName,
1127  te::da::DataSet* dataset,
1128  const std::vector<std::size_t>& properties,
1129  const te::da::ObjectIdSet* oids,
1130  const std::map<std::string, std::string>& options,
1131  std::size_t limit)
1132 {
1133  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
1134 }
1135 
1136 void te::sqlite::DataSourceTransactor::optimize(const std::map<std::string, std::string>& opInfo)
1137 {
1138  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
1139 }
1141 {
1142  throw te::common::Exception(TR_COMMON("SQLITE: Not implemented yet!"));
1143 }
virtual void setName(const std::string &name)
It sets the constraint name.
Definition: Constraint.h:126
Property * getProperty(std::size_t i) const
It returns the i-th property.
te::da::DataSetType * getDataSetType(const std::string &datasetName)
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset.
std::auto_ptr< te::da::Sequence > getSequence(const std::string &name)
It gets the sequence with the given name in 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.
Geometric property.
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.
A visitor for building an SQL statement using SQLite dialect.
void Convert2SpatiaLiteGeom(const te::gm::GeomType t, std::string &geomType, std::string &dimension)
Definition: Utils.cpp:623
Utility functions for the data access module.
void addCheckConstraint(const std::string &datasetName, te::da::CheckConstraint *cc)
It adds a check constraint to the dataset.
struct sqlite3 sqlite3
void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset.
Impl(DataSource *parent, sqlite3 *db)
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.
~DataSourceTransactor()
Virtual destructor.
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.
DataSourceTransactor()
Default constructor that can be called by subclasses.
A class that models the description of a dataset.
Definition: DataSetType.h:72
DataSourceCatalogLoader manages metadata information for the TerraLib SQLite Data Access Driver...
std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids=0)
It removes all the informed items from the dataset.
bool isDataSetNameValid(const std::string &datasetName)
It returns true if the given string is a valid dataset name.
bool isInTransaction() const
It returns true if a transaction is in progress, otherwise, it returns false.
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.
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
static const MachineByteOrder sm_machineByteOrder
A flag that indicates the machine byte order (Big Endian or Little Endian).
Definition: Globals.h:54
PrimaryKey * getPrimaryKey() const
It returns the primary key associated to the dataset type.
Definition: DataSetType.h:214
An utility class to coordinate transactions.
std::vector< std::string > getUniqueKeyNames(const std::string &datasetName)
It gets the unique key names of the given dataset.
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
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.
std::auto_ptr< te::da::DataSet > query(const te::da::Select &q, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It executes a query that may return some data using a generic query. A dataset can be connected or di...
It describes a sequence (a number generator).
Definition: Sequence.h:56
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.
TEDATAACCESSEXPORT std::string GetSQLValueNames(const DataSetType *dt)
Definition: Utils.cpp:670
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
std::string Convert2SQLCreate(const te::dt::Property *p)
Definition: Utils.cpp:848
void dropSequence(const std::string &name)
It removes the sequence from the data source.
A class that describes a check constraint.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:118
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
std::auto_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema.
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
It models a property definition.
Definition: Property.h:59
A class that implements a prepared query for the TerraLib SQLite Data Access Driver.
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...
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
Definition: PrimaryKey.h:109
void commit()
It commits the transaction.
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
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 begin()
It starts a new transaction.
bool indexExists(const std::string &datasetName, const std::string &name)
It checks if an index with the given name exists in the dataset.
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:40
bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset.
TraverseType
A dataset can be traversed in two ways:
Definition: Enums.h:53
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
Definition: DataSet.h:65
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema.
std::size_t getNumberOfForeignKeys() const
It returns the number of foreign keys defined for the dataset type.
Definition: DataSetType.h:467
void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the dataset schema.
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.
int getSRID() const
It returns the spatial reference system identifier associated to this property.
void addPrimaryKey(const std::string &datasetName, te::da::PrimaryKey *pk)
It adds a primary key constraint to the dataset schema.
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
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.
A class that helps to determine the size of a SpatiaLite geometry.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
sqlite3_stmt * queryLite(const std::string &query)
void addSequence(te::da::Sequence *sequence)
It creates a new sequence in the data source.
std::vector< std::string > getCheckConstraintNames(const std::string &datasetName)
It gets the check constraint names of the given dataset.
bool isPropertyNameValid(const std::string &propertyName)
It checks if the given property name is valid.
DataSetType * getReferencedDataSetType() const
It returns the referenced DataSetType of this foreign key constraint.
Definition: ForeignKey.h:153
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.
std::string GetSQLType(const te::dt::Property *p)
Definition: Utils.cpp:769
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:50
bool hasDataSets()
It checks if the data source has any dataset.
bool isRequired() const
It returns true if the attribute is required, otherwise it returns false.
bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source.
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
te::gm::Envelope * getExtent(const std::string &tableName, const std::string &geomColName)
std::size_t size() const
It returns the number of properties of the CompositeProperty.
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
void execute(const te::da::Query &command)
It executes the specified command using a generic query representation.
A class that implements a prepared query for the TerraLib SQLite Data Access Driver.
Definition: PreparedQuery.h:68
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
std::auto_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName)
It retrieves the primary key of the dataset.
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
std::string GetBindableSpatialRelation(const std::string &colName, const te::gm::SpatialRelation r)
Definition: Utils.cpp:574
A class that serializes a geometry to the SpatiaLite EWKB format.
A visitor for building an SQL statement using SQLite dialect.
Definition: SQLVisitor.h:44
int getType() const
It returns the property data type.
Definition: Property.h:161
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
void addForeignKey(const std::string &datasetName, te::da::ForeignKey *fk)
It adds a foreign key constraint to a dataset.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that form the unique key.
Definition: UniqueKey.h:110
ForeignKey * getForeignKey(std::size_t i) const
It returns the i-th foreign key associated to the dataset type.
Definition: DataSetType.h:480
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the index.
Definition: Index.h:183
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source.
void dropCheckConstraint(const std::string &datasetName, const std::string &name)
It removes the check constraint from the dataset.
std::vector< std::string > getDataSetNames()
std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset.
std::auto_ptr< te::gm::Envelope > getExtent(const std::string &datasetName, const std::string &propertyName)
It retrieves the bounding rectangle of the spatial property for the given dataset.
std::auto_ptr< te::da::ForeignKey > getForeignKey(const std::string &datasetName, const std::string &name)
It retrieves the foreign key from the given dataset.
void renameProperty(const std::string &datasetName, const std::string &propertyName, const std::string &newPropertyName)
It renames a property of the given dataset.
Implements the DataSource class for the SQLite Data Access Driver.
struct sqlite3_stmt sqlite3_stmt
Definition: FwDataSet.h:35
std::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset.
void addUniqueKey(const std::string &datasetName, te::da::UniqueKey *uk)
It adds a unique key constraint to the dataset.
An implementation of DataSourceTransactor class for the TerraLib SQLite Data Access Driver...
void commit()
It commits the transaction.
std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
std::string GetSQLBindValues(const te::da::DataSet *dataset)
Definition: Utils.cpp:874
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.
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
virtual const std::string & getName() const
It returns the constraint name.
Definition: Constraint.h:119
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.
te::da::FKActionType GetAction(const std::string &action)
Definition: Utils.cpp:824
IndexType getIndexType() const
It gets the index type.
Definition: Index.h:169
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the foreign key constraint.
Definition: ForeignKey.h:103
static std::size_t getEWKBSize(const te::gm::Geometry *g)
Definition: EWKBSize.cpp:49
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
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
Definition: Geometry.cpp:104
void cancel()
It requests that the data source stop the processing of the current command.
bool uniqueKeyExists(const std::string &datasetName, const std::string &name)
It checks if a unique key with the given name exists in the dataset.
Implementation of the BatchExecutor class for the TerraLib SQLite Data Access driver.
A Query is independent from the data source language/dialect.
Definition: Query.h:46
It describes an index associated to a DataSetType.
Definition: Index.h:54
Implementation of a forward-only dataset for the TerraLib SQLite Data Access driver.
const std::string & getName() const
It returns the property name.
Definition: Property.h:127
const std::string & getName() const
It returns the index name.
Definition: Index.h:155