// SqlQuery.cxx #include "dataset_sql/SqlQuery.h" #include #include #include #include using std::string; using std::ostream; using dset::SqlQuery; //********************************************************************** // Member functions. //********************************************************************** // Constructor. SqlQuery::SqlQuery(string sql){ m_query = sql; m_validity = true; } //********************************************************************** // Char constructor. SqlQuery::SqlQuery(const char* csql){ m_query = csql; m_validity = true; } //********************************************************************** // Destructor. SqlQuery::~SqlQuery() { } //********************************************************************** // Validity. bool SqlQuery::is_valid() const { return m_validity; } //********************************************************************** // Reset the Sql query to the default selection catalog. SqlQuery& SqlQuery::reset() { set("select * from selection"); return *this; } //********************************************************************** // Set an SQL query SqlQuery& SqlQuery::set(string sql) { m_query = sql; return *this; } //********************************************************************** // Add 'AND' constraints to a query SqlQuery& SqlQuery::andconstraint(string constraint) { if ( m_query.size() ) { m_query += " AND "; } m_query += constraint; return *this; } //********************************************************************** // Add 'OR' constraints to a query SqlQuery& SqlQuery::orconstraint(string constraint) { if ( m_query.size() ) { m_query += " OR "; } m_query += constraint; return *this; } //********************************************************************** // Return the curent query string SqlQuery::to_string() const{ return m_query; } //********************************************************************** // Free functions. //********************************************************************** // Output stream. std::ostream& operator<<(std::ostream& lhs, const SqlQuery& rhs) { lhs << "SQL Query: " << rhs.to_string(); return lhs; } //**********************************************************************