2013-10-11 23:07:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 - Juan Ferrer Toribio
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sql-dml.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION: sql-dml
|
|
|
|
* @Short_description: parent class of data manipulation statements.
|
|
|
|
* @Title: SqlDml
|
|
|
|
*
|
|
|
|
* The #SqlDml is the base class for all SQL statements that manipulate data.
|
|
|
|
**/
|
|
|
|
G_DEFINE_ABSTRACT_TYPE (SqlDml, sql_dml, SQL_TYPE_STMT);
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
|
|
|
|
|
2013-10-14 12:08:06 +00:00
|
|
|
/**
|
|
|
|
* sql_dml_add_target:
|
|
|
|
* @obj: a #SqlDml
|
|
|
|
* @target: a #SqlTarget
|
|
|
|
*
|
|
|
|
* Add a target to the DML statement.
|
|
|
|
**/
|
|
|
|
void sql_dml_add_target (SqlDml * obj, SqlTarget * target)
|
|
|
|
{
|
|
|
|
g_return_if_fail (SQL_IS_DML (obj));
|
|
|
|
g_return_if_fail (SQL_IS_TARGET (target));
|
|
|
|
|
|
|
|
obj->target = g_slist_append (obj->target, g_object_ref_sink (target));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sql_dml_set_where:
|
|
|
|
* @obj: a #SqlDml
|
|
|
|
* @expr: a #SqlExpr
|
|
|
|
*
|
|
|
|
* Sets the where expression of an DML statement.
|
|
|
|
**/
|
2013-10-11 23:07:35 +00:00
|
|
|
void sql_dml_set_where (SqlDml * obj, SqlExpr * where)
|
|
|
|
{
|
|
|
|
g_return_if_fail (SQL_IS_DML (obj));
|
2013-10-14 12:08:06 +00:00
|
|
|
g_return_if_fail (SQL_IS_EXPR (where));
|
2013-10-11 23:07:35 +00:00
|
|
|
|
2013-10-14 12:08:06 +00:00
|
|
|
g_clear_object (&obj->where);
|
|
|
|
obj->where = g_object_ref_sink (where);
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2013-10-14 12:08:06 +00:00
|
|
|
PROP_WHERE = 1
|
2013-10-11 23:07:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void sql_dml_set_property (SqlDml * obj, guint id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PROP_WHERE:
|
|
|
|
sql_dml_set_where (obj, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sql_dml_get_property (SqlDml * obj, guint id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PROP_WHERE:
|
|
|
|
g_value_set_object (value, obj->where);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
|
2013-10-14 12:08:06 +00:00
|
|
|
static void sql_dml_finalize (SqlDml * obj)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2013-10-14 12:08:06 +00:00
|
|
|
g_clear_object (&obj->where);
|
|
|
|
g_slist_free_full (obj->target, g_object_unref);
|
|
|
|
G_OBJECT_CLASS (sql_dml_parent_class)->finalize (G_OBJECT (obj));
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 12:08:06 +00:00
|
|
|
static void sql_dml_init (SqlDml * obj)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2013-10-14 12:08:06 +00:00
|
|
|
obj->target = NULL;
|
|
|
|
obj->where = NULL;
|
2013-10-11 23:07:35 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 12:08:06 +00:00
|
|
|
static void sql_dml_class_init (SqlDmlClass * k)
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
2013-10-14 12:08:06 +00:00
|
|
|
GObjectClass * klass = G_OBJECT_CLASS (k);
|
|
|
|
klass->finalize = (GObjectFinalizeFunc) sql_dml_finalize;
|
|
|
|
klass->set_property = (GObjectSetPropertyFunc) sql_dml_set_property;
|
|
|
|
klass->get_property = (GObjectGetPropertyFunc) sql_dml_get_property;
|
|
|
|
|
|
|
|
g_object_class_install_property (klass, PROP_WHERE,
|
|
|
|
g_param_spec_object ("where"
|
2013-10-11 23:07:35 +00:00
|
|
|
,"Where"
|
2013-10-14 12:08:06 +00:00
|
|
|
,"The expression used to filter rows, it's the WHERE section of an statement"
|
2013-10-11 23:07:35 +00:00
|
|
|
,SQL_TYPE_EXPR
|
|
|
|
,G_PARAM_READWRITE
|
|
|
|
));
|
|
|
|
}
|