Exemplo n.º 1
0
SEXP aRTdb::Print()
{
	stringstream s;

	if(!Database) error("Invalid object");

	TeAttrTableVector atts;
	Database->getAttrTables(atts, TeAttrExternal);

	s << artOBJECT("aRTdb") << "\n\n"
	  << "Database: \"" << Database->databaseName() << "\"" << endl
	  << "Layers: ";

    TeLayerMap& layer_map = Database -> layerMap();
    TeLayer* layer;
    TeLayerMap::iterator lit;

    if( layer_map.size() > 0 )
	{
		s << endl;
	    for (lit = layer_map.begin(); lit != layer_map.end(); ++lit)
	    {
	        layer = lit -> second;
	        s << "    \"" << layer -> name() << "\"" << endl;
	    }
	}
	else s << "(none)" << endl;
 
	s << "Themes: ";

	TeThemeMap& theme_map = Database -> themeMap();
	TeAbstractTheme* theme;
	TeThemeMap::iterator tit;
	if(theme_map.size() > 0)
	{
		s << endl;
		for (tit = theme_map.begin(); tit != theme_map.end(); ++tit)
		{
			theme = tit -> second;
			s << "    \"" << theme -> name() << "\"" << endl;
		}
	}
	else s << "(none)" << endl;

	s << "External tables: ";
    if( atts.size() )
	{
		s << endl;
		for(unsigned i = 0; i != atts.size(); i++)
			s << "    \"" << atts[i].name() << "\"" << endl;
	}
	else s << "(none)" << endl;
			
	s << endl;
	Rprintf( StreamToChar(s) );
	return RNULL;
}
Exemplo n.º 2
0
SEXP aRTdb::ShowTables()
{
	SEXP vectorTables;
	TeAttrTableVector atts;
	TeAttributeList attrList;
	
	Database -> getAttrTables(atts, TeAttrExternal);
	
	// TODO: it returns false when the database does not have any table
	//if ( !Database -> getAttrTables(atts, TeAttrExternal) )
	//	error("Error loading tables from database!");

	if( !atts.size() ) return R_NilValue;
	
	vectorTables = allocVector(STRSXP, atts.size());

	for (unsigned i = 0; i < atts.size(); i++)
		SET_STRING_ELT(vectorTables, i, mkChar(atts[i].name().c_str()));

	return vectorTables;
}
bool updateDB301To302(TeDatabase* db, string& errorMessage)
{
		
	TeDatabasePortal* portal = db->getPortal();
	if(!portal)
		return false;

	// ----- valid attribute table 
	
	TeAttrTableVector attrTableVec;
	if(db->getAttrTables(attrTableVec))
	{
		for(unsigned int i=0; i<attrTableVec.size(); ++i)
		{
			TeTable fromTable = attrTableVec[i];
			bool	flag = false;
			
			if(fromTable.tableType()==TeAttrMedia)
				continue;

			//verify if there is another table with the same name
			for(unsigned int j=0; j<i; ++j)
			{
				if(TeConvertToUpperCase(attrTableVec[j].name())==TeConvertToUpperCase(fromTable.name())) 
				{
					flag = true;
					break;
				}
			}

			if(flag)
				continue;
			
			if(db->validTable(fromTable)) //fromTable was modified
			{
				TeAttributeList newAttrList = fromTable.attributeList();
				TeAttributeList oldAttrList = attrTableVec[i].attributeList();
				TeAttributeList::iterator newAttIt = newAttrList.begin();
				TeAttributeList::iterator oldAttIt = oldAttrList.begin();

				bool change = false;
				while(newAttIt!=newAttrList.end())
				{
					if(((*oldAttIt).rep_.name_) != ((*newAttIt).rep_.name_))
					{
						TeAttributeRep rep = (*newAttIt).rep_;
						if(db->alterTable(fromTable.name(), rep, (*oldAttIt).rep_.name_))
							change = true;
					}

					++newAttIt;
					++oldAttIt;
				}

				if(change)
				{
					// update te_layer_table
					string upd = " UPDATE te_layer_table ";
					upd +=	" SET unique_id = '"+ fromTable.uniqueName() +"'";
					upd +=  ", attr_link = '"+ fromTable.linkName() +"'";
					upd +=	" WHERE attr_table = '"+ fromTable.name() +"'";

					if(!db->execute (upd))
					{
						delete portal;
						errorMessage = "Error updating te_layer_table!\n";
						errorMessage += db->errorMessage();
						return false;
					}
				}
			}//if
		}//for
		portal->freeResult();
	}

	// ----- te_grouping table

	string sel = " SELECT theme_id, grouping_attr, grouping_attr_type FROM te_grouping ";
	if(!portal->query(sel))
	{
		delete portal;
		return false;
	}

	while(portal->fetchRow())
	{
		string themeId, gAttr;
		themeId = portal->getData(0);
		gAttr = portal->getData(1);
		int gTypr = portal->getInt(2);
		
		if(((gAttr.empty()) || (gAttr=="NONE")) && (gTypr==0))
		{
			string del = " DELETE FROM te_grouping WHERE theme_id = "+ themeId; 
			db->execute(del);
		}
	}

	// ----- te_grouping table

	delete portal;
	return true; 
}
Exemplo n.º 4
0
string 
TeQuerierDB::sqlFrom(string geomTable)
{
	string fromPar = "";
	string fromClause = "";
	
	//get collection tables 
	string collAuxTable = params_->theme()->collectionAuxTable();
	string collTable = params_->theme()->collectionTable();
	
	if(collAuxTable.empty() || collTable.empty())
		return attrTable_.name();

	if(attrTable_.name().empty())
		return "";
	
	string uniqueIdName = attrTable_.name() +"."+ attrTable_.uniqueName(); 
	string objectIdName = attrTable_.name() +"."+ attrTable_.linkName(); 
	string linkName; 
	if(attrTable_.tableType() != TeAttrExternal)
		linkName = attrTable_.name() +"."+ attrTable_.linkName(); 
	else
		linkName = collTable +".c_object_id "; 

	//load geometry table if there is spatial restriction
	if(geomTable.empty() && params_->hasSpatialRes())
	{
		TeRepresentation* rep = (theme()->layer()->vectRepres())[0];
		geomTable = theme()->layer()->tableName(rep->geomRep_);
	}

	//get the extern table position 
	int posExtern = -1;
	TeAttrTableVector attr = params_->theme()->attrTables();
	for(unsigned int i=0; i<attr.size(); ++i)
	{
		if(attr[i].tableType() == TeAttrExternal)
			++posExtern;
	}
	
	//if the table is temporal   
	if((attrTable_.tableType()==TeAttrEvent) || (attrTable_.tableType()==TeFixedGeomDynAttr))
	{
		fromPar += "((";
		fromClause = attrTable_.name()+" RIGHT JOIN "+ collAuxTable; 
				
		if(attrTable_.tableType()==TeFixedGeomDynAttr)
		{
			fromClause += " ON "+ uniqueIdName +" = ";
			fromClause += collAuxTable +".aux0";
			fromClause += ")";
		}
		else
		{
			fromClause += " ON "+ objectIdName +" = ";
			fromClause += collAuxTable +".object_id"+ ")";
		}

		fromClause += " LEFT JOIN "+ collTable; 
		fromClause += " ON "+ collAuxTable +".object_id = "+ collTable +".c_object_id )";
		
		if(!geomTable.empty())
		{
			fromPar += "(";
			fromClause += " LEFT JOIN "+ geomTable +" ON ";
			fromClause += collAuxTable +".object_id = "+ geomTable +".object_id )";
		}

		if(params_->selectedObjs() != TeAll) //! join with collection table
		{
			fromPar += "(";
			fromClause += " LEFT JOIN "+ collTable +" ON ";
			fromClause += collAuxTable +".object_id = "+ collTable +".c_object_id )";
		}
	} 

	else if (attrTable_.tableType()==TeAttrStatic)
	{
		fromPar += "(";
		fromClause =  attrTable_.name()+" RIGHT JOIN "+ collTable; 
		fromClause += " ON "+ linkName +" = "+ collTable +".c_object_id)";

		if(!geomTable.empty()) //! join with geometry table
		{
			fromPar += "(";
			fromClause += " LEFT JOIN "+ geomTable +" ON ";
			fromClause += collTable +".c_object_id = "+ geomTable +".object_id )";
		}

		if(params_->selectedObjs() != TeAll) //! join with collection table
		{
			fromPar += "(";
			fromClause += " LEFT JOIN "+ collAuxTable +" ON ";
			fromClause += collTable +".c_object_id = "+ collAuxTable +".object_id )";
		}
	}
	else if (attrTable_.tableType()==TeAttrExternal)
	{
		fromPar += "((";
		fromClause = collAuxTable +" RIGHT JOIN "+ collTable; 
		fromClause += " ON "+ collAuxTable +".object_id = "+ collTable +".c_object_id )";
		fromClause += " LEFT JOIN "+ attrTable_.name() +" ON ";
		fromClause +=  collAuxTable +".aux"+ Te2String(posExtern) +" = ";
		fromClause +=  uniqueIdName +" )";

		if(!geomTable.empty()) //! join with geometry table
		{
			fromPar += "(";
			fromClause += " LEFT JOIN "+ geomTable +" ON ";
			fromClause += collTable +".c_object_id = "+ geomTable +".object_id )";
		} 
	}
		
	return (fromPar+fromClause);
}