27 #include "../common/Exception.h" 28 #include "../core/translator/Translator.h" 29 #include "../dataaccess/dataset/CheckConstraint.h" 30 #include "../dataaccess/dataset/DataSet.h" 31 #include "../dataaccess/dataset/ForeignKey.h" 32 #include "../dataaccess/dataset/Index.h" 33 #include "../dataaccess/dataset/ObjectIdSet.h" 34 #include "../dataaccess/dataset/PrimaryKey.h" 35 #include "../dataaccess/dataset/Sequence.h" 36 #include "../dataaccess/dataset/UniqueKey.h" 37 #include "../dataaccess/datasource/DataSourceCatalog.h" 38 #include "../dataaccess/datasource/ScopedTransaction.h" 39 #include "../dataaccess/query/Select.h" 40 #include "../dataaccess/query/SQLDialect.h" 41 #include "../dataaccess/utils/Utils.h" 42 #include "../datatype/Array.h" 43 #include "../datatype/Date.h" 44 #include "../datatype/DateTimeProperty.h" 45 #include "../datatype/Property.h" 46 #include "../datatype/SimpleData.h" 47 #include "../datatype/StringProperty.h" 48 #include "../geometry/Envelope.h" 49 #include "../geometry/GeometryProperty.h" 50 #include "../geometry/Utils.h" 51 #include "../geometry/Geometry.h" 52 #include "../memory/DataSet.h" 67 #include <boost/format.hpp> 68 #include <boost/lexical_cast.hpp> 71 #import "msado15.dll" \
72 no_namespace rename(
"EOF",
"EndOfFile")
83 if(name ==
"lower_x" ||
94 m_isInTransaction(false)
160 std::string sql(
"SELECT * FROM ");
163 return query(sql, travType, connected, accessPolicy);
177 std::string lowerX =
"lower_x";
178 std::string upperX =
"upper_x";
179 std::string lowerY =
"lower_y";
180 std::string upperY =
"upper_y";
182 std::string q(
"SELECT * FROM " + name +
" WHERE ");
184 q +=
"NOT("+ lowerX +
" >= " + boost::lexical_cast<std::string>(e->
m_urx) +
" OR ";
185 q += upperX +
" <= " + boost::lexical_cast<std::string>(e->
m_llx) +
" OR ";
186 q += lowerY +
" >= " + boost::lexical_cast<std::string>(e->
m_ury) +
" OR ";
187 q += upperY +
" <= " + boost::lexical_cast<std::string>(e->
m_lly) +
")";
189 return query(q, travType, connected, accessPolicy);
223 return query(sql, travType);
231 _RecordsetPtr result =
m_conn->
query(query, connected);
233 std::unique_ptr<te::da::DataSet> dset(
new DataSet(
this, result));
289 std::vector<std::string> datasets;
291 ADOX::_CatalogPtr pCatalog = 0;
293 TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
297 pCatalog->PutActiveConnection(variant_t((IDispatch *)
m_conn->
getConn()));
299 ADOX::TablesPtr tables = pCatalog->GetTables();
301 for(
long i = 0; i < tables->GetCount(); ++i)
303 ADOX::_TablePtr table = tables->GetItem(i);
304 std::string tableName = table->GetName();
306 std::string tabletype = table->GetType();
308 if(table->GetType() == _bstr_t(
"ACCESS TABLE") ||
309 table->GetType() == _bstr_t(
"LINK") ||
310 table->GetType() == _bstr_t(
"PASS-THROUGH") ||
311 table->GetType() == _bstr_t(
"SYSTEM TABLE") ||
312 table->GetType() == _bstr_t(
"VIEW") ||
313 table->GetType() == _bstr_t(
"GLOBAL TEMPORARY") ||
314 tableName ==
"geometry_columns")
317 datasets.push_back(std::string(table->GetName()));
356 std::vector<te::dt::Property*> dtProperties = dt->getProperties();
358 boost::ptr_vector<te::dt::Property> properties;
360 for(std::size_t i = 0; i < dtProperties.size(); ++i)
361 properties.push_back(dtProperties[i]->clone());
369 throw te::common::Exception((boost::format(
TE_TR(
"The dataset \"%1%\" has no property with this name \"%2%\"!")) % datasetName % name).str());
373 return std::unique_ptr<te::dt::Property>(dt->getProperty(name)->clone());
380 assert(propertyPos < dt->size());
382 return std::unique_ptr<te::dt::Property>(dt->getProperty(propertyPos)->clone());
389 std::vector<std::string> pNames;
391 std::size_t numProperties = dt->size();
393 for(std::size_t i = 0; i < numProperties; ++i)
394 pNames.push_back(dt->getProperty(i)->getName());
408 std::vector<std::string> datasets;
410 ADOX::_CatalogPtr pCatalog = 0;
412 TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
416 pCatalog->PutActiveConnection(variant_t((IDispatch *)
m_conn->
getConn()));
418 ADOX::TablesPtr tables = pCatalog->GetTables();
420 ADOX::_TablePtr table;
422 for(
long i = 0; i < tables->GetCount(); ++i)
425 table = tables->GetItem(i);
426 std::string tableName = table->GetName();
428 if(tableName == datasetName)
436 ADOX::ColumnsPtr cols = table->GetColumns();
438 for(
int i = 0; i < cols->Count; ++i)
440 ADOX::_ColumnPtr
col = cols->GetItem((
long)i);
442 if(((LPCSTR)(_bstr_t)col->GetName()) == name)
458 const std::string& propertyName = p->
getName();
464 throw te::common::Exception((boost::format(
TE_TR(
"The dataset already \"%1%\" has a property with this name \"%2%\"!")) % datasetName % propertyName).str());
466 ADOX::_CatalogPtr pCatalog = 0;
468 ADOX::_TablePtr pTable = 0;
470 TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
474 pCatalog->PutActiveConnection(variant_t((IDispatch *)
m_conn->
getConn()));
476 pTable = pCatalog->Tables->GetItem(datasetName.c_str());
478 ADOX::_ColumnPtr newColumn = 0;
480 TESTHR(newColumn.CreateInstance(__uuidof(ADOX::Column)));
482 newColumn->PutName(propertyName.c_str());
506 newColumn->PutAttributes(ADOX::adColNullable);
508 pTable->Columns->Append(_variant_t ((IDispatch*)newColumn), ado_type, 0);
517 std::size_t ssize = 0;
522 newColumn->DefinedSize = (long)ssize;
525 newColumn->PutAttributes(ADOX::adColNullable);
527 pTable->Columns->Append(_variant_t ((IDispatch*)newColumn), ado_type, (
long)ssize);
541 newColumn->PutAttributes(ADOX::adColNullable);
543 pTable->Columns->Append(_variant_t ((IDispatch*)newColumn), ado_type, 0);
575 throw te::common::Exception((boost::format(
TE_TR(
"The dataset \"%1%\" has no property with this name \"%2%\"!")) % datasetName % name).str());
581 ADOX::_CatalogPtr pCatalog = 0;
583 ADOX::_TablePtr pTable = 0;
585 TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
589 pCatalog->PutActiveConnection(variant_t((IDispatch *)
m_conn->
getConn()));
597 std::string sql =
"delete from geometry_columns where f_geometry_column = '";
599 sql +=
"' AND f_table_name = '";
613 const std::string& propertyName,
614 const std::string& newPropertyName)
616 ADOX::_CatalogPtr pCatalog = 0;
618 ADOX::_TablePtr pTable = 0;
620 TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
624 pCatalog->PutActiveConnection(variant_t((IDispatch *)
m_conn->
getConn()));
626 pTable = pCatalog->Tables->GetItem(datasetName.c_str());
628 ADOX::_ColumnPtr
col = pTable->GetColumns()->GetItem(propertyName.c_str());
630 col->PutName(newPropertyName.c_str());
632 pCatalog->GetTables()->Refresh();
642 std::unique_ptr<te::dt::Property> prp(newProp);
645 std::string sql(
"ALTER TABLE ");
646 sql += datasetName +
" ALTER COLUMN " + propName +
" " + type;
655 return std::unique_ptr<te::da::PrimaryKey>(
static_cast<te::da::PrimaryKey*
>(dt->getPrimaryKey()->clone()));
662 if(dt->getPrimaryKey()->getName() == name)
670 _variant_t vOptional;
671 vOptional.vt = VT_ERROR;
672 vOptional.scode = DISP_E_PARAMNOTFOUND;
674 ADOX::_KeyPtr pKey = 0;
675 ADOX::_TablePtr pTable = 0;
676 ADOX::_CatalogPtr pCatalog = 0;
678 TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
679 TESTHR(pKey.CreateInstance(__uuidof(ADOX::Key)));
683 pCatalog->PutActiveConnection(variant_t((IDispatch *)
m_conn->
getConn()));
685 pTable = pCatalog->Tables->GetItem(datasetName.c_str());
687 pKey->Name = pTable->Name +
"_pk";
688 pKey->Type = ADOX::adKeyPrimary;
697 TESTHR(pTable->Keys->Append(_variant_t((IDispatch *)pKey),ADOX::adKeyPrimary,vOptional,
L"",
L""));
698 pCatalog->Tables->Refresh();
708 ADOX::_KeyPtr pKey = 0;
709 ADOX::_TablePtr pTable = 0;
710 ADOX::_CatalogPtr pCatalog = 0;
712 std::unique_ptr<te::da::PrimaryKey> pk(
getPrimaryKey(datasetName));
716 pCatalog->PutActiveConnection(variant_t((IDispatch *)
m_conn->
getConn()));
718 pTable = pCatalog->Tables->GetItem(datasetName.c_str());
720 pKey = pTable->Keys->GetItem(pk->getName().c_str());
722 TESTHR(pTable->GetKeys()->Delete(_variant_t((IDispatch *)pKey)));
733 throw te::common::Exception((boost::format(
TE_TR(
"The dataset \"%1%\" has no foreign key with this name \"%2%\"!")) % datasetName % name).str());
737 return std::unique_ptr<te::da::ForeignKey>(
static_cast<te::da::ForeignKey*
>(dt->getForeignKey(name)->clone()));
744 std::vector<std::string> fkNames;
746 std::size_t numFK = dt->getNumberOfForeignKeys();
748 for(std::size_t i = 0; i < numFK; ++i)
749 fkNames.push_back(dt->getForeignKey(i)->getName());
760 if(std::find(fkNames.begin(), fkNames.end(), name) != fkNames.end())
768 _variant_t vOptional;
769 vOptional.vt = VT_ERROR;
770 vOptional.scode = DISP_E_PARAMNOTFOUND;
772 ADOX::_KeyPtr pKey = 0;
773 ADOX::_TablePtr pTable = 0;
774 ADOX::_CatalogPtr pCatalog = 0;
778 pCatalog->PutActiveConnection(variant_t((IDispatch *)
m_conn->
getConn()));
780 pTable = pCatalog->Tables->GetItem(datasetName.c_str());
782 TESTHR(pKey.CreateInstance(__uuidof(ADOX::Key)));
784 pKey->Name = pTable->Name +
"_fk";
785 pKey->Type = ADOX::adKeyForeign;
798 TESTHR(pTable->Keys->Append(_variant_t((IDispatch *)pKey),ADOX::adKeyPrimary,vOptional,
L"",
L""));
800 pCatalog->Tables->Refresh();
810 ADOX::_KeyPtr pKey = 0;
811 ADOX::_TablePtr pTable = 0;
812 ADOX::_CatalogPtr pCatalog = 0;
817 pCatalog->PutActiveConnection(variant_t((IDispatch *)
m_conn->
getConn()));
819 pTable = pCatalog->Tables->GetItem(datasetName.c_str());
821 pKey = pTable->Keys->GetItem(fkName.c_str());
823 TESTHR(pTable->GetKeys()->Delete(_variant_t((IDispatch *)pKey)));
834 throw te::common::Exception((boost::format(
TE_TR(
"The dataset \"%1%\" has no unique key with this name \"%2%\"!")) % datasetName % name).str());
838 return std::unique_ptr<te::da::UniqueKey>(
static_cast<te::da::UniqueKey*
>(dt->getUniqueKey(name)->clone()));
845 std::vector<std::string> ukNames;
847 std::size_t numUKs = dt->getNumberOfUniqueKeys();
849 for(std::size_t i = 0; i < numUKs; ++i)
850 ukNames.push_back(dt->getUniqueKey(i)->getName());
861 if(std::find(ukNames.begin(), ukNames.end(), name) != ukNames.end())
869 _variant_t vOptional;
870 vOptional.vt = VT_ERROR;
871 vOptional.scode = DISP_E_PARAMNOTFOUND;
873 ADOX::_KeyPtr pKey = 0;
874 ADOX::_TablePtr pTable = 0;
875 ADOX::_CatalogPtr pCatalog = 0;
877 TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
878 TESTHR(pKey.CreateInstance(__uuidof(ADOX::Key)));
882 pCatalog->PutActiveConnection(variant_t((IDispatch *)
m_conn->
getConn()));
884 pTable = pCatalog->Tables->GetItem(datasetName.c_str());
886 pKey->Name = pTable->Name +
"_uk";
887 pKey->Type = ADOX::adKeyUnique;
896 TESTHR(pTable->Keys->Append(_variant_t((IDispatch *)pKey),ADOX::adKeyUnique,vOptional,
L"",
L""));
898 pCatalog->Tables->Refresh();
908 ADOX::_KeyPtr pKey = 0;
909 ADOX::_TablePtr pTable = 0;
910 ADOX::_CatalogPtr pCatalog = 0;
914 pCatalog->PutActiveConnection(variant_t((IDispatch *)
m_conn->
getConn()));
916 pTable = pCatalog->Tables->GetItem(datasetName.c_str());
918 pKey = pTable->Keys->GetItem(name.c_str());
920 TESTHR(pTable->GetKeys()->Delete(_variant_t((IDispatch *)pKey)));
931 throw te::common::Exception((boost::format(
TE_TR(
"The dataset \"%1%\" has no check constraint with this name \"%2%\"!")) % datasetName % name).str());
935 return std::unique_ptr<te::da::CheckConstraint>(
static_cast<te::da::CheckConstraint*
>(dt->getCheckConstraint(name)->clone()));
942 std::vector<std::string> ccNames;
944 std::size_t numCCs = dt->getNumberOfCheckConstraints();
946 for(std::size_t i = 0; i < numCCs; ++i)
947 ccNames.push_back(dt->getCheckConstraint(i)->getName());
956 if(std::find(ccNames.begin(), ccNames.end(), name) != ccNames.end())
975 throw te::common::Exception((boost::format(
TE_TR(
"The dataset \"%1%\" has no index with this name \"%2%\"!")) % datasetName % name).str());
979 return std::unique_ptr<te::da::Index>(dt->getIndex(name)->clone());
984 std::vector<std::string> idxNames;
988 std::size_t numIdxs = dt->getNumberOfIndexes();
990 for(std::size_t i = 0; i < numIdxs; ++i)
991 idxNames.push_back(dt->getIndex(i)->getName());
998 std::vector<std::string> idxNames =
getIndexNames(datasetName);
1000 if(std::find(idxNames.begin(), idxNames.end(), name) != idxNames.end())
1007 const std::map<std::string, std::string>&)
1009 ADOX::_IndexPtr pIndex = 0;
1010 ADOX::_TablePtr pTable = 0;
1011 ADOX::_CatalogPtr pCatalog = 0;
1013 TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
1014 TESTHR(pIndex.CreateInstance(__uuidof(ADOX::Index)));
1018 pCatalog->PutActiveConnection(variant_t((IDispatch *)
m_conn->
getConn()));
1020 pTable = pCatalog->Tables->GetItem(datasetName.c_str());
1022 pIndex->Name = idx->
getName().c_str();
1024 std::vector<te::dt::Property*> idxProps = idx->
getProperties();
1025 for(
size_t i = 0; i < idxProps.size(); i++)
1034 TESTHR(pTable->Indexes->Append(_variant_t((IDispatch *)pIndex)));
1036 catch(_com_error& e)
1045 throw te::common::Exception((boost::format(
TE_TR(
"The dataset \"%1%\" has no index with this name: \"%2%\"!")) % datasetName % idxName).str());
1047 std::string sql(
"DROP INDEX ");
1085 const std::string& )
1090 std::string sql =
"SELECT MIN(lower_x), MIN(lower_y), MAX(upper_x), MAX(upper_y) from " + datasetName;
1092 std::unique_ptr<te::da::DataSet> resultBox(
query(sql));
1098 resultBox->moveFirst();
1099 env->m_llx = resultBox->getDouble(0);
1100 env->m_lly = resultBox->getDouble(1);
1101 env->m_urx = resultBox->getDouble(2);
1102 env->m_ury = resultBox->getDouble(3);
1120 std::unique_ptr<te::da::DataSet> result(
getDataSet(datasetName));
1122 return result->size();
1129 if(datasetNames.empty())
1139 if(std::find(datasetNames.begin(), datasetNames.end(), name) != datasetNames.end())
1147 ADOX::_TablePtr pTable = 0;
1148 ADOX::_CatalogPtr pCatalog = 0;
1150 TESTHR(pTable.CreateInstance(__uuidof (ADOX::Table)));
1151 TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
1155 pCatalog->PutActiveConnection(variant_t((IDispatch *)
m_conn->
getConn()));
1157 pTable->Name = dt->
getName().c_str();
1159 TESTHR(pCatalog->Tables->Append(_variant_t((IDispatch*)pTable)));
1162 catch(_com_error &e)
1167 std::size_t ncols = dt->
size();
1169 for(std::size_t i = 0; i < ncols; ++i)
1177 const std::string& ,
1178 const std::map<std::string, std::string>& )
1185 ADOX::_CatalogPtr pCatalog = 0;
1187 TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
1191 pCatalog->PutActiveConnection(variant_t((IDispatch *)
m_conn->
getConn()));
1193 TESTHR(pCatalog->Tables->Delete(name.c_str()));
1195 catch(_com_error& e)
1203 ADOX::_CatalogPtr pCatalog = 0;
1205 TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
1209 pCatalog->Tables->GetItem(name.c_str())->PutName(newName.c_str());
1211 catch(_com_error& e)
1219 const std::map<std::string, std::string>&,
1223 _RecordsetPtr recset;
1224 TESTHR(recset.CreateInstance(__uuidof(Recordset)));
1228 TESTHR(recset->Open(_bstr_t(datasetName.c_str()),
1229 _variant_t((IDispatch*)
m_conn->
getConn(),
true), adOpenKeyset, adLockOptimistic, adCmdTable));
1233 TESTHR(recset->AddNew());
1253 recset->GetFields()->GetItem(pname.c_str())->Value = (_bstr_t)d->
getChar(pname.c_str());
1257 recset->GetFields()->GetItem(pname.c_str())->Value = (_bstr_t)d->
getUChar(pname.c_str());
1261 recset->GetFields()->GetItem(pname.c_str())->Value = (_variant_t)d->
getInt16(pname.c_str());
1265 recset->GetFields()->GetItem(pname.c_str())->Value = (_variant_t)d->
getInt32(pname.c_str());
1269 recset->GetFields()->GetItem(pname.c_str())->Value = (_variant_t)d->
getInt64(pname.c_str());
1278 double dval = boost::lexical_cast<
double>(sval);
1279 recset->GetFields()->GetItem(pname.c_str())->Value = (_variant_t)(dval);
1285 std::unique_ptr<te::dt::DateTime> dtm(d->
getDateTime(i));
1289 recset->GetFields()->GetItem(pname.c_str())->Value = (_bstr_t)dtt.c_str();
1295 recset->GetFields()->GetItem(pname.c_str())->Value = (_variant_t)d->
getFloat(pname.c_str());
1299 recset->GetFields()->GetItem(pname.c_str())->Value = (_variant_t)d->
getDouble(pname.c_str());
1303 recset->GetFields()->GetItem(pname.c_str())->Value = (_bstr_t)d->
getString(pname.c_str()).c_str();
1307 recset->GetFields()->GetItem(pname.c_str())->Value = (_variant_t)d->
getBool(pname.c_str());
1325 std::unique_ptr<te::gm::Geometry> geometry(d->
getGeometry(pname));
1328 recset->GetFields()->GetItem(
"lower_x")->Value = (_variant_t)env->
m_llx;
1329 recset->GetFields()->GetItem(
"lower_y")->Value = (_variant_t)env->m_lly;
1330 recset->GetFields()->GetItem(
"upper_x")->Value = (_variant_t)env->m_urx;
1331 recset->GetFields()->GetItem(
"upper_y")->Value = (_variant_t)env->m_ury;
1336 recset->Fields->GetItem(pname.c_str())->AppendChunk (var);
1347 TESTHR(recset->Update());
1351 catch(_com_error& e)
1359 ADOX::_CatalogPtr pCatalog = 0;
1361 TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
1365 pCatalog->PutActiveConnection(variant_t((IDispatch *)
m_conn->
getConn()));
1367 TESTHR(pCatalog->Tables->Delete(datasetName.c_str()));
1369 catch(_com_error& e)
1377 const std::vector<std::size_t>&,
1379 const std::map<std::string, std::string>&,
1387 const std::vector< std::set<int> >& properties,
1388 const std::vector<size_t>& ids)
1394 std::set<int>::iterator it;
1402 std::string sql =
"UPDATE " + datasetName +
" SET ";
1403 plst = properties[i];
1408 for(it = plst.begin(); it != plst.end(); ++it)
1416 pName +=
"=\"" + dataset->
getAsString(*it) +
"\"";
1423 for(
size_t j=0; j<ids.size(); ++j)
1436 sql += pName +
" WHERE " + id;
1462 ADOX::_CatalogPtr pCatalog = 0;
1464 TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
1468 pCatalog->PutActiveConnection(variant_t((IDispatch *)adoConn));
1470 catch(_com_error& e)
1474 ADOX::TablesPtr tables = pCatalog->GetTables();
1476 ADOX::_TablePtr t = tables->GetItem(dt->
getName().c_str());
1478 ADOX::KeysPtr keys = t->GetKeys();
1480 ADOX::_KeyPtr pk = 0;
1482 for(
long i = 0; i < keys->Count; i++)
1484 if(keys->GetItem(i)->GetType() == ADOX::adKeyPrimary)
1485 pk = keys->GetItem(i);
1494 ADOX::ColumnsPtr cols = pk->GetColumns();
1498 for(
long i = 0; i < cols->GetCount(); i++)
1499 tlPk->
add(dt->
getProperty(std::string(cols->GetItem(i)->GetName())));
1504 std::string dsName = dt->
getName();
1507 ADOX::DataTypeEnum colType;
1508 std::map<int, std::string> colNamesMap;
1509 std::map<int, ADOX::DataTypeEnum> colTypesMap;
1510 std::map<int, int> charLengthMap;
1511 std::map<int, bool> isRequiredMap;
1512 std::map<int, bool> hasDefaultMap;
1513 std::map<int, std::string> defaultValueMap;
1515 _ConnectionPtr conn = 0;
1523 _RecordsetPtr rs = NULL;
1525 TESTHR(rs.CreateInstance(__uuidof(Recordset)));
1529 SAFEARRAY FAR* psa = NULL;
1530 SAFEARRAYBOUND rgsabound;
1534 rgsabound.lLbound = 0;
1535 rgsabound.cElements = 3;
1536 psa = SafeArrayCreate(VT_VARIANT, 1, &rgsabound);
1538 var[0].vt = VT_EMPTY;
1539 var[1].vt = VT_EMPTY;
1540 var[2] = dsName.c_str();
1543 for(LONG i = 0; i < 3; ++i)
1544 hr = SafeArrayPutElement(psa, &i, &var[i]);
1546 Array.vt = VT_ARRAY | VT_VARIANT;
1549 rs = conn->OpenSchema(adSchemaColumns, &Array, vtMissing);
1552 while (!(rs->EndOfFile))
1555 _bstr_t columnName = rs->Fields->GetItem(
"COLUMN_NAME")->Value;
1556 pos = rs->Fields->GetItem(
"ORDINAL_POSITION")->Value;
1558 colNamesMap[pos] = (LPCSTR)columnName;
1561 colType = ADOX::DataTypeEnum(
int(rs->Fields->GetItem(
"DATA_TYPE")->Value));
1562 colTypesMap[pos] = colType;
1565 _variant_t length = rs->Fields->GetItem(
"CHARACTER_MAXIMUM_LENGTH")->Value;
1567 if(length.vt != VT_NULL)
1568 charLength = (
int)length.dblVal;
1569 charLengthMap[pos] = charLength;
1572 bool nullVal = rs->Fields->GetItem(
"IS_NULLABLE")->Value;
1573 isRequiredMap[pos] = !nullVal;
1576 bool hasDefault = rs->Fields->GetItem(
"COLUMN_HASDEFAULT")->Value;
1577 hasDefaultMap[pos] = !hasDefault;
1580 std::string defaultStr;
1583 _bstr_t defaultValue = rs->Fields->GetItem(
"COLUMN_DEFAULT")->Value;
1584 defaultStr = (LPSTR)defaultValue;
1587 defaultValueMap[pos] = defaultStr;
1593 catch (_com_error& e)
1595 std::cout <<
"Error = " << (
char*) e.ErrorMessage() << std::endl;
1599 for(
int i = 0; i < numCols; ++i)
1602 ADOX::DataTypeEnum colType = colTypesMap[i];
1603 std::string colName = colNamesMap[i];
1619 case ::adLongVarChar:
1620 case ::adLongVarWChar:
1628 sp->
setSize(charLengthMap[i]);
1633 case ADOX::adTinyInt:
1634 case ADOX::adSmallInt:
1635 case ADOX::adInteger:
1636 case ADOX::adBigInt:
1637 case ADOX::adSingle:
1638 case ADOX::adDouble:
1639 case ADOX::adDecimal:
1640 case ::adUnsignedBigInt:
1641 case ::adUnsignedInt:
1642 case ::adUnsignedSmallInt:
1643 case ::adUnsignedTinyInt:
1652 case ADOX::adBinary:
1653 case ADOX::adLongVarBinary:
1657 std::map<std::string, std::string>::iterator it = geomColumns.find(dsName);
1659 if(it != geomColumns.end())
1661 if(it->second == colName)
1675 case ADOX::adDBDate:
1676 case ADOX::adDBTime:
1677 case ADOX::adDBTimeStamp:
1694 ADOX::_CatalogPtr pCatalog = 0;
1696 TESTHR(pCatalog.CreateInstance(__uuidof(ADOX::Catalog)));
1700 pCatalog->PutActiveConnection(variant_t((IDispatch *)adoConn));
1702 catch(_com_error& e)
1707 ADOX::TablesPtr tables = pCatalog->GetTables();
1709 ADOX::_TablePtr t = tables->GetItem(dt->
getName().c_str());
1711 ADOX::KeysPtr keys = t->GetKeys();
1713 for(
long i = 0; i < keys->Count; i++)
1715 if(keys->GetItem(i)->GetType() == ADOX::adKeyUnique)
1717 ADOX::_KeyPtr uk = keys->GetItem(i);
1721 ADOX::ColumnsPtr cols = uk->GetColumns();
1723 for(
long j = 0; j < cols->Count; j++)
1724 tlUk->
add(dt->
getProperty(std::string(cols->GetItem(i)->GetName())));
1733 ADOX::_CatalogPtr pCatalog = 0;
1735 TESTHR((pCatalog.CreateInstance(__uuidof(ADOX::Catalog))));
1739 pCatalog->PutActiveConnection(variant_t((IDispatch *)adoConn));
1741 catch(_com_error& e)
1746 ADOX::TablesPtr tables = pCatalog->GetTables();
1748 ADOX::_TablePtr t = tables->GetItem(dt->
getName().c_str());
1750 ADOX::IndexesPtr idxs = t->GetIndexes();
1752 for(
long i = 0; i < idxs->GetCount(); i++)
1754 ADOX::_IndexPtr idx = idxs->GetItem(i);
1757 tlIdx->
setName(std::string(idx->GetName()));
1759 std::vector<te::dt::Property*> props;
1761 ADOX::ColumnsPtr cols = idx->GetColumns();
1762 for(
long i = 0; i < cols->GetCount(); i++)
1763 props.push_back(dt->
getProperty(std::string(cols->GetItem(i)->GetName())));
1773 _RecordsetPtr rs = NULL;
1775 std::string dtName = dt->
getName();
1777 std::string str =
"[" + dtName +
"]";
1783 TESTHR(rs.CreateInstance(__uuidof(Recordset)));
1785 rs = adoConn->OpenSchema(adSchemaCheckConstraints);
1787 while (!(rs->EndOfFile))
1789 std::string constraintName = (LPCSTR)(bstr_t)(rs->Fields->GetItem(
"CONSTRAINT_NAME")->GetValue());
1791 if(constraintName.find(str) != std::string::npos)
1794 std::string checkClause = (LPCSTR)(bstr_t)(rs->Fields->GetItem(
"CHECK_CLAUSE")->GetValue());
1801 catch(_com_error& e)
1807 if(rs && rs->State == adStateOpen)
1816 int coord_dimension = 2;
1819 coord_dimension = 3;
1821 _RecordsetPtr recset;
1822 TESTHR(recset.CreateInstance(__uuidof(Recordset)));
1826 TESTHR(recset->Open(_bstr_t(
"geometry_columns"),
1827 _variant_t((IDispatch*)adoConn,
true), adOpenKeyset, adLockOptimistic, adCmdTable));
1829 TESTHR(recset->AddNew());
1831 recset->GetFields()->GetItem(
"f_table_catalog")->Value = (_bstr_t)std::string(
"''").c_str();
1832 recset->GetFields()->GetItem(
"f_table_schema")->Value = (_bstr_t)std::string(
"public").c_str();
1833 recset->GetFields()->GetItem(
"f_table_name")->Value = (_bstr_t)datasetName.c_str();
1834 recset->GetFields()->GetItem(
"f_geometry_column")->Value = (_bstr_t)geomProp->
getName().c_str();
1835 recset->GetFields()->GetItem(
"coord_dimension")->Value = (_variant_t)coord_dimension;
1836 recset->GetFields()->GetItem(
"srid")->Value = (_variant_t)geomProp->
getSRID();
1841 catch(_com_error& e)
virtual std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
Property * getProperty(std::size_t i) const
It returns the i-th property.
virtual unsigned char getUChar(std::size_t i) const =0
Method for retrieving an unsigned character attribute value (1 byte long).
void add(te::dt::Property *p)
It adds the property to the list of properties that participates in the unique key.
StringType
The subtype of string property.
std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset.
_ConnectionPtr getConn() const
It gets the ADO Connection object.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
std::unique_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName)
It retrieves the primary key of the dataset.
DataSet class implementation for Microsoft Access driver.
void dropCheckConstraint(const std::string &datasetName, const std::string &name)
It removes the check constraint from the dataset.
std::vector< std::string > getCheckConstraintNames(const std::string &datasetName)
It gets the check constraint names of the given dataset.
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
int GetSRID(_ConnectionPtr adoConn, std::string tableName, std::string geomPropName)
Read the geometry_columns table end return a SRID.
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids=0)
It removes all the informed items from the dataset.
void getIndexes(te::da::DataSetType *dt)
It update the DataSetType about the Indexes.
An atomic property like an integer or double.
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
void getUniqueKeys(te::da::DataSetType *dt)
It update the DataSetType about the Unique Keys.
const std::string & GetGeometryName(te::gm::GeomType t)
It returns the geometry OGC names.
te::gm::GeomType GetType(_ConnectionPtr adoConn, std::string tableName, std::string geomPropName)
Read the geometry_columns table end return a geometry type.
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.
A class that models the description of a dataset.
int Convert2Terralib(ADOX::DataTypeEnum adoType)
Bind ADOX Type to TerraLib Type.
virtual std::string getNumeric(std::size_t i) const =0
Method for retrieving a numeric attribute value.
bool isInTransaction() const
It returns true if a transaction is in progress, otherwise, it returns false.
Utility functions for ADO.
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
virtual float getFloat(std::size_t i) const =0
Method for retrieving a float attribute value.
void addForeignKey(const std::string &datasetName, te::da::ForeignKey *fk)
It adds a foreign key constraint to a dataset.
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...
std::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset.
void addIndex(const std::string &datasetName, te::da::Index *idx, const std::map< std::string, std::string > &options)
It adds an index to the dataset.
std::unique_ptr< te::da::Sequence > getSequence(const std::string &name)
It gets the sequence with the given name in the data source.
double m_urx
Upper right corner x-coordinate.
An static class with global definitions.
PrimaryKey * getPrimaryKey() const
It returns the primary key associated to the dataset type.
std::unique_ptr< te::dt::Property > getProperty(const std::string &datasetName, const std::string &name)
It retrieves the property with the given name from the dataset.
SpatialRelation
Spatial relations between geometric objects.
bool hasDataSets()
It checks if the data source has any dataset.
It describes a sequence (a number generator).
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
static te::dt::Date ds(2010, 01, 01)
std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
_RecordsetPtr query(const std::string &query, bool connected=false)
It queries the database.
A class that describes a check constraint.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
#define TE_TR(message)
It marks a string in order to get translated.
std::string GetFormattedDateTime(te::dt::DateTime *dateTime)
It gets a formatted DateTime string for ADO.
A class that implements a connection to a ADO database.
std::size_t size() const
It returns the maximum number of characters for a varying string, or the number of characters for a f...
It models a property definition.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
void addSequence(te::da::Sequence *sequence)
It creates a new sequence 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.
std::unique_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.
std::vector< std::string > getUniqueKeyNames(const std::string &datasetName)
It gets the unique key names of the given dataset.
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
std::unique_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.
AccessPolicy
Supported data access policies (can be used as bitfield).
TraverseType
A dataset can be traversed in two ways:
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.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
std::string GetAdoStringType(const int &terralib)
Bind TerraLib type to an ADO valid fiel type name.
double m_llx
Lower left corner x-coordinate.
bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset.
void optimize(const std::map< std::string, std::string > &opInfo)
For some data access drivers, this method will perform some operations to optimize the data storage...
bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source.
virtual boost::int16_t getInt16(std::size_t i) const =0
Method for retrieving a 16-bit integer attribute value (2 bytes long).
void begin()
It starts a new transaction.
int getSRID() const
It returns the spatial reference system identifier associated to this property.
void changePropertyDefinition(const std::string &datasetName, const std::string &propName, te::dt::Property *newProp)
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
An Envelope defines a 2D rectangular region.
void addCheckConstraint(const std::string &datasetName, te::da::CheckConstraint *cc)
It adds a check constraint to the dataset.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset.
std::unique_ptr< te::da::Index > getIndex(const std::string &datasetName, const std::string &name)
It gets the index with the given name from the dataset.
void insertIntoGeometryColumns(const std::string &datasetName, te::gm::GeometryProperty *geomProp)
It insert a geometry property in the geometry_clumns (SFS Schema).
std::unique_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::string escape(const std::string &value)
It escapes a string for using in commands and queries.
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
DataSource * m_ds
The ADO data source associated to this transactor.
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
static te::dt::TimeDuration dt(20, 30, 50, 11)
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source.
void addUniqueKey(const std::string &datasetName, te::da::UniqueKey *uk)
It adds a unique key constraint to the dataset.
void addPrimaryKey(const std::string &datasetName, te::da::PrimaryKey *pk)
It adds a primary key constraint to the dataset schema.
void registerGeometryColumn(const std::string &datasetName, const std::string &geomColName)
DataSetType * getReferencedDataSetType() const
It returns the referenced DataSetType of this foreign key constraint.
bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
std::unique_ptr< te::da::ForeignKey > getForeignKey(const std::string &datasetName, const std::string &name)
It retrieves the foreign key from the given dataset.
void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the dataset schema.
It models a foreign key constraint for a DataSetType.
A visitor for building an SQL statement using ADO dialect.
virtual std::string getAsString(std::size_t i, int precision=0) const
Method for retrieving a data value as a string plain representation.
bool isRequired() const
It returns true if the attribute is required, otherwise it returns false.
The type for string types: FIXED_STRING, VAR_STRING or STRING.
It describes a unique key (uk) constraint.
const std::map< std::string, std::string > & getGeomColumns() const
void setProperties(const std::vector< te::dt::Property * > &properties)
It sets the properties that take part of the index.
Property * getParent() const
It returns the parent of this property, or NULL, if it doesn't have one.
std::size_t size() const
It returns the number of properties of the CompositeProperty.
Implementation of the data source class for the ADO driver.
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
A visitor for building an SQL statement using ADO dialect.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
std::unique_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
void renameProperty(const std::string &datasetName, const std::string &propertyName, const std::string &newPropertyName)
It renames a property of the given dataset.
A Select models a query to be used when retrieving data from a DataSource.
void getCheckConstraints(te::da::DataSetType *dt)
It update the DataSetType about the Check Constraints.
Connection * m_conn
The connection used by this transactor.
double m_lly
Lower left corner y-coordinate.
std::unique_ptr< te::da::PreparedQuery > getPrepared(const std::string &qName=std::string(""))
It creates a prepared query object that may be used for query commands (select, insert, update and delete) that are used repeatedly.
void commit()
It commits the transaction.
void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema.
int getType() const
It returns the property data type.
void add(Constraint *c)
It adds a new constraint.
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
virtual std::unique_ptr< te::dt::DateTime > getDateTime(std::size_t i) const =0
Method for retrieving a date and time attribute value.
A dataset is the unit of information manipulated by the data access module of TerraLib.
virtual char getChar(std::size_t i) const =0
Method for retrieving a signed character attribute value (1 byte long).
bool m_isInTransaction
Tells if there is a transaction in progress.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that form the unique key.
std::string MakeConnectionStr(const te::core::URI &connInfo)
Create a connection string based on a map.
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.
double m_ury
Upper right corner y-coordinate.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the index.
It describes a primary key (pk) constraint.
const te::core::URI & getConnectionInfo() const
An Uniform Resource Identifier used to describe the datasource connection.
void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema.
void setExpression(const std::string &e)
It sets the check constraint expression.
ADOX::DataTypeEnum Convert2Ado(int terralib)
Bind TerraLib Type to ADO Type.
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.
void setRequired(bool r)
It tells if the property is required or not.
void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset.
void add(const std::string &datasetName, te::da::DataSet *d, const std::map< std::string, std::string > &options, std::size_t limit=0, bool enableProgress=true)
It adds data items to the dataset in the data source.
void execute(const std::string &command)
It executes the given SQL command and throws away the result.
virtual bool getBool(std::size_t i) const =0
Method for retrieving a boolean attribute value.
A class that implements a connection to a ADO database.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
bool IsZProperty(te::gm::GeomType type)
Verifies whether Z property.
virtual boost::int64_t getInt64(std::size_t i) const =0
Method for retrieving a 64-bit integer attribute value (8 bytes long).
void setName(const std::string &name)
It sets the index name.
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
DataSourceTransactor class implementation for Microsoft Access driver.
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos.
Transactor(DataSource *ds)
void update(const std::string &datasetName, te::da::DataSet *dataset, const std::vector< std::size_t > &properties, const te::da::ObjectIdSet *oids, const std::map< std::string, std::string > &options, std::size_t limit=0)
It updates the contents of a dataset for the set of data items.
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the foreign key constraint.
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
virtual bool moveFirst()=0
It moves the internal pointer to the first item in the collection.
const std::vector< te::dt::Property * > & getReferencedProperties() const
It returns the referenced properties (on the referenced DataSetType) of this foreign key constraint...
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.
void execute(const te::da::Query &command)
It executes the specified command using a generic query representation.
void cancel()
It requests that the data source stop the processing of the current command.
A Query is independent from the data source language/dialect.
It describes an index associated to a DataSetType.
virtual std::string getString(std::size_t i) const =0
Method for retrieving a string value attribute.
void setPrimaryKey(PrimaryKey *pk)
It sets the primary key constraint.
std::unique_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.
bool uniqueKeyExists(const std::string &datasetName, const std::string &name)
It checks if a unique key with the given name exists in the dataset.
void dropSequence(const std::string &name)
It removes the sequence from the data source.
const std::string & getName() const
It returns the property name.
bool isEnvelopeProperty(const std::string &name)
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
const std::string & getName() const
It returns the index name.
std::unique_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...