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

/*
* 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);
SqlUpdate * sql_update_new ()
{
return g_object_new (SQL_TYPE_UPDATE, NULL);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
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);
}
static void sql_update_render (SqlUpdate * obj, SqlRender * render)
{
sql_render_add_list (render, T, "UPDATE", SQL_DML (obj)->target, ",");
if (SQL_DML (obj)->target)
{
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);
}
}
static void sql_update_set_free (SqlUpdateSet * obj)
{
g_object_unref (obj->field);
g_object_unref (obj->expr);
g_free (obj);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ 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));
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);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void sql_update_init (SqlUpdate * obj)
{
obj->set = NULL;
}
static void sql_update_finalize (SqlUpdate * obj)
{
g_slist_free_full (obj->set, (GFreeFunc) sql_update_set_free);
G_OBJECT_CLASS (sql_update_parent_class)->finalize (G_OBJECT (obj));
}
static void sql_update_class_init (SqlUpdateClass * klass)
{
G_OBJECT_CLASS (klass)->finalize = (GObjectFinalizeFunc) sql_update_finalize;
SQL_OBJECT_CLASS (klass)->render = (SqlRenderFunc) sql_update_render;
}