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-select-order.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION: sql-select-order
|
|
|
|
* @Short_description:
|
|
|
|
* @Title: SqlSelectOrder
|
|
|
|
**/
|
|
|
|
G_DEFINE_TYPE (SqlSelectOrder, sql_select_order, SQL_TYPE_OBJECT);
|
|
|
|
|
2013-10-14 11:59:07 +00:00
|
|
|
SqlObject * sql_select_order_new ()
|
2013-10-11 23:07:35 +00:00
|
|
|
{
|
|
|
|
return g_object_new (SQL_TYPE_SELECT_ORDER, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
|
|
|
|
|
|
|
|
static void sql_select_order_render (SqlSelectOrder * obj, SqlRender * render)
|
|
|
|
{
|
|
|
|
sql_render_add_object (render, obj->expr);
|
|
|
|
|
|
|
|
if (obj->way == SQL_SELECT_ORDER_DESC)
|
|
|
|
sql_render_add_token (render, "DESC");
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_EXPR = 1
|
|
|
|
,PROP_WAY
|
|
|
|
};
|
|
|
|
|
|
|
|
static void sql_select_order_set_property (SqlSelectOrder * 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_WAY:
|
|
|
|
obj->way = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sql_select_order_get_property (SqlSelectOrder * obj, guint id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PROP_EXPR:
|
|
|
|
g_value_set_object (value, obj->expr);
|
|
|
|
break;
|
|
|
|
case PROP_WAY:
|
|
|
|
g_value_set_enum (value, obj->way);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
|
|
|
|
|
|
|
static void sql_select_order_init (SqlSelectOrder * obj)
|
|
|
|
{
|
|
|
|
obj->expr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sql_select_order_finalize (SqlSelectOrder * obj)
|
|
|
|
{
|
|
|
|
sql_object_remove (obj, obj->expr);
|
|
|
|
G_OBJECT_CLASS (sql_select_order_parent_class)->finalize (G_OBJECT (obj));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sql_select_order_class_init (SqlSelectOrderClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass * k = G_OBJECT_CLASS (klass);
|
|
|
|
k->finalize = (GObjectFinalizeFunc) sql_select_order_finalize;
|
|
|
|
k->set_property = (GObjectSetPropertyFunc) sql_select_order_set_property;
|
|
|
|
k->get_property = (GObjectGetPropertyFunc) sql_select_order_get_property;
|
|
|
|
SQL_OBJECT_CLASS (k)->render = (SqlRenderFunc) sql_select_order_render;
|
|
|
|
|
|
|
|
g_object_class_install_property (k, PROP_EXPR,
|
|
|
|
sql_param_object ("expr"
|
2014-05-09 11:40:32 +00:00
|
|
|
,("Expression")
|
|
|
|
,("The expression")
|
2013-10-11 23:07:35 +00:00
|
|
|
,SQL_TYPE_EXPR
|
|
|
|
,G_PARAM_READWRITE
|
|
|
|
));
|
|
|
|
g_object_class_install_property (k, PROP_WAY,
|
|
|
|
g_param_spec_enum ("way"
|
2014-05-09 11:40:32 +00:00
|
|
|
,("Way")
|
|
|
|
,("The order way")
|
2013-10-11 23:07:35 +00:00
|
|
|
,SQL_TYPE_SELECT_ORDER_WAY
|
|
|
|
,SQL_SELECT_ORDER_ASC
|
|
|
|
,G_PARAM_READWRITE
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
GType sql_select_order_way_get_type ()
|
|
|
|
{
|
|
|
|
static GType type = 0;
|
|
|
|
|
|
|
|
if (type == 0)
|
|
|
|
{
|
|
|
|
static const GEnumValue values[] =
|
|
|
|
{
|
|
|
|
{SQL_SELECT_ORDER_ASC ,"SQL_SELECT_ORDER_ASC" ,"asc"
|
|
|
|
},{SQL_SELECT_ORDER_DESC ,"SQL_SELECT_ORDER_DESC" ,"desc"
|
|
|
|
},{0, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
type = g_enum_register_static
|
|
|
|
(g_intern_static_string ("SqlSelectOrderWay"), values);
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|