/* * 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 . */ #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, "("); sql_render_add_item (render, TRUE, NULL, obj->select); sql_render_append (render, ")"); } } //+++++++++++++++++++++++++++++++++++++++++++++++++++ Public void sql_subquery_set_select (SqlSubquery * obj, SqlSelect * select) { g_return_if_fail (SQL_IS_SUBQUERY (obj)); g_return_if_fail (SQL_IS_SELECT (select) || !select); sql_object_remove (obj, obj->select); obj->select = sql_object_add (obj, select); } //+++++++++++++++++++++++++++++++++++++++++++++++++++ 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) { sql_object_remove (obj, obj->select); 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, sql_param_object ("select" ,"Select" ,"The SELECT statement" ,SQL_TYPE_SELECT ,G_PARAM_READWRITE )); }