Añadidos todos los cambios de la rama

This commit is contained in:
Alejandro T. Colombini Gómez 2013-12-16 12:20:33 +01:00
parent f6a57e87b6
commit 55476ff00a
19 changed files with 30 additions and 1516 deletions

View File

@ -2623,7 +2623,6 @@ void db_model_perform_operations (DbModel * obj, gboolean retry)
sql_dml_set_where (SQL_DML (select), SQL_EXPR(op));
if (priv->param_default)
for (sl = priv->param_default; sl; sl = sl->next)
{
gboolean cont = FALSE;

View File

@ -581,9 +581,9 @@ static DbResultSet * __db_pg_query
if (!x)
{
GPtrArray * col_iter = g_ptr_array_index (col, ind)
,* rel_iter = g_ptr_array_index (rel_oid, ind)
,* name_array;
GPtrArray * col_iter = g_ptr_array_index (col, ind),
* rel_iter = g_ptr_array_index (rel_oid, ind),
* name_array;
r = g_slist_nth_data
(list, GPOINTER_TO_UINT (g_ptr_array_index (ind_select, ind)));
@ -615,7 +615,7 @@ static DbResultSet * __db_pg_query
// Set the metadata if it is a *CALCULATED FIELD*
col_tup[j] = -1;
if (fname[0] == '?')
if (fname && fname[0] == '?')
{
r->column[j].name = g_strdup ("");
g_free (fname);
@ -631,14 +631,14 @@ static DbResultSet * __db_pg_query
}
else
for (k = 0; k < ntup; k++)
if (GPOINTER_TO_INT (g_ptr_array_index (col_iter, j))
== atoi (PQgetvalue (res_col, k, 4))
&& GPOINTER_TO_INT (g_ptr_array_index (rel_iter, j))
== atoi (PQgetvalue (res_col, k, 1)))
{
col_tup[j] = k;
break;
}
if (GPOINTER_TO_INT (g_ptr_array_index (col_iter, j))
== atoi (PQgetvalue (res_col, k, 4))
&& GPOINTER_TO_INT (g_ptr_array_index (rel_iter, j))
== atoi (PQgetvalue (res_col, k, 1)))
{
col_tup[j] = k;
break;
}
if (col_tup[j] >= 0) // NOT a calculated field.
{
@ -678,29 +678,27 @@ static DbResultSet * __db_pg_query
g_strfreev (split);
}
else
else if (g_str_has_prefix (pg_val, "nextval"))
{
if (g_str_has_prefix (pg_val, "nextval"))
{// Serial fields
GValue * v = g_new0 (GValue, 1);
gchar ** split = g_strsplit_set (pg_val, "(':)", G_MAXINT8);
SqlFunction * function = sql_function_new ("currval", NULL);
g_value_set_string (g_value_init (v, G_TYPE_STRING), split[2]);
sql_function_add_param (function, sql_value_new_with_value (v));
g_value_unset (v);
g_free (v);
g_value_take_object (g_value_init (&def[j], SQL_TYPE_FUNCTION),
g_object_ref_sink (function));
g_strfreev (split);
}
else
db_pg_set_g_value (&def[j], type, pg_val);
// Serial fields
GValue * v = g_new0 (GValue, 1);
gchar ** split = g_strsplit_set (pg_val, "(':)", G_MAXINT8);
SqlFunction * function = sql_function_new ("currval", NULL);
g_value_set_string (g_value_init (v, G_TYPE_STRING), split[2]);
sql_function_add_param (function, sql_value_new_with_value (v));
g_value_unset (v);
g_free (v);
g_value_take_object (g_value_init (&def[j], SQL_TYPE_FUNCTION),
g_object_ref_sink (function));
g_strfreev (split);
}
else
db_pg_set_g_value (&def[j], type, pg_val);
}
else
g_value_init (&def[j], GVN_TYPE_NULL);
// Checking whether the column can be NULL
nullable[j] = !g_strcmp0 (PQgetvalue (res_col, ctup, 2),"t")
? FALSE : TRUE;
@ -713,10 +711,9 @@ static DbResultSet * __db_pg_query
}
else
{
guint nkeys;
guint l, nkeys, nedit = 0;
gchar ** pkey = NULL;
GSList * prev_tables = NULL;
guint nedit = 0, l;
struct
{
gchar * name;

View File

@ -1,127 +0,0 @@
/*
* 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-holder.h"
/**
* SECTION: sql-holder
* @Short_description:
* @Title: SqlHolder
**/
G_DEFINE_TYPE (SqlHolder, sql_holder, SQL_TYPE_OBJECT);
SqlHolder * sql_holder_new (const gchar * id)
{
return g_object_new (SQL_TYPE_HOLDER, "id", id, NULL);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
static void sql_holder_render (SqlHolder * obj, SqlRender * render)
{
SqlObject * held_object = NULL;
GSList * i = sql_render_get_ancestors (render);
for (; i && !held_object; i = i->next)
held_object = sql_object_get_held_object (held_object, obj->id);
if (held_object)
sql_render_add_object (render, held_object);
else
sql_render_printf (render, "#%s", obj->id);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
/**
* sql_holder_get_id:
* @obj: the #SqlHolder
*
* Gets the identifier assigned to the holder.
*
* Return value: (transfer none): the id
**/
const gchar * sql_holder_get_id (SqlHolder * obj)
{
g_return_val_if_fail (SQL_IS_HOLDER (obj), NULL);
return obj->id;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
enum
{
PROP_ID = 1
};
static void sql_holder_set_property (SqlHolder * obj, guint id,
const GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_ID:
g_free (obj->id);
obj->id = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
}
}
static void sql_holder_get_property (SqlHolder * obj, guint id,
GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_ID:
g_value_set_string (value, sql_holder_get_id (obj));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void sql_holder_init (SqlHolder * obj)
{
obj->id = NULL;
}
static void sql_holder_finalize (SqlHolder * obj)
{
g_free (obj->id);
G_OBJECT_CLASS (sql_holder_finalize)->finalize (G_OBJECT (obj));
}
static void sql_holder_class_init (SqlHolderClass * k)
{
GObjectClass * klass = G_OBJECT_CLASS (k);
klass->finalize = (GObjectFinalizeFunc) sql_holder_finalize;
klass->set_property = (GObjectSetPropertyFunc) sql_holder_set_property;
klass->get_property = (GObjectGetPropertyFunc) sql_holder_get_property;
SQL_OBJECT_CLASS (klass)->render = (SqlRenderFunc) sql_holder_render;
g_object_class_install_property (klass, PROP_ID,
g_param_spec_string ("id"
,_("Identifier")
,_("The holder identifier")
,NULL
,G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY
));
}

View File

@ -1,46 +0,0 @@
/*
* 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/>.
*/
#ifndef SQL_HOLDER_H
#define SQL_HOLDER_H
#include "sql-object.h"
#define SQL_TYPE_HOLDER (sql_holder_get_type ())
#define SQL_HOLDER(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, SQL_TYPE_HOLDER, SqlHolder))
#define SQL_IS_HOLDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, SQL_TYPE_HOLDER))
typedef struct _SqlHolder SqlHolder;
typedef struct _SqlHolderClass SqlHolderClass;
struct _SqlHolder
{
SqlObject parent;
gchar * id;
};
struct _SqlHolderClass
{
/* <private> */
SqlObjectClass parent;
};
GType sql_holder_get_type ();
SqlHolder * sql_holder_new (const gchar * id);
const gchar * sql_holder_get_id (SqlHolder * obj);
#endif

View File

@ -1,266 +0,0 @@
/*
* 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-list.h"
/**
* SECTION: sql-list
* @Short_description: Container for a list of #SqlObject of a certain type
* @Title: SqlList
**/
G_DEFINE_TYPE (SqlList, sql_list, SQL_TYPE_OBJECT);
SqlList * sql_list_new (GType gtype)
{
return g_object_new (SQL_TYPE_LIST, "gtype", gtype, NULL);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
static void sql_list_render (SqlList * obj, SqlRender * render)
{
GList * i;
for (i = obj->items.tail; i; i = i->next)
{
sql_render_add_object (render, i->data);
if (i->next)
sql_render_append (render, ", ");
}
}
static gboolean sql_list_is_ready (SqlList * obj)
{
GList * i;
for (i = obj->items.tail; i; i = i->next)
if (!sql_object_is_ready (i->data))
return FALSE;
return TRUE;
}
static void sql_list_item_changed (SqlObject * item, SqlObject * obj)
{
sql_object_changed (obj);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
/**
* sql_list_add:
* @obj: the #SqlList
* @item: (allow-none): the #SqlObject
*
* Adds an item to the end of the list.
**/
void sql_list_add (SqlList * obj, gpointer item)
{
g_return_if_fail (SQL_IS_LIST (obj));
sql_list_insert (obj, item, -1);
}
/**
* sql_list_insert:
* @obj: the #SqlList
* @item: (allow-none): the #SqlObject
* @n: the position in which to place the item
*
* Adds an item to the list. If position is a negative number the element will
* be added to the end of the list.
**/
void sql_list_insert (SqlList * obj, gpointer item, guint n)
{
g_return_if_fail (SQL_IS_LIST (obj));
g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (item, obj->gtype) || SQL_IS_HOLDER (item) || !item);
if (n > 0)
g_queue_push_nth (&obj->items, g_object_ref_sink (item), n);
else
g_queue_push_head (&obj->items, g_object_ref_sink (item));
g_signal_connect (item, "changed",
G_CALLBACK (sql_list_item_changed), obj
);
}
/**
* sql_list_get:
* @obj: the #SqlList
*
* Gets an item from the list.
*
* Return value: (transfer none) (allow-none): the selected #SqlObject
**/
gpointer sql_list_get (SqlList * obj, guint n)
{
g_return_val_if_fail (SQL_IS_LIST (obj), NULL);
return g_queue_peek_nth (&obj->items, n);
}
/**
* sql_list_remove:
* @obj: the #SqlList
*
* Removes an item from the list.
*
* Return value: (transfer none) (allow-none): the removed #SqlObject
**/
gpointer sql_list_remove (SqlList * obj, guint n)
{
SqlObject * item;
g_return_val_if_fail (SQL_IS_LIST (obj), NULL);
item = g_queue_pop_nth (&obj->items, n);
g_signal_handlers_disconnect_by_func (item,
sql_list_item_changed, obj);
return item;
}
/**
* sql_list_get_items:
* @obj: the #SqlList
*
* Gets all list elements.
*
* Return value: (transfer none) (allow-none): the list items
**/
GList * sql_list_get_items (SqlList * obj)
{
g_return_val_if_fail (SQL_IS_LIST (obj), NULL);
return obj->items.tail;
}
/**
* sql_list_get_items_type:
* @obj: the #SqlList
*
* Gets the allowed type for the list elements.
*
* Return value: the #GType
**/
GType sql_list_get_items_type (SqlList * obj)
{
g_return_val_if_fail (SQL_IS_LIST (obj), 0);
return obj->gtype;
}
/**
* sql_list_lenght:
* @obj: the #SqlList
*
* Gets the number of items in the list.
*
* Return value: the number of items
**/
guint sql_list_length (SqlList * obj)
{
g_return_val_if_fail (SQL_IS_LIST (obj), 0);
return obj->items.length;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
enum
{
PROP_GTYPE = 1
,PROP_LENGTH
};
static void sql_list_set_property (SqlList * obj, guint id,
const GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_GTYPE:
obj->gtype = g_value_get_gtype (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
}
}
static void sql_list_get_property (SqlList * obj, guint id,
GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_GTYPE:
g_value_set_gtype (value, obj->gtype);
break;
case PROP_LENGTH:
g_value_set_uint (value, sql_list_length (obj));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void sql_list_init (SqlList * obj)
{
g_queue_init (&obj->items);
}
static void sql_list_finalize (SqlList * obj)
{
GList * i;
for (i = obj->items.tail; i; i = i->next)
{
g_signal_handlers_disconnect_by_func (i->data,
sql_list_item_changed, obj);
g_object_unref (i->data);
}
g_queue_clear (&obj->items);
G_OBJECT_CLASS (sql_list_finalize)->finalize (G_OBJECT (obj));
}
static void sql_list_class_init (SqlListClass * k)
{
GObjectClass * klass = G_OBJECT_CLASS (k);
klass->finalize = (GObjectFinalizeFunc) sql_list_finalize;
klass->set_property = (GObjectSetPropertyFunc) sql_list_set_property;
klass->get_property = (GObjectGetPropertyFunc) sql_list_get_property;
SQL_OBJECT_CLASS (klass)->render = (SqlRenderFunc) sql_list_render;
SQL_OBJECT_CLASS (klass)->is_ready = (SqlObjectIsReadyFunc) sql_list_is_ready;
g_object_class_install_property (klass, PROP_LENGTH,
g_param_spec_uint ("length"
,_("Length")
,_("The length of the list")
,0, G_MAXUINT, 0
,G_PARAM_READABLE
));
g_object_class_install_property (klass, PROP_GTYPE,
g_param_spec_gtype ("gtype"
,_("GType")
,_("The allowed type for the items")
,SQL_TYPE_OBJECT
,G_PARAM_READABLE | G_PARAM_CONSTRUCT_ONLY
));
}

View File

@ -1,53 +0,0 @@
/*
* 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/>.
*/
#ifndef SQL_LIST_H
#define SQL_LIST_H
#define SQL_TYPE_LIST (sql_list_get_type ())
#define SQL_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, SQL_TYPE_LIST, SqlList))
#define SQL_IS_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, SQL_TYPE_LIST))
typedef struct _SqlList SqlList;
typedef struct _SqlListClass SqlListClass;
#include "sql-object.h"
struct _SqlList
{
SqlObject parent;
GType gtype;
GQueue items;
};
struct _SqlListClass
{
/* <private> */
SqlObjectClass parent;
};
GType sql_list_get_type ();
SqlList * sql_list_new (GType gtype);
void sql_list_add (SqlList * obj, gpointer item);
void sql_list_insert (SqlList * obj, gpointer item, guint n);
gpointer sql_list_get (SqlList * obj, guint n);
gpointer sql_list_remove (SqlList * obj, guint n);
GList * sql_list_get_items (SqlList * obj);
GType sql_list_get_items_type (SqlList * obj);
guint sql_list_length (SqlList * obj);
#endif

View File

@ -1,109 +0,0 @@
/*
* Copyright (C) 2013 - 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-param-list.h"
#include "sql-holder.h"
GParamSpec *
sql_param_list (const gchar * name, const gchar * nick,
const gchar * blurb, GType items_type, GParamFlags flags)
{
SqlParamList * pspec;
g_return_val_if_fail (g_type_is_a (items_type, SQL_TYPE_OBJECT), NULL);
pspec = g_param_spec_internal (SQL_TYPE_PARAM_OBJECT
,name
,nick
,blurb
,flags
);
pspec->items_type = items_type;
G_PARAM_SPEC (pspec)->value_type = SQL_TYPE_LIST;
return G_PARAM_SPEC (pspec);
}
static void
sql_param_list_init (GParamSpec * pspec) {}
static void
sql_param_list_set_default (GParamSpec * pspec, GValue * value)
{
SqlList * list = sql_list_new (SQL_PARAM_LIST (pspec)->items_type);
g_value_set_object (value, list);
}
static gboolean
sql_param_list_validate (GParamSpec * pspec, GValue * value)
{
GType type;
gboolean change;
gpointer object = g_value_get_object (value);
if (!object)
return TRUE;
type = G_OBJECT_TYPE (object);
change = !(
(g_value_type_compatible (type, SQL_TYPE_LIST)
&& SQL_PARAM_LIST (pspec)->items_type == sql_list_get_items_type (object))
|| g_value_type_compatible (type, SQL_TYPE_HOLDER)
);
if (change)
g_value_set_object (value, NULL);
return change;
}
static gint
sql_param_list_values_cmp (GParamSpec * pspec, const GValue * a, const GValue * b)
{
guint8 * pa = g_value_get_object (a);
guint8 * pb = g_value_get_object (b);
return pa < pb ? -1 : pa > pb;
}
GType
sql_param_list_get_type ()
{
static GType type = 0;
if (!type)
{
GParamSpecTypeInfo pspec_info =
{
sizeof (SqlParamList)
,16
,sql_param_list_init
,SQL_TYPE_LIST
,NULL
,sql_param_list_set_default
,sql_param_list_validate
,sql_param_list_values_cmp
};
type = g_param_type_register_static (
g_intern_static_string ("SqlParamList"), &pspec_info);
}
return type;
}

View File

@ -1,42 +0,0 @@
/*
* Copyright (C) 2013 - 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/>.
*/
#ifndef SQL_PARAM_LIST_H
#define SQL_PARAM_LIST_H
#include "sql-object.h"
#define SQL_TYPE_PARAM_LIST (sql_param_list_get_type ())
#define SQL_PARAM_LIST(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), SQL_TYPE_PARAM_LIST, SqlParamList))
typedef struct
{
GParamSpec parent;
GType items_type;
}
SqlParamList;
GType sql_param_list_get_type ();
GParamSpec * sql_param_list (const gchar * name
,const gchar * nick
,const gchar * blurb
,GType items_type
,GParamFlags flags);
#endif

View File

@ -1,106 +0,0 @@
/*
* Copyright (C) 2013 - 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-param-object.h"
#include "sql-holder.h"
GParamSpec *
sql_param_object (const gchar * name, const gchar * nick,
const gchar * blurb, GType object_type, GParamFlags flags)
{
GParamSpec * pspec;
g_return_val_if_fail (g_type_is_a (object_type, SQL_TYPE_OBJECT), NULL);
pspec = g_param_spec_internal (SQL_TYPE_PARAM_OBJECT
,name
,nick
,blurb
,flags
);
pspec->value_type = object_type;
return pspec;
}
static void
sql_param_object_init (GParamSpec * pspec) {}
static void
sql_param_object_set_default (GParamSpec * pspec, GValue * value)
{
g_value_set_object (value, NULL);
}
static gboolean
sql_param_object_validate (GParamSpec * pspec, GValue * value)
{
GType type;
gboolean change;
GObject * object = g_value_get_object (value);
if (!object)
return TRUE;
type = G_OBJECT_TYPE (object);
change = !(
g_value_type_compatible (type, G_PARAM_SPEC_VALUE_TYPE (pspec))
|| g_value_type_compatible (type, SQL_TYPE_HOLDER)
);
if (change)
g_value_set_object (value, NULL);
return change;
}
static gint
sql_param_object_values_cmp (GParamSpec * pspec, const GValue * a, const GValue * b)
{
guint8 * pa = g_value_get_object (a);
guint8 * pb = g_value_get_object (b);
return pa < pb ? -1 : pa > pb;
}
GType
sql_param_object_get_type ()
{
static GType type = 0;
if (!type)
{
GParamSpecTypeInfo pspec_info =
{
sizeof (SqlParamObject)
,16
,sql_param_object_init
,SQL_TYPE_OBJECT
,NULL
,sql_param_object_set_default
,sql_param_object_validate
,sql_param_object_values_cmp
};
type = g_param_type_register_static (
g_intern_static_string ("SqlParamObject"), &pspec_info);
}
return type;
}

View File

@ -1,39 +0,0 @@
/*
* Copyright (C) 2013 - 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/>.
*/
#ifndef SQL_PARAM_OBJECT_H
#define SQL_PARAM_OBJECT_H
#include "sql-object.h"
#define SQL_TYPE_PARAM_OBJECT (sql_param_object_get_type ())
#define SQL_PARAM_OBJECT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), SQL_TYPE_PARAM_OBJECT, SqlParamObject))
typedef struct
{
GParamSpec parent;
}
SqlParamObject;
GType sql_param_object_get_type ();
GParamSpec * sql_param_object (const gchar * name
,const gchar * nick
,const gchar * blurb
,GType object_type
,GParamFlags flags);
#endif

View File

@ -1,124 +0,0 @@
/*
* 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);
SqlSelectField * 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
));
}

View File

@ -1,47 +0,0 @@
/*
* 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/>.
*/
#ifndef SQL_SELECT_FIELD_H
#define SQL_SELECT_FIELD_H
#include "sql-object.h"
#include "sql-expr.h"
#define SQL_TYPE_SELECT_FIELD (sql_select_field_get_type ())
#define SQL_SELECT_FIELD(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, SQL_TYPE_SELECT_FIELD, SqlSelectField))
#define SQL_IS_SELECT_FIELD(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, SQL_TYPE_SELECT_FIELD))
typedef struct _SqlSelectField SqlSelectField;
typedef struct _SqlSelectFieldClass SqlSelectFieldClass;
struct _SqlSelectField
{
SqlObject parent;
SqlExpr * expr;
gchar * alias;
};
struct _SqlSelectFieldClass
{
/* <private> */
SqlObjectClass parent;
};
GType sql_select_field_get_type ();
SqlSelectField * sql_select_field_new ();
#endif

View File

@ -1,139 +0,0 @@
/*
* 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);
SqlSelectOrder * sql_select_order_new ()
{
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"
,"Expression"
,"The expression"
,SQL_TYPE_EXPR
,G_PARAM_READWRITE
));
g_object_class_install_property (k, PROP_WAY,
g_param_spec_enum ("way"
,"Way"
,"The order way"
,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;
}

View File

@ -1,63 +0,0 @@
/*
* 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/>.
*/
#ifndef SQL_SELECT_ORDER_H
#define SQL_SELECT_ORDER_H
#include "sql-object.h"
#include "sql-expr.h"
#define SQL_TYPE_SELECT_ORDER (sql_select_order_get_type ())
#define SQL_SELECT_ORDER(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, SQL_TYPE_SELECT_ORDER, SqlSelectOrder))
#define SQL_IS_SELECT_ORDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, SQL_TYPE_SELECT_ORDER))
#define SQL_TYPE_SELECT_ORDER_WAY (sql_select_order_way_get_type ())
typedef struct _SqlSelectOrder SqlSelectOrder;
typedef struct _SqlSelectOrderClass SqlSelectOrderClass;
/**
* SqlSelectOrderWay:
* @SQL_SELECT_ORDER_ASC: ascendent order
* @SQL_SELECT_ORDER_DESC: descendent order
**/
typedef enum
{
SQL_SELECT_ORDER_ASC
,SQL_SELECT_ORDER_DESC
}
SqlSelectOrderWay;
struct _SqlSelectOrder
{
SqlObject parent;
SqlExpr * expr;
SqlSelectOrderWay way;
};
struct _SqlSelectOrderClass
{
/* <private> */
SqlObjectClass parent;
};
GType sql_select_order_get_type ();
GType sql_select_order_way_get_type ();
SqlSelectOrder * sql_select_order_new ();
#endif

View File

@ -1,108 +0,0 @@
/*
* 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-set.h"
/**
* SECTION: sql-set
* @Short_description: represents any set used in SQL.
* @Title: SqlSet
**/
G_DEFINE_TYPE (SqlSet, sql_set, SQL_TYPE_EXPR);
SqlSet * sql_set_new ()
{
return g_object_new (SQL_TYPE_SET, NULL);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
static void sql_set_render (SqlSet * obj, SqlRender * render)
{
/* if (obj)
sql_render_add_object (render, obj);
else
sql_render_add_token (render, "DEFAULT");
*/
sql_render_append (render, "(");
sql_render_add_list (render, FALSE, NULL, obj->exprs, ",");
sql_render_append (render, ")");
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
enum
{
PROP_EXPRS = 1
};
static void sql_set_set_property (SqlSet * obj, guint id,
const GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_EXPRS:
sql_object_remove (obj, obj->exprs);
obj->exprs = sql_object_add (obj, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
}
}
static void sql_set_get_property (SqlSet * obj, guint id,
GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_EXPRS:
g_value_set_object (value, obj->exprs);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void sql_set_init (SqlSet * obj)
{
obj->exprs = NULL;
}
static void sql_set_finalize (SqlSet * obj)
{
sql_object_remove (obj, obj->exprs);
G_OBJECT_CLASS (sql_set_parent_class)->finalize (G_OBJECT (obj));
}
static void sql_set_class_init (SqlSetClass * klass)
{
GObjectClass * k = G_OBJECT_CLASS (klass);
k->finalize = (GObjectFinalizeFunc) sql_set_finalize;
k->set_property = (GObjectSetPropertyFunc) sql_set_set_property;
k->get_property = (GObjectGetPropertyFunc) sql_set_get_property;
SQL_OBJECT_CLASS (klass)->render = (SqlRenderFunc) sql_set_render;
g_object_class_install_property (k, PROP_EXPRS,
sql_param_list ("exprs"
,"Expressions"
,"The list of expressions"
,SQL_TYPE_EXPR
,G_PARAM_READWRITE
));
}

View File

@ -1,45 +0,0 @@
/*
* 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/>.
*/
#ifndef SQL_SET_H
#define SQL_SET_H
#include "sql-expr.h"
#define SQL_TYPE_SET (sql_set_get_type ())
#define SQL_SET(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, SQL_TYPE_SET, SqlSet))
#define SQL_IS_SET(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, SQL_TYPE_SET))
typedef struct _SqlSet SqlSet;
typedef struct _SqlSetClass SqlSetClass;
struct _SqlSet
{
SqlExpr parent;
SqlList * exprs;
};
struct _SqlSetClass
{
/* <private> */
SqlObjectClass parent;
};
GType sql_set_get_type ();
SqlSet * sql_set_new ();
#endif

View File

@ -1,120 +0,0 @@
/*
* 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-update-set.h"
/**
* SECTION: sql-update_set
* @Short_description: Defines a field for the SET clause for an #SqlUpdate.
* @Title: SqlUpdateSet
**/
G_DEFINE_TYPE (SqlUpdateSet, sql_update_set, SQL_TYPE_OBJECT);
SqlUpdateSet * sql_update_set_new ()
{
return g_object_new (SQL_TYPE_UPDATE_SET, NULL);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
static void sql_update_set_render (SqlUpdateSet * set, SqlRender * render)
{
sql_render_add_object (render, set->field);
sql_render_add_token (render, "=");
sql_render_add_object (render, set->expr);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
enum
{
PROP_FIELD = 1
,PROP_EXPR
};
static void sql_update_set_set_property (SqlUpdateSet * obj, guint id,
const GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_FIELD:
sql_object_remove (obj, obj->field);
obj->field = sql_object_add (obj, g_value_get_object (value));
break;
case PROP_EXPR:
sql_object_remove (obj, obj->expr);
obj->expr = sql_object_add (obj, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
}
}
static void sql_update_set_get_property (SqlUpdateSet * obj, guint id,
GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_FIELD:
g_value_set_object (value, obj->field);
break;
case PROP_EXPR:
g_value_set_object (value, obj->expr);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void sql_update_set_init (SqlUpdateSet * obj)
{
obj->field = NULL;
obj->expr = NULL;
}
static void sql_update_set_finalize (SqlUpdateSet * obj)
{
sql_object_remove (obj, obj->field);
sql_object_remove (obj, obj->expr);
G_OBJECT_CLASS (sql_update_set_parent_class)->finalize (G_OBJECT (obj));
}
static void sql_update_set_class_init (SqlUpdateSetClass * klass)
{
GObjectClass * k = G_OBJECT_CLASS (klass);
k->finalize = (GObjectFinalizeFunc) sql_update_set_finalize;
k->set_property = (GObjectSetPropertyFunc) sql_update_set_set_property;
k->get_property = (GObjectGetPropertyFunc) sql_update_set_get_property;
SQL_OBJECT_CLASS (klass)->render = (SqlRenderFunc) sql_update_set_render;
g_object_class_install_property (k, PROP_FIELD,
g_param_spec_object ("field"
,"Field"
,"The field"
,SQL_TYPE_FIELD
,G_PARAM_READWRITE
));
g_object_class_install_property (k, PROP_EXPR,
g_param_spec_object ("expr"
,"Expression"
,"The expression"
,SQL_TYPE_EXPR
,G_PARAM_READWRITE
));
}

View File

@ -1,48 +0,0 @@
/*
* 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/>.
*/
#ifndef SQL_UPDATE_SET_H
#define SQL_UPDATE_SET_H
#include "sql-object.h"
#include "sql-field.h"
#include "sql-expr.h"
#define SQL_TYPE_UPDATE_SET (sql_update_set_get_type ())
#define SQL_UPDATE_SET(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, SQL_TYPE_UPDATE_SET, SqlUpdateSet))
#define SQL_IS_UPDATE_SET(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, SQL_TYPE_UPDATE_SET))
typedef struct _SqlUpdateSet SqlUpdateSet;
typedef struct _SqlUpdateSetClass SqlUpdateSetClass;
struct _SqlUpdateSet
{
SqlObject parent;
SqlField * field;
SqlExpr * expr;
};
struct _SqlUpdateSetClass
{
/* <private> */
SqlObjectClass parent;
};
GType sql_update_set_get_type ();
SqlUpdateSet * sql_update_set_new ();
#endif

View File

@ -38,7 +38,7 @@ static void vn_column_spin_on_edited (GtkCellRendererSpin * cell,
val = min;
else if (val > max)
val = max;
g_value_init (&value, G_TYPE_DOUBLE);
g_value_set_double (&value, val);
g_object_set (obj->adjustment, "value", val, NULL);
@ -194,7 +194,7 @@ static void vn_column_spin_class_init (VnColumnSpinClass * klass)
g_param_spec_double ("upper"
,_("Maximum value")
,_("The maximum value of the adjustment.")
,-G_MAXDOUBLE ,G_MAXDOUBLE , G_MAXDOUBLE
,-G_MAXDOUBLE ,G_MAXDOUBLE , 0.0
,G_PARAM_CONSTRUCT | G_PARAM_READWRITE
));