This repository has been archived on 2024-07-15. You can view files and clone it, but cannot push or open issues or pull requests.
hedera/sql/sql-update.c

93 lines
2.6 KiB
C
Raw Normal View History

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-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);
2013-10-14 12:08:06 +00:00
SqlUpdate * sql_update_new ()
2013-10-11 23:07:35 +00:00
{
return g_object_new (SQL_TYPE_UPDATE, NULL);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
2013-10-14 12:08:06 +00:00
static void sql_update_render_set (SqlUpdateSet * set, SqlRender * render)
{
sql_render_add_object (render, set->field);
sql_render_add_token (render, "=");
sql_render_add_object (render, set->expr);
}
2013-10-11 23:07:35 +00:00
static void sql_update_render (SqlUpdate * obj, SqlRender * render)
{
2013-10-14 12:08:06 +00:00
sql_render_add_list (render, T, "UPDATE", SQL_DML (obj)->target, ",");
2013-10-11 23:07:35 +00:00
2013-10-14 12:08:06 +00:00
if (SQL_DML (obj)->target)
2013-10-11 23:07:35 +00:00
{
2013-10-14 12:08:06 +00:00
sql_render_add_list_with_func (render, T, "SET", obj->set, ",",
(SqlRenderFunc) sql_update_render_set);
sql_render_add_item (render, F, "WHERE", SQL_DML (obj)->where);
2013-10-11 23:07:35 +00:00
}
}
2013-10-14 12:08:06 +00:00
static void sql_update_set_free (SqlUpdateSet * obj)
{
g_object_unref (obj->field);
g_object_unref (obj->expr);
g_free (obj);
}
2013-10-11 23:07:35 +00:00
//+++++++++++++++++++++++++++++++++++++++++++++++++++ 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));
2013-10-14 12:08:06 +00:00
SqlUpdateSet * set = g_new (SqlUpdateSet, 1);
set->field = g_object_ref_sink (field);
set->expr = g_object_ref_sink (expr);
obj->set = g_slist_append (obj->set, set);
2013-10-11 23:07:35 +00:00
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void sql_update_init (SqlUpdate * obj)
{
2013-10-14 12:08:06 +00:00
obj->set = NULL;
2013-10-11 23:07:35 +00:00
}
static void sql_update_finalize (SqlUpdate * obj)
{
2013-10-14 12:08:06 +00:00
g_slist_free_full (obj->set, (GFreeFunc) sql_update_set_free);
2013-10-11 23:07:35 +00:00
G_OBJECT_CLASS (sql_update_parent_class)->finalize (G_OBJECT (obj));
}
static void sql_update_class_init (SqlUpdateClass * klass)
{
2013-10-14 12:08:06 +00:00
G_OBJECT_CLASS (klass)->finalize = (GObjectFinalizeFunc) sql_update_finalize;
2013-10-11 23:07:35 +00:00
SQL_OBJECT_CLASS (klass)->render = (SqlRenderFunc) sql_update_render;
}