// -*- C++ -*- //

/* dataselect.h
 *
 * Copyright 2006 libgdamm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or(at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

_DEFS(libgdamm,libgda)
_PINCLUDE(glibmm/private/object_p.h)

#include <libgdamm/datamodel.h>
#include <libgdamm/statement.h>
#include <libgdamm/set.h>

namespace Gnome
{

namespace Gda
{

/** Data models returned by the execution of a SELECT statement.
 *
 * This data model implements the Gda::DataModel interface and is the required 
 * base object when database providers implement a data model returned when a 
 * SELECT statement has been executed. As the GdaDataModel interface is implemented, 
 * consult the API to access and modify the data held in a GdaDataSelect object.
 *
 * The default behaviour however is to disallow modifications, and this section 
 * documents how to characterize a Gda::DataSelect to allow modifications. 
 * Once this is done, any modification done to the data model whill be propagated 
 * to the modified table in the database using INSERT, UPDATE or DELETE statements.
 *
 * After any modification, it is still possible to read values from the data model
 * (even values for rows which have been modified or inserted). The data model 
 * might then execute some SELECT statement to fetch some actualized values. 
 * Note: there is a corner case where a modification made to a row would make 
 * the row not selected at first in the data model (for example is the original 
 * SELECT statement included a clause "WHERE id < 100" and the modification sets 
 * the "id" value to 110), then the row will still be in the data model 
 * even though it would not be if the SELECT statement which execution 
 * created the data model in the first place was re-run.
 *
 * @ingroup DataModels
 */
class DataSelect
 : public Glib::Object,
   public DataModel
{
  _CLASS_GOBJECT(DataSelect, GdaDataSelect, GDA_DATA_SELECT, Glib::Object, GObject)
  _IMPLEMENTS_INTERFACE(DataModel)
public:
  _WRAP_METHOD(bool set_row_selection_condition_sql(const Glib::ustring& sql_where), gda_data_select_set_row_selection_condition_sql, errthrow)
  // This is internal only
  _IGNORE (gda_data_select_set_row_selection_condition)
  _WRAP_METHOD(void compute_row_selection_condition(), gda_data_select_compute_row_selection_condition, errthrow)
  _WRAP_METHOD(void set_modification_statement(const Glib::RefPtr<Statement>& mod_stmt), gda_data_select_set_modification_statement, errthrow)
  _WRAP_METHOD(void set_modification_statement_sql(const Glib::ustring& sql), gda_data_select_set_modification_statement_sql, errthrow)
  _WRAP_METHOD(void compute_modification_statements(), gda_data_select_compute_modification_statements, errthrow)
  _WRAP_METHOD(void compute_columns_attributes(), gda_data_select_compute_columns_attributes, errthrow)

  _WRAP_METHOD(Glib::RefPtr<Connection> get_connection(), gda_data_select_get_connection)

  _WRAP_METHOD(void rerun(), gda_data_select_rerun, errthrow)

  _WRAP_PROPERTY("auto-reset", bool)
  _WRAP_PROPERTY("store-all-rows", bool)
  _WRAP_PROPERTY("connection", Glib::RefPtr<Connection>)
  _WRAP_PROPERTY("delete-stmt", Glib::RefPtr<Statement>)
  _WRAP_PROPERTY("insert-stmt", Glib::RefPtr<Statement>)
  _WRAP_PROPERTY("prepared-stmt", Glib::RefPtr<Statement>)
  _WRAP_PROPERTY("update-stmt", Glib::RefPtr<Statement>)
  _WRAP_PROPERTY("exec-params", Glib::RefPtr<Set>)
  _WRAP_PROPERTY("model-usage", guint)

};

} // namespace Gda
} // namespace Gnome

