125 lines
3.2 KiB
C
125 lines
3.2 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-select-field.h"
|
|
|
|
/**
|
|
* SECTION: sql-select_field
|
|
* @Short_description:
|
|
* @Title: SqlSelectField
|
|
**/
|
|
G_DEFINE_TYPE (SqlSelectField, sql_select_field, SQL_TYPE_OBJECT);
|
|
|
|
SqlObject * sql_select_field_new ()
|
|
{
|
|
return g_object_new (SQL_TYPE_SELECT_FIELD, NULL);
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
|
|
|
|
static void sql_select_field_render (SqlSelectField * obj, SqlRender * render)
|
|
{
|
|
sql_render_add_object (render, obj->expr);
|
|
|
|
if (obj->alias)
|
|
{
|
|
sql_render_add_token (render, "AS");
|
|
sql_render_add_identifier (render, obj->alias);
|
|
}
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
|
|
|
enum
|
|
{
|
|
PROP_EXPR = 1
|
|
,PROP_ALIAS
|
|
};
|
|
|
|
static void sql_select_field_set_property (SqlSelectField * obj, guint id,
|
|
const GValue * value, GParamSpec * pspec)
|
|
{
|
|
switch (id)
|
|
{
|
|
case PROP_EXPR:
|
|
sql_object_remove (obj, obj->expr);
|
|
obj->expr = sql_object_add (obj, g_value_get_object (value));
|
|
break;
|
|
case PROP_ALIAS:
|
|
g_free (obj->alias);
|
|
obj->alias = g_value_dup_string (value);
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
}
|
|
}
|
|
|
|
static void sql_select_field_get_property (SqlSelectField * obj, guint id,
|
|
GValue * value, GParamSpec * pspec)
|
|
{
|
|
switch (id)
|
|
{
|
|
case PROP_EXPR:
|
|
g_value_set_object (value, obj->expr);
|
|
break;
|
|
case PROP_ALIAS:
|
|
g_value_set_string (value, obj->alias);
|
|
break;
|
|
default:
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
}
|
|
}
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
static void sql_select_field_init (SqlSelectField * obj)
|
|
{
|
|
obj->expr = NULL;
|
|
obj->alias = NULL;
|
|
}
|
|
|
|
static void sql_select_field_finalize (SqlSelectField * obj)
|
|
{
|
|
g_free (obj->alias);
|
|
sql_object_remove (obj, obj->expr);
|
|
G_OBJECT_CLASS (sql_select_field_parent_class)->finalize (G_OBJECT (obj));
|
|
}
|
|
|
|
static void sql_select_field_class_init (SqlSelectFieldClass * klass)
|
|
{
|
|
GObjectClass * k = G_OBJECT_CLASS (klass);
|
|
k->finalize = (GObjectFinalizeFunc) sql_select_field_finalize;
|
|
k->set_property = (GObjectSetPropertyFunc) sql_select_field_set_property;
|
|
k->get_property = (GObjectGetPropertyFunc) sql_select_field_get_property;
|
|
SQL_OBJECT_CLASS (k)->render = (SqlRenderFunc) sql_select_field_render;
|
|
|
|
g_object_class_install_property (k, PROP_EXPR,
|
|
sql_param_object ("expr"
|
|
,("Expression")
|
|
,("The expression")
|
|
,SQL_TYPE_EXPR
|
|
,G_PARAM_READWRITE
|
|
));
|
|
g_object_class_install_property (k, PROP_ALIAS,
|
|
g_param_spec_string ("alias"
|
|
,("Alias")
|
|
,("The alias for the expression")
|
|
,NULL
|
|
,G_PARAM_READWRITE
|
|
));
|
|
}
|