parent
a48f4923f4
commit
090b4124da
|
@ -17,6 +17,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define remove_delimiters(str) (g_strdup (g_strstrip (g_strdelimit (str, "`\"", ' '))))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DbUpdatedField:
|
* DbUpdatedField:
|
||||||
* @column: the position of the field in the row
|
* @column: the position of the field in the row
|
||||||
|
@ -80,6 +82,41 @@ typedef struct
|
||||||
}
|
}
|
||||||
DbModelRequest;
|
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
|
//----------------------------------------------- Field
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -90,8 +127,6 @@ typedef struct
|
||||||
}
|
}
|
||||||
Field;
|
Field;
|
||||||
|
|
||||||
#define remove_delimiters(str) (g_strdup (g_strstrip (g_strdelimit (str, "`\"", ' '))))
|
|
||||||
|
|
||||||
static void field_parse (Field * field, const gchar * string)
|
static void field_parse (Field * field, const gchar * string)
|
||||||
{
|
{
|
||||||
gchar ** split = g_strsplit (string, ".", 0);
|
gchar ** split = g_strsplit (string, ".", 0);
|
||||||
|
@ -136,133 +171,61 @@ static guint field_hash (const Field * field)
|
||||||
return g_str_hash (field->name);
|
return g_str_hash (field->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------- Table
|
//----------------------------------------------- TableInfo
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
gchar * name;
|
gchar * name;
|
||||||
gchar * schema;
|
gchar * schema;
|
||||||
}
|
gchar * alias;
|
||||||
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
|
|
||||||
{
|
|
||||||
GSList * pkeys;
|
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_info->name);
|
||||||
g_free (table_data);
|
g_free (table_info->schema);
|
||||||
}
|
g_free (table_info->alias);
|
||||||
|
g_slist_free (table_info->pkeys);
|
||||||
//----------------------------------------------- ParamDef
|
g_hash_table_unref (table_info->columns);
|
||||||
|
g_slist_free (table_info->parent_columns);
|
||||||
typedef struct
|
g_slist_free (table_info->child_columns);
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------- ColumnDef
|
//----------------------------------------------- ColumnDef
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
PARAM_DEF,
|
|
||||||
FIELD_DEF
|
|
||||||
}
|
|
||||||
DefType;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Field * field;
|
gulong link;
|
||||||
gpointer def;
|
GvnParam * param;
|
||||||
DefType type;
|
Field * src_column;
|
||||||
}
|
}
|
||||||
ColumnDef;
|
ColumnDef;
|
||||||
|
|
||||||
static ColumnDef * column_def_new (DefType type, gpointer def)
|
static ColumnDef * column_def_new ()
|
||||||
{
|
{
|
||||||
ColumnDef * column_def = g_new (ColumnDef, 1);
|
ColumnDef * column_def = g_new (ColumnDef, 1);
|
||||||
column_def->type = type;
|
column_def->link = 0;
|
||||||
column_def->def = def;
|
column_def->param = NULL;
|
||||||
|
column_def->src_column = NULL;
|
||||||
return column_def;
|
return column_def;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void column_def_free (ColumnDef * def)
|
static void column_def_free (ColumnDef * def)
|
||||||
{
|
{
|
||||||
field_free (def->field);
|
if (def->param)
|
||||||
|
|
||||||
switch (def->type)
|
|
||||||
{
|
{
|
||||||
case PARAM_DEF:
|
if (def->link)
|
||||||
param_def_free (def->def);
|
g_signal_handler_disconnect (def->param, def->link);
|
||||||
break;
|
|
||||||
case FIELD_DEF:
|
g_object_unref (def->param);
|
||||||
field_free (def->def);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
if (def->src_column)
|
||||||
|
field_free (def->src_column);
|
||||||
|
|
||||||
g_free (def);
|
g_free (def);
|
||||||
}
|
}
|
||||||
|
|
1331
db/db-model.c
1331
db/db-model.c
File diff suppressed because it is too large
Load Diff
|
@ -197,7 +197,6 @@ void db_model_add_pre_stmt (DbModel * obj, SqlStmt * stmt);
|
||||||
void db_model_add_post_stmt (DbModel * obj, SqlStmt * stmt);
|
void db_model_add_post_stmt (DbModel * obj, SqlStmt * stmt);
|
||||||
DbModelStatus db_model_get_status (DbModel * obj);
|
DbModelStatus db_model_get_status (DbModel * obj);
|
||||||
const gchar * db_model_get_main_table (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);
|
DbModelUpdateFlags db_model_get_update_flags (DbModel * obj);
|
||||||
void db_model_request_update_flags (DbModel * obj
|
void db_model_request_update_flags (DbModel * obj
|
||||||
,DbModelUpdateFlags flags);
|
,DbModelUpdateFlags flags);
|
||||||
|
|
|
@ -72,6 +72,8 @@ DbResult * db_result_copy (const DbResult * obj)
|
||||||
result->column[n].info = obj->column[n].info;
|
result->column[n].info = obj->column[n].info;
|
||||||
result->column[n].spec = gvn_param_spec_copy (obj->column[n].spec);
|
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 = 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].name = g_strdup (obj->column[n].name);
|
||||||
result->column[n].alias = g_strdup (obj->column[n].alias);
|
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.name);
|
||||||
g_free (col.alias);
|
g_free (col.alias);
|
||||||
g_free (col.table);
|
g_free (col.table);
|
||||||
|
g_free (col.table_alias);
|
||||||
|
g_free (col.schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (obj->column);
|
g_free (obj->column);
|
||||||
|
|
|
@ -69,13 +69,13 @@ DbColumnInfo;
|
||||||
**/
|
**/
|
||||||
struct _DbColumn
|
struct _DbColumn
|
||||||
{
|
{
|
||||||
DbColumnInfo info;
|
|
||||||
GvnParamSpec * spec;
|
|
||||||
gchar * schema;
|
|
||||||
gchar * table;
|
|
||||||
gchar * table_alias;
|
|
||||||
gchar * name;
|
gchar * name;
|
||||||
gchar * alias;
|
gchar * alias;
|
||||||
|
gchar * table;
|
||||||
|
gchar * table_alias;
|
||||||
|
gchar * schema;
|
||||||
|
DbColumnInfo info;
|
||||||
|
GvnParamSpec * spec;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType db_result_get_type ();
|
GType db_result_get_type ();
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Generated with glade 3.18.2 -->
|
<!-- Generated with glade 3.18.3 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.0"/>
|
<requires lib="gtk+" version="3.0"/>
|
||||||
<requires lib="vn" version="0.0"/>
|
<requires lib="vn" version="0.0"/>
|
||||||
<!-- interface-local-resource-path ../image -->
|
<!-- interface-local-resource-path ../image -->
|
||||||
<object class="DbIterator" id="homes">
|
<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>
|
||||||
<object class="DbIterator" id="info">
|
<object class="DbIterator" id="info">
|
||||||
<property name="sql">SELECT id, name, credit, active, born, photo, object_id FROM "user" ORDER BY id</property>
|
<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>
|
<property name="editable">True</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</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>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
|
|
@ -628,6 +628,7 @@ static DbResultSet * __db_pg_query
|
||||||
r->column[j].info = 0;
|
r->column[j].info = 0;
|
||||||
r->column[j].name = NULL;
|
r->column[j].name = NULL;
|
||||||
r->column[j].table = NULL;
|
r->column[j].table = NULL;
|
||||||
|
r->column[j].table_alias = NULL;
|
||||||
r->column[j].schema = NULL;
|
r->column[j].schema = NULL;
|
||||||
|
|
||||||
if (GPOINTER_TO_INT (g_ptr_array_index (col_iter, j)) == 0)
|
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].alias = g_strdup (r->column[j].name);
|
||||||
r->column[j].table = g_strdup ("");
|
r->column[j].table = g_strdup ("");
|
||||||
|
r->column[j].table_alias = g_strdup ("");
|
||||||
r->column[j].spec = gvn_param_spec_new_with_attrs
|
r->column[j].spec = gvn_param_spec_new_with_attrs
|
||||||
(((GType*) g_ptr_array_index (types, ind))[j]
|
(((GType*) g_ptr_array_index (types, ind))[j]
|
||||||
, FALSE, FALSE, NULL);
|
, FALSE, FALSE, NULL);
|
||||||
|
@ -763,8 +765,12 @@ static DbResultSet * __db_pg_query
|
||||||
guint n;
|
guint n;
|
||||||
|
|
||||||
if (!r->column[j].table)
|
if (!r->column[j].table)
|
||||||
|
{
|
||||||
r->column[j].table =
|
r->column[j].table =
|
||||||
g_strdup (PQgetvalue (res_col, k, 1));
|
g_strdup (PQgetvalue (res_col, k, 1));
|
||||||
|
r->column[j].table_alias =
|
||||||
|
g_strdup (r->column[j].table);
|
||||||
|
}
|
||||||
|
|
||||||
g_strfreev (pkey);
|
g_strfreev (pkey);
|
||||||
pkey = g_strsplit (PQgetvalue (res_col, k, 2), " ", G_MAXINT);
|
pkey = g_strsplit (PQgetvalue (res_col, k, 2), " ", G_MAXINT);
|
||||||
|
|
|
@ -48,9 +48,12 @@ static void sql_batch_item_changed (SqlObject * item, SqlBatch * obj)
|
||||||
|
|
||||||
static void sql_batch_free_item (SqlBatch * obj, SqlObject * item)
|
static void sql_batch_free_item (SqlBatch * obj, SqlObject * item)
|
||||||
{
|
{
|
||||||
g_signal_handlers_disconnect_by_func (item,
|
if (item)
|
||||||
sql_batch_item_changed, obj);
|
{
|
||||||
g_object_unref (item);
|
g_signal_handlers_disconnect_by_func (item,
|
||||||
|
sql_batch_item_changed, obj);
|
||||||
|
g_object_unref (item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
#include "sql-target.h"
|
#include "sql-target.h"
|
||||||
|
|
||||||
#define SQL_TYPE_FIELD (sql_field_get_type ())
|
#define SQL_TYPE_FIELD (sql_field_get_type ())
|
||||||
#define SQL_FIELD(object) (G_TYPE_CHECK_INSTANCE_CAST (object, SQL_TYPE_FIELD, SqlField))
|
#define SQL_FIELD(self) (G_TYPE_CHECK_INSTANCE_CAST (self, SQL_TYPE_FIELD, SqlField))
|
||||||
#define SQL_IS_FIELD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SQL_TYPE_FIELD))
|
#define SQL_IS_FIELD(self) (G_TYPE_CHECK_INSTANCE_TYPE ((self), SQL_TYPE_FIELD))
|
||||||
|
|
||||||
typedef struct _SqlField SqlField;
|
typedef struct _SqlField SqlField;
|
||||||
typedef struct _SqlFieldClass SqlFieldClass;
|
typedef struct _SqlFieldClass SqlFieldClass;
|
||||||
|
@ -49,10 +49,10 @@ SqlObject * sql_field_new_with_target (const gchar * name
|
||||||
,const gchar * schema);
|
,const gchar * schema);
|
||||||
|
|
||||||
const gchar * sql_field_get_name (SqlField * self);
|
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);
|
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);
|
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
|
#endif
|
||||||
|
|
|
@ -31,36 +31,36 @@ SqlObject * sql_holder_new (const gchar * id)
|
||||||
|
|
||||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ 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)
|
if (object)
|
||||||
sql_render_add_object (render, object);
|
sql_render_add_object (render, object);
|
||||||
else
|
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
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sql_holder_get_id:
|
* sql_holder_get_id:
|
||||||
* @obj: the #SqlHolder
|
* @self: the #SqlHolder
|
||||||
*
|
*
|
||||||
* Gets the identifier assigned to the holder.
|
* Gets the identifier assigned to the holder.
|
||||||
*
|
*
|
||||||
* Return value: (transfer none): the id
|
* 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
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
||||||
|
@ -70,44 +70,44 @@ enum
|
||||||
PROP_ID = 1
|
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)
|
const GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
case PROP_ID:
|
case PROP_ID:
|
||||||
g_free (obj->id);
|
g_free (self->id);
|
||||||
obj->id = g_value_dup_string (value);
|
self->id = g_value_dup_string (value);
|
||||||
break;
|
break;
|
||||||
default:
|
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)
|
GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
case PROP_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;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ 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_free (self->id);
|
||||||
G_OBJECT_CLASS (sql_holder_parent_class)->finalize (G_OBJECT (obj));
|
G_OBJECT_CLASS (sql_holder_parent_class)->finalize (G_OBJECT (self));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sql_holder_class_init (SqlHolderClass * k)
|
static void sql_holder_class_init (SqlHolderClass * k)
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
#define SQL_HOLDER_H
|
#define SQL_HOLDER_H
|
||||||
|
|
||||||
#define SQL_TYPE_HOLDER (sql_holder_get_type ())
|
#define SQL_TYPE_HOLDER (sql_holder_get_type ())
|
||||||
#define SQL_HOLDER(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, SQL_TYPE_HOLDER, SqlHolder))
|
#define SQL_HOLDER(self) (G_TYPE_CHECK_INSTANCE_CAST (self, SQL_TYPE_HOLDER, SqlHolder))
|
||||||
#define SQL_IS_HOLDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, SQL_TYPE_HOLDER))
|
#define SQL_IS_HOLDER(self) (G_TYPE_CHECK_INSTANCE_TYPE (self, SQL_TYPE_HOLDER))
|
||||||
|
|
||||||
typedef struct _SqlHolder SqlHolder;
|
typedef struct _SqlHolder SqlHolder;
|
||||||
typedef struct _SqlHolderClass SqlHolderClass;
|
typedef struct _SqlHolderClass SqlHolderClass;
|
||||||
|
@ -41,6 +41,6 @@ struct _SqlHolderClass
|
||||||
|
|
||||||
GType sql_holder_get_type ();
|
GType sql_holder_get_type ();
|
||||||
SqlObject * sql_holder_new (const gchar * id);
|
SqlObject * sql_holder_new (const gchar * id);
|
||||||
const gchar * sql_holder_get_id (SqlHolder * obj);
|
const gchar * sql_holder_get_id (SqlHolder * self);
|
||||||
|
|
||||||
#endif
|
#endif
|
105
sql/sql-join.c
105
sql/sql-join.c
|
@ -47,51 +47,58 @@ static const gchar * SQL_JOIN_TYPE[] =
|
||||||
,"RIGHT"
|
,"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_item (render, TRUE, NULL, self->target_left);
|
||||||
sql_render_add_token (render, SQL_JOIN_TYPE[obj->type]);
|
sql_render_add_token (render, SQL_JOIN_TYPE[self->type]);
|
||||||
sql_render_add_token (render, "JOIN");
|
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_add_token (render, "USING");
|
||||||
sql_render_append (render, "(");
|
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, ")");
|
sql_render_append (render, ")");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
sql_render_add_item (render, FALSE, "ON", obj->condition);
|
sql_render_add_item (render, FALSE, "ON", self->condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ 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_JOIN (self));
|
||||||
g_return_if_fail (SQL_IS_TARGET (target) || SQL_IS_HOLDER (target) || !target);
|
|
||||||
|
return self->type;
|
||||||
sql_object_remove (obj, obj->target_left);
|
|
||||||
obj->target_left = sql_object_add (obj, target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
g_return_if_fail (SQL_IS_TARGET (target) || SQL_IS_HOLDER (target) || !target);
|
||||||
|
|
||||||
sql_object_remove (obj, obj->target_right);
|
sql_object_remove (self, self->target_left);
|
||||||
obj->target_right = sql_object_add (obj, target);
|
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);
|
g_return_if_fail (SQL_IS_EXPR (condition) || SQL_IS_HOLDER (condition) || !condition);
|
||||||
|
|
||||||
sql_object_remove (obj, obj->condition);
|
sql_object_remove (self, self->condition);
|
||||||
obj->condition = sql_object_add (obj, condition);
|
self->condition = sql_object_add (self, condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
||||||
|
@ -106,80 +113,80 @@ enum
|
||||||
,PROP_USING_FIELDS
|
,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)
|
const GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
case PROP_TARGET_LEFT:
|
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;
|
break;
|
||||||
case PROP_TARGET_RIGHT:
|
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;
|
break;
|
||||||
case PROP_TYPE:
|
case PROP_TYPE:
|
||||||
obj->type = g_value_get_enum (value);
|
self->type = g_value_get_enum (value);
|
||||||
break;
|
break;
|
||||||
case PROP_CONDITION:
|
case PROP_CONDITION:
|
||||||
sql_join_set_condition (obj, g_value_get_object (value));
|
sql_join_set_condition (self, g_value_get_object (value));
|
||||||
break;
|
break;
|
||||||
case PROP_HAS_USING:
|
case PROP_HAS_USING:
|
||||||
obj->has_using = g_value_get_boolean (value);
|
self->has_using = g_value_get_boolean (value);
|
||||||
break;
|
break;
|
||||||
case PROP_USING_FIELDS:
|
case PROP_USING_FIELDS:
|
||||||
sql_object_remove (obj, obj->using_fields);
|
sql_object_remove (self, self->using_fields);
|
||||||
obj->using_fields = sql_object_add (obj, g_value_get_object (value));
|
self->using_fields = sql_object_add (self, g_value_get_object (value));
|
||||||
break;
|
break;
|
||||||
default:
|
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)
|
GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
case PROP_TARGET_LEFT:
|
case PROP_TARGET_LEFT:
|
||||||
g_value_set_object (value, obj->target_left);
|
g_value_set_object (value, self->target_left);
|
||||||
break;
|
break;
|
||||||
case PROP_TARGET_RIGHT:
|
case PROP_TARGET_RIGHT:
|
||||||
g_value_set_object (value, obj->target_right);
|
g_value_set_object (value, self->target_right);
|
||||||
break;
|
break;
|
||||||
case PROP_TYPE:
|
case PROP_TYPE:
|
||||||
g_value_set_enum (value, obj->type);
|
g_value_set_enum (value, self->type);
|
||||||
break;
|
break;
|
||||||
case PROP_CONDITION:
|
case PROP_CONDITION:
|
||||||
g_value_set_object (value, obj->condition);
|
g_value_set_object (value, self->condition);
|
||||||
break;
|
break;
|
||||||
case PROP_HAS_USING:
|
case PROP_HAS_USING:
|
||||||
g_value_set_boolean (value, obj->has_using);
|
g_value_set_boolean (value, self->has_using);
|
||||||
break;
|
break;
|
||||||
case PROP_USING_FIELDS:
|
case PROP_USING_FIELDS:
|
||||||
g_value_set_object (value, obj->using_fields);
|
g_value_set_object (value, self->using_fields);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
||||||
|
|
||||||
static void sql_join_init (SqlJoin * obj)
|
static void sql_join_init (SqlJoin * self)
|
||||||
{
|
{
|
||||||
obj->target_left = NULL;
|
self->target_left = NULL;
|
||||||
obj->target_right = NULL;
|
self->target_right = NULL;
|
||||||
obj->condition = NULL;
|
self->condition = NULL;
|
||||||
obj->using_fields = 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 (self, self->target_left);
|
||||||
sql_object_remove (obj, obj->target_right);
|
sql_object_remove (self, self->target_right);
|
||||||
sql_object_remove (obj, obj->condition);
|
sql_object_remove (self, self->condition);
|
||||||
sql_object_remove (obj, obj->using_fields);
|
sql_object_remove (self, self->using_fields);
|
||||||
G_OBJECT_CLASS (sql_join_parent_class)->finalize (G_OBJECT (obj));
|
G_OBJECT_CLASS (sql_join_parent_class)->finalize (G_OBJECT (self));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sql_join_class_init (SqlJoinClass * klass)
|
static void sql_join_class_init (SqlJoinClass * klass)
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
#include "sql-expr.h"
|
#include "sql-expr.h"
|
||||||
|
|
||||||
#define SQL_TYPE_JOIN (sql_join_get_type ())
|
#define SQL_TYPE_JOIN (sql_join_get_type ())
|
||||||
#define SQL_IS_JOIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, SQL_TYPE_JOIN))
|
#define SQL_IS_JOIN(self) (G_TYPE_CHECK_INSTANCE_TYPE (self, SQL_TYPE_JOIN))
|
||||||
#define SQL_JOIN(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, SQL_TYPE_JOIN, SqlJoin))
|
#define SQL_JOIN(self) (G_TYPE_CHECK_INSTANCE_CAST (self, SQL_TYPE_JOIN, SqlJoin))
|
||||||
|
|
||||||
#define SQL_TYPE_JOIN_TYPE (sql_join_type_get_type ())
|
#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 ();
|
GType sql_join_type_get_type ();
|
||||||
|
|
||||||
SqlObject * sql_join_new (SqlTarget * left, SqlTarget * right, SqlJoinType type);
|
SqlObject * sql_join_new (SqlTarget * left, SqlTarget * right, SqlJoinType type);
|
||||||
void sql_join_set_condition (SqlJoin * obj, SqlExpr * condition);
|
SqlJoinType sql_join_get_join_type (SqlJoin * self);
|
||||||
void sql_join_set_target_right (SqlJoin * obj, SqlTarget * target);
|
void sql_join_set_condition (SqlJoin * self, SqlExpr * condition);
|
||||||
void sql_join_set_target_left (SqlJoin * obj, SqlTarget * target);
|
void sql_join_set_target_right (SqlJoin * self, SqlTarget * target);
|
||||||
|
void sql_join_set_target_left (SqlJoin * self, SqlTarget * target);
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -33,18 +33,68 @@ SqlObject * sql_table_new (const gchar * name, const gchar * schema)
|
||||||
|
|
||||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ 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_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))
|
if (SQL_TARGET (self)->alias)
|
||||||
sql_render_add_identifier (render, SQL_TARGET (obj)->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
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
||||||
|
@ -55,53 +105,53 @@ enum
|
||||||
,PROP_SCHEMA
|
,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)
|
const GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
case PROP_NAME:
|
case PROP_NAME:
|
||||||
g_free (obj->name);
|
g_free (self->name);
|
||||||
obj->name = g_value_dup_string (value);
|
self->name = g_value_dup_string (value);
|
||||||
break;
|
break;
|
||||||
case PROP_SCHEMA:
|
case PROP_SCHEMA:
|
||||||
g_free (obj->schema);
|
g_free (self->schema);
|
||||||
obj->schema = g_value_dup_string (value);
|
self->schema = g_value_dup_string (value);
|
||||||
break;
|
break;
|
||||||
default:
|
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)
|
GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
case PROP_NAME:
|
case PROP_NAME:
|
||||||
g_value_set_string (value, obj->name);
|
g_value_set_string (value, self->name);
|
||||||
break;
|
break;
|
||||||
case PROP_SCHEMA:
|
case PROP_SCHEMA:
|
||||||
g_value_set_string (value, obj->schema);
|
g_value_set_string (value, self->schema);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
||||||
|
|
||||||
static void sql_table_init (SqlTable * obj)
|
static void sql_table_init (SqlTable * self)
|
||||||
{
|
{
|
||||||
obj->name = NULL;
|
self->name = NULL;
|
||||||
obj->schema = NULL;
|
self->schema = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sql_table_finalize (SqlTable * obj)
|
static void sql_table_finalize (SqlTable * self)
|
||||||
{
|
{
|
||||||
g_free (obj->name);
|
g_free (self->name);
|
||||||
g_free (obj->schema);
|
g_free (self->schema);
|
||||||
G_OBJECT_CLASS (sql_table_parent_class)->finalize (G_OBJECT (obj));
|
G_OBJECT_CLASS (sql_table_parent_class)->finalize (G_OBJECT (self));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sql_table_class_init (SqlTableClass * klass)
|
static void sql_table_class_init (SqlTableClass * klass)
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
#include "sql-target.h"
|
#include "sql-target.h"
|
||||||
|
|
||||||
#define SQL_TYPE_TABLE (sql_table_get_type ())
|
#define SQL_TYPE_TABLE (sql_table_get_type ())
|
||||||
#define SQL_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, SQL_TYPE_TABLE, SqlTable))
|
#define SQL_TABLE(self) (G_TYPE_CHECK_INSTANCE_CAST (self, SQL_TYPE_TABLE, SqlTable))
|
||||||
#define SQL_IS_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, SQL_TYPE_TABLE))
|
#define SQL_IS_TABLE(self) (G_TYPE_CHECK_INSTANCE_TYPE (self, SQL_TYPE_TABLE))
|
||||||
|
|
||||||
typedef struct _SqlTable SqlTable;
|
typedef struct _SqlTable SqlTable;
|
||||||
typedef struct _SqlTableClass SqlTableClass;
|
typedef struct _SqlTableClass SqlTableClass;
|
||||||
|
@ -40,7 +40,11 @@ struct _SqlTableClass
|
||||||
SqlTargetClass parent;
|
SqlTargetClass parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType sql_table_get_type ();
|
GType sql_table_get_type ();
|
||||||
SqlObject * sql_table_new (const gchar * name, const gchar * schema);
|
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
|
#endif
|
||||||
|
|
|
@ -29,12 +29,28 @@ G_DEFINE_ABSTRACT_TYPE (SqlTarget, sql_target, SQL_TYPE_OBJECT);
|
||||||
|
|
||||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ 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);
|
g_free (self->alias);
|
||||||
obj->alias = g_strdup (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
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
||||||
|
@ -44,43 +60,43 @@ enum
|
||||||
PROP_ALIAS = 1
|
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)
|
const GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
case PROP_ALIAS:
|
case PROP_ALIAS:
|
||||||
sql_target_set_alias (obj, g_value_get_string (value));
|
sql_target_set_alias (self, g_value_get_string (value));
|
||||||
break;
|
break;
|
||||||
default:
|
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)
|
GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
case PROP_ALIAS:
|
case PROP_ALIAS:
|
||||||
g_value_set_string (value, obj->alias);
|
g_value_set_string (value, self->alias);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, id, pspec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++ 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_free (self->alias);
|
||||||
G_OBJECT_CLASS (sql_target_parent_class)->finalize (G_OBJECT (obj));
|
G_OBJECT_CLASS (sql_target_parent_class)->finalize (G_OBJECT (self));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sql_target_class_init (SqlTargetClass * k)
|
static void sql_target_class_init (SqlTargetClass * k)
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
#include "sql-object.h"
|
#include "sql-object.h"
|
||||||
|
|
||||||
#define SQL_TYPE_TARGET (sql_target_get_type ())
|
#define SQL_TYPE_TARGET (sql_target_get_type ())
|
||||||
#define SQL_TARGET(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, SQL_TYPE_TARGET, SqlTarget))
|
#define SQL_TARGET(self) (G_TYPE_CHECK_INSTANCE_CAST (self, SQL_TYPE_TARGET, SqlTarget))
|
||||||
#define SQL_IS_TARGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, SQL_TYPE_TARGET))
|
#define SQL_IS_TARGET(self) (G_TYPE_CHECK_INSTANCE_TYPE (self, SQL_TYPE_TARGET))
|
||||||
|
|
||||||
typedef struct _SqlTarget SqlTarget;
|
typedef struct _SqlTarget SqlTarget;
|
||||||
typedef struct _SqlTargetClass SqlTargetClass;
|
typedef struct _SqlTargetClass SqlTargetClass;
|
||||||
|
@ -39,7 +39,8 @@ struct _SqlTargetClass
|
||||||
SqlObjectClass parent;
|
SqlObjectClass parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType sql_target_get_type ();
|
GType sql_target_get_type ();
|
||||||
void sql_target_set_alias (SqlTarget * obj, const gchar * alias);
|
void sql_target_set_alias (SqlTarget * self, const gchar * alias);
|
||||||
|
const gchar * sql_target_get_alias (SqlTarget * self);
|
||||||
|
|
||||||
#endif
|
#endif
|
Reference in New Issue