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

189 lines
5.4 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-operation.h"
#include "sql-value.h"
/**
* SECTION: sql-operation
* @Short_description: operations between #SqlExpr
* @Title: SqlOperation
*
* Any operation over or between one or more #SqlExpr is represented by the
* #SqlOperation of the corresponding type. To see the different types of
* #SqlOperation see #SqlOperationType.
**/
G_DEFINE_TYPE (SqlOperation, sql_operation, SQL_TYPE_EXPR);
SqlObject * sql_operation_new (SqlOperationType type)
{
return g_object_new (SQL_TYPE_OPERATION, "type", type, NULL);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
static const gchar * SQL_OPERATION_TYPE[] =
{
"NOT"
,"-"
,"+"
,"*"
,"/"
,"+"
,"-"
,"IS"
,"="
,"!="
,">="
,">"
,"<="
,"<"
,"LIKE"
,"AND"
,"OR"
,"XOR"
,"%"
,"IN"
};
static void sql_operation_render (SqlOperation * obj, SqlRender * render)
{
sql_render_add_espace (render);
sql_render_append (render, "(");
sql_render_add_list (render, TRUE, NULL, obj->operators,
SQL_OPERATION_TYPE[obj->type]);
sql_render_append (render, ")");
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
enum
{
PROP_TYPE = 1
,PROP_OPERATORS
};
static void sql_operation_set_property (SqlOperation * obj, guint id,
const GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_TYPE:
obj->type = g_value_get_enum (value);
break;
case PROP_OPERATORS:
sql_object_remove (obj, obj->operators);
obj->operators = sql_object_add (obj, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
}
}
static void sql_operation_get_property (SqlOperation * obj, guint id,
GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_TYPE:
g_value_set_enum (value, obj->type);
break;
case PROP_OPERATORS:
g_value_set_object (value, obj->operators);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void sql_operation_init (SqlOperation * obj)
{
obj->operators = NULL;
}
static void sql_operation_finalize (SqlOperation * obj)
{
sql_object_remove (obj, obj->operators);
G_OBJECT_CLASS (sql_operation_parent_class)->finalize (G_OBJECT (obj));
}
static void sql_operation_class_init (SqlOperationClass * klass)
{
GObjectClass * k = G_OBJECT_CLASS (klass);
k->finalize = (GObjectFinalizeFunc) sql_operation_finalize;
k->set_property = (GObjectSetPropertyFunc) sql_operation_set_property;
k->get_property = (GObjectGetPropertyFunc) sql_operation_get_property;
SQL_OBJECT_CLASS (klass)->render = (SqlRenderFunc) sql_operation_render;
g_object_class_install_property (k, PROP_TYPE,
g_param_spec_enum ("type"
,"Type"
,"The type of the operation"
,SQL_TYPE_OPERATION_TYPE
,SQL_OPERATION_TYPE_AND
,G_PARAM_READWRITE
));
g_object_class_install_property (k, PROP_OPERATORS,
sql_param_list ("operators"
,"Operators"
,"The list of operators"
,SQL_TYPE_EXPR
,G_PARAM_READWRITE
));
}
GType sql_operation_type_get_type ()
{
static GType type = 0;
if (type == 0)
{
static const GEnumValue values[] =
{
{SQL_OPERATION_TYPE_NOT ,"SQL_OPERATION_TYPE_NOT" ,"not"
},{SQL_OPERATION_TYPE_MINUS ,"SQL_OPERATION_TYPE_MINUS" ,"minus"
},{SQL_OPERATION_TYPE_PLUS ,"SQL_OPERATION_TYPE_PLUS" ,"plus"
},{SQL_OPERATION_TYPE_MULTIPLICATION ,"SQL_OPERATION_TYPE_MULTIPLICATION" ,"multiplication"
},{SQL_OPERATION_TYPE_DIVISION ,"SQL_OPERATION_TYPE_DIVISION" ,"division"
},{SQL_OPERATION_TYPE_SUM ,"SQL_OPERATION_TYPE_SUM" ,"sum"
},{SQL_OPERATION_TYPE_SUBTRACTION ,"SQL_OPERATION_TYPE_SUBTRACTION" ,"subtraction"
},{SQL_OPERATION_TYPE_IS ,"SQL_OPERATION_TYPE_IS" ,"is"
},{SQL_OPERATION_TYPE_EQUAL ,"SQL_OPERATION_TYPE_EQUAL" ,"equal"
},{SQL_OPERATION_TYPE_NOT_EQUAL ,"SQL_OPERATION_TYPE_NOT_EQUAL" ,"not-equal"
},{SQL_OPERATION_TYPE_GREATER_EQUAL ,"SQL_OPERATION_TYPE_GREATER_EQUAL" ,"greater-equal"
},{SQL_OPERATION_TYPE_GREATER ,"SQL_OPERATION_TYPE_GREATER" ,"greater"
},{SQL_OPERATION_TYPE_LOWER_EQUAL ,"SQL_OPERATION_TYPE_LOWER_EQUAL" ,"lower-equal"
},{SQL_OPERATION_TYPE_LOWER ,"SQL_OPERATION_TYPE_LOWER" ,"lower"
},{SQL_OPERATION_TYPE_LIKE ,"SQL_OPERATION_TYPE_LIKE" ,"like"
},{SQL_OPERATION_TYPE_AND ,"SQL_OPERATION_TYPE_AND" ,"and"
},{SQL_OPERATION_TYPE_OR ,"SQL_OPERATION_TYPE_OR" ,"or"
},{SQL_OPERATION_TYPE_XOR ,"SQL_OPERATION_TYPE_XOR" ,"xor"
},{SQL_OPERATION_TYPE_MOD ,"SQL_OPERATION_TYPE_MOD" ,"mod"
},{SQL_OPERATION_TYPE_IN ,"SQL_OPERATION_TYPE_IN" ,"in"
},{0, NULL, NULL}
};
type = g_enum_register_static
(g_intern_static_string ("SqlOperationType"), values);
}
return type;
}