- Version estable pero sin analisis de joins.
This commit is contained in:
Juan Ferrer Toribio 2014-06-05 17:59:35 +02:00
parent a48f4923f4
commit 090b4124da
17 changed files with 1013 additions and 863 deletions

View File

@ -17,6 +17,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define remove_delimiters(str) (g_strdup (g_strstrip (g_strdelimit (str, "`\"", ' '))))
/*
* DbUpdatedField:
* @column: the position of the field in the row
@ -80,6 +82,41 @@ typedef struct
}
DbModelRequest;
//----------------------------------------------- Table
typedef struct
{
gchar * name;
gchar * schema;
}
Table;
static Table * table_copy (Table * src)
{
Table * table = g_new0 (Table, 1);
table->name = g_strdup (src->name);
table->schema = g_strdup (src->schema);
return table;
}
static void table_free (Table * table)
{
g_free (table->name);
g_free (table->schema);
g_free (table);
}
static gboolean table_equal (const Table * a, const Table * b)
{
return !g_strcmp0 (a->name, b->name)
&& !g_strcmp0 (a->schema, b->schema);
}
static guint table_hash (const Table * table)
{
return g_str_hash (table->name);
}
//----------------------------------------------- Field
typedef struct
@ -90,8 +127,6 @@ typedef struct
}
Field;
#define remove_delimiters(str) (g_strdup (g_strstrip (g_strdelimit (str, "`\"", ' '))))
static void field_parse (Field * field, const gchar * string)
{
gchar ** split = g_strsplit (string, ".", 0);
@ -136,133 +171,61 @@ static guint field_hash (const Field * field)
return g_str_hash (field->name);
}
//----------------------------------------------- Table
//----------------------------------------------- TableInfo
typedef struct
{
gchar * name;
gchar * schema;
}
Table;
static void table_parse (Table * table, const gchar * string)
{
gchar ** split = g_strsplit (string, ".", 0);
guint len = g_strv_length (split);
table->name = len > 0 ? remove_delimiters (split[--len]) : NULL;
table->schema = len > 0 ? remove_delimiters (split[--len]) : NULL;
g_strfreev (split);
}
static Table * table_copy (Table * src)
{
Table * table = g_new0 (Table, 1);
table->name = g_strdup (src->name);
table->schema = g_strdup (src->schema);
return table;
}
static void table_free (Table * table)
{
g_free (table->name);
g_free (table->schema);
g_free (table);
}
static gboolean table_equal (const Table * a, const Table * b)
{
return !g_strcmp0 (a->name, b->name)
&& !g_strcmp0 (a->schema, b->schema);
}
static guint table_hash (const Table * table)
{
return g_str_hash (table->name);
}
static gboolean table_has_column (Table * table, DbColumn * column)
{
return !g_strcmp0 (column->table, table->name)
&& !g_strcmp0 (column->schema, table->schema);
}
//----------------------------------------------- TableData
typedef struct
{
gchar * alias;
GSList * pkeys;
GHashTable * columns;
GSList * parent_columns;
GSList * child_columns;
}
TableData;
TableInfo;
static void table_data_free (TableData * table_data)
static void table_info_free (TableInfo * table_info)
{
g_slist_free (table_data->pkeys);
g_free (table_data);
}
//----------------------------------------------- ParamDef
typedef struct
{
GvnParam * param;
SqlObject * equal_op;
SqlObject * link_op;
}
ParamDef;
static void param_def_free (ParamDef * def)
{
g_object_unref (def->param);
if (def->equal_op)
{
SqlObject * operators = sql_object_get (def->link_op, "operators");
sql_list_remove_item (SQL_LIST (operators), def->equal_op);
}
g_free (def);
g_free (table_info->name);
g_free (table_info->schema);
g_free (table_info->alias);
g_slist_free (table_info->pkeys);
g_hash_table_unref (table_info->columns);
g_slist_free (table_info->parent_columns);
g_slist_free (table_info->child_columns);
}
//----------------------------------------------- ColumnDef
typedef enum
{
PARAM_DEF,
FIELD_DEF
}
DefType;
typedef struct
{
Field * field;
gpointer def;
DefType type;
gulong link;
GvnParam * param;
Field * src_column;
}
ColumnDef;
static ColumnDef * column_def_new (DefType type, gpointer def)
static ColumnDef * column_def_new ()
{
ColumnDef * column_def = g_new (ColumnDef, 1);
column_def->type = type;
column_def->def = def;
column_def->link = 0;
column_def->param = NULL;
column_def->src_column = NULL;
return column_def;
}
static void column_def_free (ColumnDef * def)
{
field_free (def->field);
switch (def->type)
if (def->param)
{
case PARAM_DEF:
param_def_free (def->def);
break;
case FIELD_DEF:
field_free (def->def);
break;
if (def->link)
g_signal_handler_disconnect (def->param, def->link);
g_object_unref (def->param);
}
if (def->src_column)
field_free (def->src_column);
g_free (def);
}

File diff suppressed because it is too large Load Diff

View File

@ -197,7 +197,6 @@ void db_model_add_pre_stmt (DbModel * obj, SqlStmt * stmt);
void db_model_add_post_stmt (DbModel * obj, SqlStmt * stmt);
DbModelStatus db_model_get_status (DbModel * obj);
const gchar * db_model_get_main_table (DbModel * obj);
void db_model_request_main_table (DbModel * obj, const gchar * table);
DbModelUpdateFlags db_model_get_update_flags (DbModel * obj);
void db_model_request_update_flags (DbModel * obj
,DbModelUpdateFlags flags);

View File

@ -72,6 +72,8 @@ DbResult * db_result_copy (const DbResult * obj)
result->column[n].info = obj->column[n].info;
result->column[n].spec = gvn_param_spec_copy (obj->column[n].spec);
result->column[n].table = g_strdup (obj->column[n].table);
result->column[n].table_alias = g_strdup (obj->column[n].table_alias);
result->column[n].schema = g_strdup (obj->column[n].schema);
result->column[n].name = g_strdup (obj->column[n].name);
result->column[n].alias = g_strdup (obj->column[n].alias);
}
@ -107,6 +109,8 @@ void db_result_free (DbResult * obj)
g_free (col.name);
g_free (col.alias);
g_free (col.table);
g_free (col.table_alias);
g_free (col.schema);
}
g_free (obj->column);

View File

@ -69,13 +69,13 @@ DbColumnInfo;
**/
struct _DbColumn
{
DbColumnInfo info;
GvnParamSpec * spec;
gchar * schema;
gchar * table;
gchar * table_alias;
gchar * name;
gchar * alias;
gchar * table;
gchar * table_alias;
gchar * schema;
DbColumnInfo info;
GvnParamSpec * spec;
};
GType db_result_get_type ();

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.2 -->
<!-- Generated with glade 3.18.3 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<requires lib="vn" version="0.0"/>
<!-- interface-local-resource-path ../image -->
<object class="DbIterator" id="homes">
<property name="sql">SELECT id, street, pc, city, province, ok FROM user_address WHERE #link ORDER BY id</property>
<property name="sql">SELECT id, street, pc, city, province, ok, user_id FROM user_address WHERE #link ORDER BY id</property>
</object>
<object class="DbIterator" id="info">
<property name="sql">SELECT id, name, credit, active, born, photo, object_id FROM "user" ORDER BY id</property>
@ -348,6 +348,13 @@
<property name="editable">True</property>
</object>
</child>
<child>
<object class="VnColumnEntry" id="col-user">
<property name="title" translatable="yes">User</property>
<property name="column_name">user_id</property>
<property name="editable">True</property>
</object>
</child>
</object>
</child>
</object>

View File

@ -628,6 +628,7 @@ static DbResultSet * __db_pg_query
r->column[j].info = 0;
r->column[j].name = NULL;
r->column[j].table = NULL;
r->column[j].table_alias = NULL;
r->column[j].schema = NULL;
if (GPOINTER_TO_INT (g_ptr_array_index (col_iter, j)) == 0)
@ -650,6 +651,7 @@ static DbResultSet * __db_pg_query
r->column[j].alias = g_strdup (r->column[j].name);
r->column[j].table = g_strdup ("");
r->column[j].table_alias = g_strdup ("");
r->column[j].spec = gvn_param_spec_new_with_attrs
(((GType*) g_ptr_array_index (types, ind))[j]
, FALSE, FALSE, NULL);
@ -763,8 +765,12 @@ static DbResultSet * __db_pg_query
guint n;
if (!r->column[j].table)
{
r->column[j].table =
g_strdup (PQgetvalue (res_col, k, 1));
r->column[j].table_alias =
g_strdup (r->column[j].table);
}
g_strfreev (pkey);
pkey = g_strsplit (PQgetvalue (res_col, k, 2), " ", G_MAXINT);

View File

@ -48,9 +48,12 @@ static void sql_batch_item_changed (SqlObject * item, SqlBatch * obj)
static void sql_batch_free_item (SqlBatch * obj, SqlObject * item)
{
g_signal_handlers_disconnect_by_func (item,
sql_batch_item_changed, obj);
g_object_unref (item);
if (item)
{
g_signal_handlers_disconnect_by_func (item,
sql_batch_item_changed, obj);
g_object_unref (item);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public

View File

@ -22,8 +22,8 @@
#include "sql-target.h"
#define SQL_TYPE_FIELD (sql_field_get_type ())
#define SQL_FIELD(object) (G_TYPE_CHECK_INSTANCE_CAST (object, SQL_TYPE_FIELD, SqlField))
#define SQL_IS_FIELD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SQL_TYPE_FIELD))
#define SQL_FIELD(self) (G_TYPE_CHECK_INSTANCE_CAST (self, SQL_TYPE_FIELD, SqlField))
#define SQL_IS_FIELD(self) (G_TYPE_CHECK_INSTANCE_TYPE ((self), SQL_TYPE_FIELD))
typedef struct _SqlField SqlField;
typedef struct _SqlFieldClass SqlFieldClass;
@ -49,10 +49,10 @@ SqlObject * sql_field_new_with_target (const gchar * name
,const gchar * schema);
const gchar * sql_field_get_name (SqlField * self);
void sql_field_set_name (SqlField * obj, const gchar * name);
void sql_field_set_name (SqlField * self, const gchar * name);
const gchar * sql_field_get_target (SqlField * self);
void sql_field_set_target (SqlField * obj, const gchar * target);
void sql_field_set_target (SqlField * self, const gchar * target);
const gchar * sql_field_get_schema (SqlField * self);
void sql_field_set_schema (SqlField * obj, const gchar * schema);
void sql_field_set_schema (SqlField * self, const gchar * schema);
#endif

View File

@ -31,36 +31,36 @@ SqlObject * sql_holder_new (const gchar * id)
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
static void sql_holder_render (SqlHolder * obj, SqlRender * render, SqlBatch * batch)
static void sql_holder_render (SqlHolder * self, SqlRender * render, SqlBatch * batch)
{
SqlObject * object = batch ? sql_batch_get (batch, obj->id) : NULL;
SqlObject * object = batch ? sql_batch_get (batch, self->id) : NULL;
if (object)
sql_render_add_object (render, object);
else
sql_render_printf (render, "#%s", obj->id);
sql_render_printf (render, "#%s", self->id);
}
static void sql_holder_find_holders (SqlHolder * obj, SqlBatch * batch)
static void sql_holder_find_holders (SqlHolder * self, SqlBatch * batch)
{
sql_batch_add (batch, obj->id, NULL);
sql_batch_add (batch, self->id, NULL);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
/**
* sql_holder_get_id:
* @obj: the #SqlHolder
* @self: the #SqlHolder
*
* Gets the identifier assigned to the holder.
*
* Return value: (transfer none): the id
**/
const gchar * sql_holder_get_id (SqlHolder * obj)
const gchar * sql_holder_get_id (SqlHolder * self)
{
g_return_val_if_fail (SQL_IS_HOLDER (obj), NULL);
g_return_val_if_fail (SQL_IS_HOLDER (self), NULL);
return obj->id;
return self->id;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
@ -70,44 +70,44 @@ enum
PROP_ID = 1
};
static void sql_holder_set_property (SqlHolder * obj, guint id,
static void sql_holder_set_property (SqlHolder * self, guint id,
const GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_ID:
g_free (obj->id);
obj->id = g_value_dup_string (value);
g_free (self->id);
self->id = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
}
}
static void sql_holder_get_property (SqlHolder * obj, guint id,
static void sql_holder_get_property (SqlHolder * self, guint id,
GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_ID:
g_value_set_string (value, sql_holder_get_id (obj));
g_value_set_string (value, sql_holder_get_id (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void sql_holder_init (SqlHolder * obj)
static void sql_holder_init (SqlHolder * self)
{
obj->id = NULL;
self->id = NULL;
}
static void sql_holder_finalize (SqlHolder * obj)
static void sql_holder_finalize (SqlHolder * self)
{
g_free (obj->id);
G_OBJECT_CLASS (sql_holder_parent_class)->finalize (G_OBJECT (obj));
g_free (self->id);
G_OBJECT_CLASS (sql_holder_parent_class)->finalize (G_OBJECT (self));
}
static void sql_holder_class_init (SqlHolderClass * k)

View File

@ -19,8 +19,8 @@
#define SQL_HOLDER_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))
#define SQL_HOLDER(self) (G_TYPE_CHECK_INSTANCE_CAST (self, SQL_TYPE_HOLDER, SqlHolder))
#define SQL_IS_HOLDER(self) (G_TYPE_CHECK_INSTANCE_TYPE (self, SQL_TYPE_HOLDER))
typedef struct _SqlHolder SqlHolder;
typedef struct _SqlHolderClass SqlHolderClass;
@ -41,6 +41,6 @@ struct _SqlHolderClass
GType sql_holder_get_type ();
SqlObject * sql_holder_new (const gchar * id);
const gchar * sql_holder_get_id (SqlHolder * obj);
const gchar * sql_holder_get_id (SqlHolder * self);
#endif

View File

@ -47,51 +47,58 @@ static const gchar * SQL_JOIN_TYPE[] =
,"RIGHT"
};
static void sql_join_render (SqlJoin * obj, SqlRender * render)
static void sql_join_render (SqlJoin * self, SqlRender * render)
{
sql_render_add_item (render, TRUE, NULL, obj->target_left);
sql_render_add_token (render, SQL_JOIN_TYPE[obj->type]);
sql_render_add_item (render, TRUE, NULL, self->target_left);
sql_render_add_token (render, SQL_JOIN_TYPE[self->type]);
sql_render_add_token (render, "JOIN");
sql_render_add_item (render, TRUE, NULL, obj->target_right);
sql_render_add_item (render, TRUE, NULL, self->target_right);
if (obj->has_using)
if (self->has_using)
{
sql_render_add_token (render, "USING");
sql_render_append (render, "(");
sql_render_add_list (render, TRUE, NULL, obj->using_fields, ",");
sql_render_add_list (render, TRUE, NULL, self->using_fields, ",");
sql_render_append (render, ")");
}
else
sql_render_add_item (render, FALSE, "ON", obj->condition);
sql_render_add_item (render, FALSE, "ON", self->condition);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
void sql_join_set_target_left (SqlJoin * obj, SqlTarget * target)
SqlJoinType sql_join_get_join_type (SqlJoin * self)
{
g_return_if_fail (SQL_IS_JOIN (obj));
g_return_if_fail (SQL_IS_TARGET (target) || SQL_IS_HOLDER (target) || !target);
sql_object_remove (obj, obj->target_left);
obj->target_left = sql_object_add (obj, target);
g_return_if_fail (SQL_IS_JOIN (self));
return self->type;
}
void sql_join_set_target_right (SqlJoin * obj, SqlTarget * target)
void sql_join_set_target_left (SqlJoin * self, SqlTarget * target)
{
g_return_if_fail (SQL_IS_JOIN (obj));
g_return_if_fail (SQL_IS_JOIN (self));
g_return_if_fail (SQL_IS_TARGET (target) || SQL_IS_HOLDER (target) || !target);
sql_object_remove (obj, obj->target_right);
obj->target_right = sql_object_add (obj, target);
sql_object_remove (self, self->target_left);
self->target_left = sql_object_add (self, target);
}
void sql_join_set_condition (SqlJoin * obj, SqlExpr * condition)
void sql_join_set_target_right (SqlJoin * self, SqlTarget * target)
{
g_return_if_fail (SQL_IS_JOIN (obj));
g_return_if_fail (SQL_IS_JOIN (self));
g_return_if_fail (SQL_IS_TARGET (target) || SQL_IS_HOLDER (target) || !target);
sql_object_remove (self, self->target_right);
self->target_right = sql_object_add (self, target);
}
void sql_join_set_condition (SqlJoin * self, SqlExpr * condition)
{
g_return_if_fail (SQL_IS_JOIN (self));
g_return_if_fail (SQL_IS_EXPR (condition) || SQL_IS_HOLDER (condition) || !condition);
sql_object_remove (obj, obj->condition);
obj->condition = sql_object_add (obj, condition);
sql_object_remove (self, self->condition);
self->condition = sql_object_add (self, condition);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
@ -106,80 +113,80 @@ enum
,PROP_USING_FIELDS
};
static void sql_join_set_property (SqlJoin * obj, guint id,
static void sql_join_set_property (SqlJoin * self, guint id,
const GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_TARGET_LEFT:
sql_join_set_target_left (obj, g_value_get_object (value));
sql_join_set_target_left (self, g_value_get_object (value));
break;
case PROP_TARGET_RIGHT:
sql_join_set_target_right (obj, g_value_get_object (value));
sql_join_set_target_right (self, g_value_get_object (value));
break;
case PROP_TYPE:
obj->type = g_value_get_enum (value);
self->type = g_value_get_enum (value);
break;
case PROP_CONDITION:
sql_join_set_condition (obj, g_value_get_object (value));
sql_join_set_condition (self, g_value_get_object (value));
break;
case PROP_HAS_USING:
obj->has_using = g_value_get_boolean (value);
self->has_using = g_value_get_boolean (value);
break;
case PROP_USING_FIELDS:
sql_object_remove (obj, obj->using_fields);
obj->using_fields = sql_object_add (obj, g_value_get_object (value));
sql_object_remove (self, self->using_fields);
self->using_fields = sql_object_add (self, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
}
}
static void sql_join_get_property (SqlJoin * obj, guint id,
static void sql_join_get_property (SqlJoin * self, guint id,
GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_TARGET_LEFT:
g_value_set_object (value, obj->target_left);
g_value_set_object (value, self->target_left);
break;
case PROP_TARGET_RIGHT:
g_value_set_object (value, obj->target_right);
g_value_set_object (value, self->target_right);
break;
case PROP_TYPE:
g_value_set_enum (value, obj->type);
g_value_set_enum (value, self->type);
break;
case PROP_CONDITION:
g_value_set_object (value, obj->condition);
g_value_set_object (value, self->condition);
break;
case PROP_HAS_USING:
g_value_set_boolean (value, obj->has_using);
g_value_set_boolean (value, self->has_using);
break;
case PROP_USING_FIELDS:
g_value_set_object (value, obj->using_fields);
g_value_set_object (value, self->using_fields);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void sql_join_init (SqlJoin * obj)
static void sql_join_init (SqlJoin * self)
{
obj->target_left = NULL;
obj->target_right = NULL;
obj->condition = NULL;
obj->using_fields = NULL;
self->target_left = NULL;
self->target_right = NULL;
self->condition = NULL;
self->using_fields = NULL;
}
static void sql_join_finalize (SqlJoin * obj)
static void sql_join_finalize (SqlJoin * self)
{
sql_object_remove (obj, obj->target_left);
sql_object_remove (obj, obj->target_right);
sql_object_remove (obj, obj->condition);
sql_object_remove (obj, obj->using_fields);
G_OBJECT_CLASS (sql_join_parent_class)->finalize (G_OBJECT (obj));
sql_object_remove (self, self->target_left);
sql_object_remove (self, self->target_right);
sql_object_remove (self, self->condition);
sql_object_remove (self, self->using_fields);
G_OBJECT_CLASS (sql_join_parent_class)->finalize (G_OBJECT (self));
}
static void sql_join_class_init (SqlJoinClass * klass)

View File

@ -22,8 +22,8 @@
#include "sql-expr.h"
#define SQL_TYPE_JOIN (sql_join_get_type ())
#define SQL_IS_JOIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, SQL_TYPE_JOIN))
#define SQL_JOIN(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, SQL_TYPE_JOIN, SqlJoin))
#define SQL_IS_JOIN(self) (G_TYPE_CHECK_INSTANCE_TYPE (self, SQL_TYPE_JOIN))
#define SQL_JOIN(self) (G_TYPE_CHECK_INSTANCE_CAST (self, SQL_TYPE_JOIN, SqlJoin))
#define SQL_TYPE_JOIN_TYPE (sql_join_type_get_type ())
@ -60,8 +60,9 @@ GType sql_join_get_type ();
GType sql_join_type_get_type ();
SqlObject * sql_join_new (SqlTarget * left, SqlTarget * right, SqlJoinType type);
void sql_join_set_condition (SqlJoin * obj, SqlExpr * condition);
void sql_join_set_target_right (SqlJoin * obj, SqlTarget * target);
void sql_join_set_target_left (SqlJoin * obj, SqlTarget * target);
SqlJoinType sql_join_get_join_type (SqlJoin * self);
void sql_join_set_condition (SqlJoin * self, SqlExpr * condition);
void sql_join_set_target_right (SqlJoin * self, SqlTarget * target);
void sql_join_set_target_left (SqlJoin * self, SqlTarget * target);
#endif

View File

@ -33,18 +33,68 @@ SqlObject * sql_table_new (const gchar * name, const gchar * schema)
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
static void sql_table_render (SqlTable * obj, SqlRender * render)
static void sql_table_render (SqlTable * self, SqlRender * render)
{
if (obj->schema)
if (self->schema)
{
sql_render_add_identifier (render, obj->schema);
sql_render_add_identifier (render, self->schema);
sql_render_append (render, ".");
}
sql_render_add_identifier (render, obj->name);
sql_render_add_identifier (render, self->name);
if (g_strcmp0 (obj->name, SQL_TARGET (obj)->alias))
sql_render_add_identifier (render, SQL_TARGET (obj)->alias);
if (SQL_TARGET (self)->alias)
sql_render_add_identifier (render, SQL_TARGET (self)->alias);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
/**
* sql_table_get_name:
* @self: the #SqlTable
*
* Return value: the table name
**/
const gchar * sql_table_get_name (SqlTable * self)
{
return self->name;
}
/**
* sql_table_set_name:
* @self: the #SqlTable
* @target: the target name
**/
void sql_table_set_name (SqlTable * self, const gchar * name)
{
g_return_if_fail (SQL_IS_TABLE (self));
g_free (self->name);
self->name = g_strdup (name);
}
/**
* sql_table_get_schema:
* @self: the #SqlTable
*
* Return value: the schema name
**/
const gchar * sql_table_get_schema (SqlTable * self)
{
return self->schema;
}
/**
* sql_table_set_schema:
* @self: the #SqlTable
* @schema: the schema name
**/
void sql_table_set_schema (SqlTable * self, const gchar * schema)
{
g_return_if_fail (SQL_IS_TABLE (self));
g_free (self->schema);
self->schema = g_strdup (schema);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
@ -55,53 +105,53 @@ enum
,PROP_SCHEMA
};
static void sql_table_set_property (SqlTable * obj, guint id,
static void sql_table_set_property (SqlTable * self, guint id,
const GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_NAME:
g_free (obj->name);
obj->name = g_value_dup_string (value);
g_free (self->name);
self->name = g_value_dup_string (value);
break;
case PROP_SCHEMA:
g_free (obj->schema);
obj->schema = g_value_dup_string (value);
g_free (self->schema);
self->schema = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
}
}
static void sql_table_get_property (SqlTable * obj, guint id,
static void sql_table_get_property (SqlTable * self, guint id,
GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_NAME:
g_value_set_string (value, obj->name);
g_value_set_string (value, self->name);
break;
case PROP_SCHEMA:
g_value_set_string (value, obj->schema);
g_value_set_string (value, self->schema);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void sql_table_init (SqlTable * obj)
static void sql_table_init (SqlTable * self)
{
obj->name = NULL;
obj->schema = NULL;
self->name = NULL;
self->schema = NULL;
}
static void sql_table_finalize (SqlTable * obj)
static void sql_table_finalize (SqlTable * self)
{
g_free (obj->name);
g_free (obj->schema);
G_OBJECT_CLASS (sql_table_parent_class)->finalize (G_OBJECT (obj));
g_free (self->name);
g_free (self->schema);
G_OBJECT_CLASS (sql_table_parent_class)->finalize (G_OBJECT (self));
}
static void sql_table_class_init (SqlTableClass * klass)

View File

@ -21,8 +21,8 @@
#include "sql-target.h"
#define SQL_TYPE_TABLE (sql_table_get_type ())
#define SQL_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, SQL_TYPE_TABLE, SqlTable))
#define SQL_IS_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, SQL_TYPE_TABLE))
#define SQL_TABLE(self) (G_TYPE_CHECK_INSTANCE_CAST (self, SQL_TYPE_TABLE, SqlTable))
#define SQL_IS_TABLE(self) (G_TYPE_CHECK_INSTANCE_TYPE (self, SQL_TYPE_TABLE))
typedef struct _SqlTable SqlTable;
typedef struct _SqlTableClass SqlTableClass;
@ -40,7 +40,11 @@ struct _SqlTableClass
SqlTargetClass parent;
};
GType sql_table_get_type ();
SqlObject * sql_table_new (const gchar * name, const gchar * schema);
GType sql_table_get_type ();
SqlObject * sql_table_new (const gchar * name, const gchar * schema);
const gchar * sql_table_get_name (SqlTable * self);
void sql_table_set_name (SqlTable * self, const gchar * name);
const gchar * sql_table_get_schema (SqlTable * self);
void sql_table_set_schema (SqlTable * self, const gchar * schema);
#endif

View File

@ -29,12 +29,28 @@ G_DEFINE_ABSTRACT_TYPE (SqlTarget, sql_target, SQL_TYPE_OBJECT);
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
void sql_target_set_alias (SqlTarget * obj, const gchar * alias)
/**
* sql_target_set_alias:
* @self: the #SqlTargetClass
* @alias: the target alias
**/
void sql_target_set_alias (SqlTarget * self, const gchar * alias)
{
g_return_if_fail (SQL_IS_TARGET (obj));
g_return_if_fail (SQL_IS_TARGET (self));
g_free (obj->alias);
obj->alias = g_strdup (alias);
g_free (self->alias);
self->alias = g_strdup (alias);
}
/**
* sql_target_get_alias:
* @self: the #SqlTargetClass
**/
const gchar * sql_target_get_alias (SqlTarget * self)
{
g_return_if_fail (SQL_IS_TARGET (self));
return self->alias;
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
@ -44,43 +60,43 @@ enum
PROP_ALIAS = 1
};
static void sql_target_set_property (SqlTarget * obj, guint id,
static void sql_target_set_property (SqlTarget * self, guint id,
const GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_ALIAS:
sql_target_set_alias (obj, g_value_get_string (value));
sql_target_set_alias (self, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
}
}
static void sql_target_get_property (SqlTarget * obj, guint id,
static void sql_target_get_property (SqlTarget * self, guint id,
GValue * value, GParamSpec * pspec)
{
switch (id)
{
case PROP_ALIAS:
g_value_set_string (value, obj->alias);
g_value_set_string (value, self->alias);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
}
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void sql_target_init (SqlTarget * obj)
static void sql_target_init (SqlTarget * self)
{
obj->alias = NULL;
self->alias = NULL;
}
static void sql_target_finalize (SqlTarget * obj)
static void sql_target_finalize (SqlTarget * self)
{
g_free (obj->alias);
G_OBJECT_CLASS (sql_target_parent_class)->finalize (G_OBJECT (obj));
g_free (self->alias);
G_OBJECT_CLASS (sql_target_parent_class)->finalize (G_OBJECT (self));
}
static void sql_target_class_init (SqlTargetClass * k)

View File

@ -21,8 +21,8 @@
#include "sql-object.h"
#define SQL_TYPE_TARGET (sql_target_get_type ())
#define SQL_TARGET(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, SQL_TYPE_TARGET, SqlTarget))
#define SQL_IS_TARGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, SQL_TYPE_TARGET))
#define SQL_TARGET(self) (G_TYPE_CHECK_INSTANCE_CAST (self, SQL_TYPE_TARGET, SqlTarget))
#define SQL_IS_TARGET(self) (G_TYPE_CHECK_INSTANCE_TYPE (self, SQL_TYPE_TARGET))
typedef struct _SqlTarget SqlTarget;
typedef struct _SqlTargetClass SqlTargetClass;
@ -39,7 +39,8 @@ struct _SqlTargetClass
SqlObjectClass parent;
};
GType sql_target_get_type ();
void sql_target_set_alias (SqlTarget * obj, const gchar * alias);
GType sql_target_get_type ();
void sql_target_set_alias (SqlTarget * self, const gchar * alias);
const gchar * sql_target_get_alias (SqlTarget * self);
#endif