118 lines
3.1 KiB
C
118 lines
3.1 KiB
C
/*
|
|
* 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-update.h"
|
|
|
|
/**
|
|
* SECTION: sql-update
|
|
* @Short_description: an SQL UPDATE statement
|
|
* @Title: SqlUpdate
|
|
*
|
|
* Represents an SQL UPDATE statement.
|
|
**/
|
|
G_DEFINE_TYPE (SqlUpdate, sql_update, SQL_TYPE_DML);
|
|
|
|
SqlObject * sql_update_new ()
|
|
{
|
|
return g_object_new (SQL_TYPE_UPDATE, NULL);
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
|
|
|
|
static void sql_update_render (SqlUpdate * obj, SqlRender * render)
|
|
{
|
|
sql_render_add_list (render, TRUE, "UPDATE", SQL_DML (obj)->targets, ",");
|
|
|
|
if (SQL_DML (obj)->targets)
|
|
{
|
|
sql_render_add_list (render, TRUE, "SET", obj->sets, ",");
|
|
sql_render_add_item (render, FALSE, "WHERE", SQL_DML (obj)->where);
|
|
}
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
|
|
|
|
void sql_update_add_set (SqlUpdate * obj, SqlField * field, SqlExpr * expr)
|
|
{
|
|
g_return_if_fail (SQL_IS_UPDATE (obj));
|
|
g_return_if_fail (SQL_IS_FIELD (field) && SQL_IS_EXPR (expr));
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
|
|
|
enum
|
|
{
|
|
PROP_SETS = 1
|
|
};
|
|
|
|
static void sql_update_set_property (SqlUpdate * obj, guint id,
|
|
const GValue * value, GParamSpec * pspec)
|
|
{
|
|
switch (id)
|
|
{
|
|
case PROP_SETS:
|
|
sql_object_remove (obj, obj->sets);
|
|
obj->sets = sql_object_add (obj, g_value_get_object (value));
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
}
|
|
}
|
|
|
|
static void sql_update_get_property (SqlUpdate * obj, guint id,
|
|
GValue * value, GParamSpec * pspec)
|
|
{
|
|
switch (id)
|
|
{
|
|
case PROP_SETS:
|
|
g_value_set_object (value, obj->sets);
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
}
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
static void sql_update_init (SqlUpdate * obj)
|
|
{
|
|
obj->sets = NULL;
|
|
}
|
|
|
|
static void sql_update_finalize (SqlUpdate * obj)
|
|
{
|
|
sql_object_remove (obj, obj->sets);
|
|
G_OBJECT_CLASS (sql_update_parent_class)->finalize (G_OBJECT (obj));
|
|
}
|
|
|
|
static void sql_update_class_init (SqlUpdateClass * klass)
|
|
{
|
|
GObjectClass * k = G_OBJECT_CLASS (klass);
|
|
k->finalize = (GObjectFinalizeFunc) sql_update_finalize;
|
|
k->set_property = (GObjectSetPropertyFunc) sql_update_set_property;
|
|
k->get_property = (GObjectGetPropertyFunc) sql_update_get_property;
|
|
SQL_OBJECT_CLASS (klass)->render = (SqlRenderFunc) sql_update_render;
|
|
|
|
g_object_class_install_property (k, PROP_SETS,
|
|
sql_param_list ("sets"
|
|
,"Sets"
|
|
,"A list of sets"
|
|
,SQL_TYPE_UPDATE_SET
|
|
,G_PARAM_READWRITE | G_PARAM_CONSTRUCT
|
|
));
|
|
}
|