///////////////////////////////////////////////////////////
// File:			pgsql_spatial_queries.cpp
//
// Author:			Stefan Liersch
// Contact:			stefan.liersch@googlemail.com,
//					stefan.liersch@ufz.de
//
// Date:			2007-08-29
// last modified:	2007-08-29
//
//---------------------------------------------------------
// DESCRIPTION
//---------------------------------------------------------
// Functions to create spatial queries for PostGIS
// example:
// SELECT within(geometry1, geometry2)
// FROM feature1, feature2
// WHERE feature1.id = 1234
//
//---------------------------------------------------------
// ToDo
//---------------------------------------------------------
// 
//
///////////////////////////////////////////////////////////

//---------------------------------------------------------

#include "pgdatabase.h"
#include "saga_gui/helper.h"			// using function MSG_General_Add()
#define MSG_ADD(s)	MSG_General_Add(s, true, true);

wxString Cpgdatabase::Get_SQL_SpatialRelation(wxString command,
											  CSG_SimpleFeature *feature1, CSG_SimpleFeature *feature2,
											  wxString condition_value)
{
	wxString sql = "SELECT ";
	sql += command;
	sql += "(";
	sql += feature1->Get_Name();
	sql += ".";
	sql += feature1->Get_geom();
	sql += ", ";
	sql += feature2->Get_Name();
	sql += ".";
	sql += feature2->Get_geom();
	sql += ") FROM ";
	sql += feature1->Get_Name();
	sql += ", ";
	sql += feature2->Get_Name();
	sql += " WHERE ";
	sql += feature2->Get_Name();
	sql += ".";
	sql += feature1->Get_PrimaryKeyColumnName().c_str();
	sql += " = ";
	sql += condition_value;

	return(sql);
}