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-subquery.c

119 lines
3.2 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-subquery.h"
/**
* SECTION: sql-subquery
* @Short_description: an #SqlTarget containing an #SqlSelect
* @Title: SqlSubquery
*
* An #SqlTarget containing an #SqlSelect, used to add a sub-query to the
* targets field in an SQL query.
**/
G_DEFINE_TYPE (SqlSubquery, sql_subquery, SQL_TYPE_TARGET);
SqlSubquery * sql_subquery_new (SqlSelect * select)
{
return g_object_new (SQL_TYPE_SUBQUERY, "select", select, NULL);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
static void sql_subquery_render (SqlSubquery * obj, SqlRender * render)
{
if (obj->select)
{
sql_render_append (render, "(");
2013-10-14 12:08:06 +00:00
sql_render_add_item (render, T, NULL, obj->select);
2013-10-11 23:07:35 +00:00
sql_render_append (render, ")");
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
void sql_subquery_set_select (SqlSubquery * obj, SqlSelect * select)
{
g_return_if_fail (SQL_IS_SUBQUERY (obj));
2013-10-14 12:08:06 +00:00
g_return_if_fail (SQL_IS_SELECT (select));
2013-10-11 23:07:35 +00:00
2013-10-14 12:08:06 +00:00
g_clear_object (&obj->select);
obj->select = g_object_ref_sink (select);
2013-10-11 23:07:35 +00:00
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
enum
{
PROP_SELECT = 1
};
static void sql_subquery_set_property (SqlSubquery * obj, guint id,
const GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_SELECT:
sql_subquery_set_select (obj, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
}
}
static void sql_subquery_get_property (SqlSubquery * obj, guint id,
GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_SELECT:
g_value_set_object (value, obj->select);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void sql_subquery_init (SqlSubquery * obj)
{
obj->select = NULL;
}
static void sql_subquery_finalize (SqlSubquery * obj)
{
2013-10-14 12:08:06 +00:00
g_clear_object (&obj->select);
2013-10-11 23:07:35 +00:00
G_OBJECT_CLASS (sql_subquery_parent_class)->finalize (G_OBJECT (obj));
}
static void sql_subquery_class_init (SqlSubqueryClass * klass)
{
GObjectClass * k = G_OBJECT_CLASS (klass);
k->finalize = (GObjectFinalizeFunc) sql_subquery_finalize;
k->set_property = (GObjectSetPropertyFunc) sql_subquery_set_property;
k->get_property = (GObjectGetPropertyFunc) sql_subquery_get_property;
SQL_OBJECT_CLASS (klass)->render = (SqlRenderFunc) sql_subquery_render;
g_object_class_install_property (k, PROP_SELECT,
2013-10-14 12:08:06 +00:00
g_param_spec_object ("select"
, "Select"
, "An #SqlSelect"
, SQL_TYPE_SELECT, G_PARAM_READWRITE
2013-10-11 23:07:35 +00:00
));
}