DbModel:
- Ahora identifica las columnas y tablas por nombre de tabla y esquema. - Ahora utiliza menos memoria cuando es utilizado en modo solo lectura. - Codigo reorganizado y optimizado.
This commit is contained in:
parent
02da9752e1
commit
807c8f6699
1020
db/db-model.c
1020
db/db-model.c
File diff suppressed because it is too large
Load Diff
|
@ -73,7 +73,7 @@ DbResult * db_result_copy (const DbResult * obj)
|
|||
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].name = g_strdup (obj->column[n].name);
|
||||
result->column[n].display = g_strdup (obj->column[n].display);
|
||||
result->column[n].alias = g_strdup (obj->column[n].alias);
|
||||
}
|
||||
|
||||
for (n = 0; n < obj->nrows; n++)
|
||||
|
@ -105,7 +105,7 @@ void db_result_free (DbResult * obj)
|
|||
DbColumn col = obj->column[i];
|
||||
gvn_param_spec_free (col.spec);
|
||||
g_free (col.name);
|
||||
g_free (col.display);
|
||||
g_free (col.alias);
|
||||
g_free (col.table);
|
||||
}
|
||||
|
||||
|
|
|
@ -71,10 +71,11 @@ struct _DbColumn
|
|||
{
|
||||
DbColumnInfo info;
|
||||
GvnParamSpec * spec;
|
||||
gchar * schema;
|
||||
gchar * table;
|
||||
gchar * table_alias;
|
||||
gchar * name;
|
||||
gchar * display;
|
||||
gchar * alias;
|
||||
};
|
||||
|
||||
GType db_result_get_type ();
|
||||
|
|
|
@ -226,7 +226,7 @@ static DbResultSet * db_mysql_query (DbMysql * obj, const gchar * sql, GError **
|
|||
column = &result->column[i];
|
||||
column->info = 0;
|
||||
column->name = g_strdup (field[i].org_name);
|
||||
column->display = g_strdup (field[i].name);
|
||||
column->alias = g_strdup (field[i].name);
|
||||
column->table = g_strdup (field[i].org_table);
|
||||
column->table_alias = g_strdup (field[i].table);
|
||||
|
||||
|
|
|
@ -647,7 +647,7 @@ static DbResultSet * __db_pg_query
|
|||
else
|
||||
r->column[j].name = fname;
|
||||
|
||||
r->column[j].display = 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].spec = gvn_param_spec_new_with_attrs
|
||||
(((GType*) g_ptr_array_index (types, ind))[j]
|
||||
|
@ -676,7 +676,7 @@ static DbResultSet * __db_pg_query
|
|||
fdisp = g_ptr_array_index (name_array, j);
|
||||
|
||||
r->column[j].name = g_strdup (fname);
|
||||
r->column[j].display = g_strdup (fdisp);
|
||||
r->column[j].alias = g_strdup (fdisp);
|
||||
|
||||
// Getting the default value from res_col //FIXME use the parser
|
||||
if (!PQgetisnull (res_col, ctup, 3))
|
||||
|
|
|
@ -386,7 +386,7 @@ join(A) ::= target(left) join_type(type) target(right) join_cond(condition).
|
|||
SQL_TABLE (right)->schema : NULL;
|
||||
|
||||
sql_list_add (equal,
|
||||
sql_field_new_with_table (SQL_FIELD (n->data)->name, target, schema));
|
||||
sql_field_new_with_target (SQL_FIELD (n->data)->name, target, schema));
|
||||
|
||||
sql_list_add (exprs, op);
|
||||
}
|
||||
|
|
|
@ -261,3 +261,45 @@ SqlObject * sql_parser_parse (gchar * sql)
|
|||
|
||||
return object;
|
||||
}
|
||||
|
||||
SqlField * sql_parser_parse_field (const gchar * field_str)
|
||||
{
|
||||
gchar ** split;
|
||||
SqlObject * field = NULL;
|
||||
|
||||
if (!field_str || !g_strcmp0 (field_str, ""))
|
||||
return NULL;
|
||||
|
||||
split = g_strsplit (field_str, ".", 0);
|
||||
|
||||
switch (g_strv_length (split))
|
||||
{
|
||||
case 3:
|
||||
{
|
||||
field = sql_field_new_with_target
|
||||
(g_strstrip (g_strdelimit (split[2], "`\"", ' '))
|
||||
,g_strstrip (g_strdelimit (split[1], "`\"", ' '))
|
||||
,g_strstrip (g_strdelimit (split[0], "`\"", ' ')));
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
field = sql_field_new_with_target
|
||||
(g_strstrip (g_strdelimit (split[1], "`\"", ' '))
|
||||
,g_strstrip (g_strdelimit (split[0], "`\"", ' '))
|
||||
,NULL);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
field = sql_field_new_with_target
|
||||
(g_strstrip (g_strdelimit (split[0], "`\"", ' '))
|
||||
,NULL
|
||||
,NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_strfreev (split);
|
||||
return SQL_FIELD (field);
|
||||
}
|
||||
|
|
|
@ -41,16 +41,16 @@ SqlBatch * sql_batch_new ()
|
|||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
|
||||
|
||||
static void sql_batch_child_changed (SqlObject * child, SqlBatch * obj)
|
||||
static void sql_batch_item_changed (SqlObject * item, SqlBatch * obj)
|
||||
{
|
||||
sql_batch_changed (obj);
|
||||
}
|
||||
|
||||
static void sql_batch_free_child (SqlBatch * obj, SqlObject * child)
|
||||
static void sql_batch_free_item (SqlBatch * obj, SqlObject * item)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (child,
|
||||
sql_batch_child_changed, obj);
|
||||
g_object_unref (child);
|
||||
g_signal_handlers_disconnect_by_func (item,
|
||||
sql_batch_item_changed, obj);
|
||||
g_object_unref (item);
|
||||
}
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
|
||||
|
@ -65,22 +65,18 @@ static void sql_batch_free_child (SqlBatch * obj, SqlObject * child)
|
|||
**/
|
||||
gboolean sql_batch_is_ready (SqlBatch * obj)
|
||||
{
|
||||
gboolean is_ready = TRUE;
|
||||
gpointer item;
|
||||
GHashTableIter iter;
|
||||
|
||||
g_return_val_if_fail (SQL_IS_BATCH (obj), FALSE);
|
||||
|
||||
if (obj->items)
|
||||
{
|
||||
GList * i;
|
||||
GList * items = g_hash_table_get_values (obj->items);
|
||||
|
||||
for (i = items; i && is_ready; i = i->next)
|
||||
is_ready = sql_object_is_ready (i->data);
|
||||
|
||||
g_list_free (items);
|
||||
}
|
||||
g_hash_table_iter_init (&iter, obj->items);
|
||||
|
||||
return is_ready;
|
||||
while (g_hash_table_iter_next (&iter, NULL, &item))
|
||||
if (!item || !sql_object_is_ready (item))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -107,29 +103,26 @@ SqlObject * sql_batch_get (SqlBatch * obj, const gchar * id)
|
|||
* sql_batch_add:
|
||||
* @obj: a #SqlBatch
|
||||
* @id: the id of the #SqlHolder
|
||||
* @held_object: the held object
|
||||
* @item: the #SqlObject
|
||||
*
|
||||
* Adds a held object.
|
||||
* Adds a new item to the batch.
|
||||
**/
|
||||
void sql_batch_add (SqlBatch * obj, const gchar * id, SqlObject * object)
|
||||
void sql_batch_add (SqlBatch * obj, const gchar * id, SqlObject * item)
|
||||
{
|
||||
g_return_if_fail (SQL_IS_BATCH (obj));
|
||||
g_return_if_fail (id);
|
||||
g_return_if_fail (SQL_IS_OBJECT (item) || !item);
|
||||
|
||||
sql_batch_remove (obj, id);
|
||||
|
||||
if (!obj->items)
|
||||
obj->items = g_hash_table_new_full (
|
||||
g_str_hash
|
||||
,g_str_equal
|
||||
,g_free
|
||||
,NULL
|
||||
);
|
||||
|
||||
g_signal_connect (object, "changed",
|
||||
G_CALLBACK (sql_batch_child_changed), obj);
|
||||
g_hash_table_replace (obj->items,
|
||||
g_strdup (id), g_object_ref_sink (object));
|
||||
if (item)
|
||||
{
|
||||
g_object_ref_sink (item);
|
||||
g_signal_connect (item, "changed",
|
||||
G_CALLBACK (sql_batch_item_changed), obj);
|
||||
}
|
||||
|
||||
g_hash_table_replace (obj->items, g_strdup (id), item);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -143,10 +136,7 @@ void sql_batch_add_from_param (SqlBatch * obj, const gchar * id, GvnParam * para
|
|||
g_return_if_fail (id);
|
||||
g_return_if_fail (GVN_IS_PARAM (param));
|
||||
|
||||
SqlObject * value = sql_value_new ();
|
||||
sql_value_set_param (SQL_VALUE (value), param);
|
||||
sql_batch_add (obj, id, value);
|
||||
g_object_unref (value);
|
||||
sql_batch_add (obj, id, sql_value_new_with_param (param));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -160,13 +150,8 @@ void sql_batch_add_from_value (SqlBatch * obj, const gchar * id, GType type, gpo
|
|||
g_return_if_fail (id);
|
||||
|
||||
GValue gvalue = {0};
|
||||
SqlObject * value;
|
||||
|
||||
gvn_value_new_with_content (&gvalue, type, content);
|
||||
value = sql_value_new ();
|
||||
sql_value_set_value (SQL_VALUE (value), &gvalue);
|
||||
sql_batch_add (obj, id, value);
|
||||
g_object_unref (value);
|
||||
sql_batch_add (obj, id, sql_value_new_with_value (&gvalue));
|
||||
g_value_unset (&gvalue);
|
||||
}
|
||||
|
||||
|
@ -182,11 +167,11 @@ void sql_batch_remove (SqlBatch * obj, const gchar * id)
|
|||
g_return_val_if_fail (SQL_IS_BATCH (obj), NULL);
|
||||
g_return_val_if_fail (id, NULL);
|
||||
|
||||
SqlObject * child = sql_batch_get (obj, id);
|
||||
SqlObject * item = sql_batch_get (obj, id);
|
||||
|
||||
if (child)
|
||||
if (item)
|
||||
{
|
||||
sql_batch_free_child (obj, child);
|
||||
sql_batch_free_item (obj, item);
|
||||
g_hash_table_remove (obj->items, id);
|
||||
}
|
||||
}
|
||||
|
@ -232,23 +217,25 @@ void sql_batch_changed (SqlBatch * obj)
|
|||
|
||||
static void sql_batch_init (SqlBatch * obj)
|
||||
{
|
||||
obj->items = NULL;
|
||||
obj->items = g_hash_table_new_full (
|
||||
g_str_hash
|
||||
,g_str_equal
|
||||
,g_free
|
||||
,NULL
|
||||
);
|
||||
}
|
||||
|
||||
static void sql_batch_finalize (SqlBatch * obj)
|
||||
{
|
||||
if (obj->items)
|
||||
{
|
||||
GHashTableIter iter;
|
||||
gpointer child;
|
||||
gpointer item;
|
||||
GHashTableIter iter;
|
||||
|
||||
g_hash_table_iter_init (&iter, obj->items);
|
||||
g_hash_table_iter_init (&iter, obj->items);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, NULL, &child))
|
||||
sql_batch_free_child (obj, child);
|
||||
|
||||
g_hash_table_destroy (obj->items);
|
||||
}
|
||||
while (g_hash_table_iter_next (&iter, NULL, &item))
|
||||
sql_batch_free_item (obj, item);
|
||||
|
||||
g_hash_table_destroy (obj->items);
|
||||
|
||||
G_OBJECT_CLASS (sql_batch_parent_class)->finalize (G_OBJECT (obj));
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ SqlObject * sql_delete_new ()
|
|||
static void sql_delete_render (SqlDelete * obj, SqlRender * render)
|
||||
{
|
||||
sql_render_add_token (render, "DELETE");
|
||||
sql_render_add_list (render, TRUE, NULL, obj->tables, ",");
|
||||
sql_render_add_list (render, FALSE, NULL, obj->tables, ",");
|
||||
|
||||
if (SQL_DML (obj)->targets)
|
||||
{
|
||||
|
|
128
sql/sql-field.c
128
sql/sql-field.c
|
@ -52,7 +52,7 @@ SqlObject * sql_field_new (const gchar * name)
|
|||
*
|
||||
* Return value: an #SqlExpr
|
||||
*/
|
||||
SqlObject * sql_field_new_with_table (const gchar * name, const gchar * target, const gchar * schema)
|
||||
SqlObject * sql_field_new_with_target (const gchar * name, const gchar * target, const gchar * schema)
|
||||
{
|
||||
return g_object_new (SQL_TYPE_FIELD
|
||||
,"name", name
|
||||
|
@ -64,38 +64,102 @@ SqlObject * sql_field_new_with_table (const gchar * name, const gchar * target,
|
|||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
|
||||
|
||||
static void sql_field_render (SqlField * obj, SqlRender * render)
|
||||
static void sql_field_render (SqlField * self, SqlRender * render)
|
||||
{
|
||||
if (obj->target)
|
||||
if (self->target)
|
||||
{
|
||||
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->target);
|
||||
sql_render_add_identifier (render, self->target);
|
||||
sql_render_append (render, ".");
|
||||
}
|
||||
|
||||
if (!g_strcmp0 (obj->name, "*"))
|
||||
if (!g_strcmp0 (self->name, "*"))
|
||||
{
|
||||
sql_render_add_espace (render);
|
||||
sql_render_append (render, "*");
|
||||
}
|
||||
else
|
||||
sql_render_add_identifier (render, obj->name);
|
||||
sql_render_add_identifier (render, self->name);
|
||||
}
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
|
||||
|
||||
void sql_field_set_name (SqlField * obj, const gchar * name)
|
||||
/**
|
||||
* sql_field_get_name:
|
||||
* @self: the #SqlField
|
||||
*
|
||||
* Return value: the field name
|
||||
**/
|
||||
const gchar * sql_field_get_name (SqlField * self)
|
||||
{
|
||||
g_return_if_fail (SQL_IS_FIELD (obj));
|
||||
return self->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* sql_field_set_name:
|
||||
* @self: the #SqlField
|
||||
* @name: the field name
|
||||
**/
|
||||
void sql_field_set_name (SqlField * self, const gchar * name)
|
||||
{
|
||||
g_return_if_fail (SQL_IS_FIELD (self));
|
||||
g_return_if_fail (name);
|
||||
|
||||
g_free (obj->name);
|
||||
obj->name = g_strdup (name);
|
||||
g_free (self->name);
|
||||
self->name = g_strdup (name);
|
||||
}
|
||||
|
||||
/**
|
||||
* sql_field_get_target:
|
||||
* @self: the #SqlField
|
||||
*
|
||||
* Return value: the target name
|
||||
**/
|
||||
const gchar * sql_field_get_target (SqlField * self)
|
||||
{
|
||||
return self->target;
|
||||
}
|
||||
|
||||
/**
|
||||
* sql_field_set_target:
|
||||
* @self: the #SqlField
|
||||
* @target: the target name
|
||||
**/
|
||||
void sql_field_set_target (SqlField * self, const gchar * target)
|
||||
{
|
||||
g_return_if_fail (SQL_IS_FIELD (self));
|
||||
|
||||
g_free (self->target);
|
||||
self->target = g_strdup (target);
|
||||
}
|
||||
|
||||
/**
|
||||
* sql_field_get_schema:
|
||||
* @self: the #SqlField
|
||||
*
|
||||
* Return value: the schema name
|
||||
**/
|
||||
const gchar * sql_field_get_schema (SqlField * self)
|
||||
{
|
||||
return self->schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* sql_field_set_schema:
|
||||
* @self: the #SqlField
|
||||
* @schema: the schema name
|
||||
**/
|
||||
void sql_field_set_schema (SqlField * self, const gchar * schema)
|
||||
{
|
||||
g_return_if_fail (SQL_IS_FIELD (self));
|
||||
|
||||
g_free (self->schema);
|
||||
self->schema = g_strdup (schema);
|
||||
}
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
|
||||
|
@ -107,61 +171,59 @@ enum
|
|||
,PROP_SCHEMA
|
||||
};
|
||||
|
||||
static void sql_field_set_property (SqlField * obj, guint id,
|
||||
static void sql_field_set_property (SqlField * self, guint id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case PROP_NAME:
|
||||
sql_field_set_name (obj, g_value_get_string (value));
|
||||
sql_field_set_name (self, g_value_get_string (value));
|
||||
break;
|
||||
case PROP_TARGET:
|
||||
g_free (obj->target);
|
||||
obj->target = g_value_dup_string (value);
|
||||
sql_field_set_target (self, g_value_get_string (value));
|
||||
break;
|
||||
case PROP_SCHEMA:
|
||||
g_free (obj->schema);
|
||||
obj->schema = g_value_dup_string (value);
|
||||
sql_field_set_schema (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_field_get_property (SqlField * obj, guint id,
|
||||
static void sql_field_get_property (SqlField * 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_TARGET:
|
||||
g_value_set_string (value, obj->target);
|
||||
g_value_set_string (value, self->target);
|
||||
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_field_init (SqlField * obj)
|
||||
static void sql_field_init (SqlField * self)
|
||||
{
|
||||
obj->name = NULL;
|
||||
obj->target = NULL;
|
||||
obj->schema = NULL;
|
||||
self->name = NULL;
|
||||
self->target = NULL;
|
||||
self->schema = NULL;
|
||||
}
|
||||
|
||||
static void sql_field_finalize (SqlField * obj)
|
||||
static void sql_field_finalize (SqlField * self)
|
||||
{
|
||||
g_free (obj->name);
|
||||
g_free (obj->target);
|
||||
g_free (obj->schema);
|
||||
G_OBJECT_CLASS (sql_field_parent_class)->finalize (G_OBJECT (obj));
|
||||
g_free (self->name);
|
||||
g_free (self->target);
|
||||
g_free (self->schema);
|
||||
G_OBJECT_CLASS (sql_field_parent_class)->finalize (G_OBJECT (self));
|
||||
}
|
||||
|
||||
static void sql_field_class_init (SqlFieldClass * klass)
|
||||
|
|
|
@ -42,11 +42,17 @@ struct _SqlFieldClass
|
|||
SqlExprClass parent;
|
||||
};
|
||||
|
||||
GType sql_field_get_type ();
|
||||
SqlObject * sql_field_new (const gchar * name);
|
||||
SqlObject * sql_field_new_with_table (const gchar * name
|
||||
,const gchar * target
|
||||
,const gchar * schema);
|
||||
void sql_field_set_name (SqlField * obj, const gchar * name);
|
||||
GType sql_field_get_type ();
|
||||
SqlObject * sql_field_new (const gchar * name);
|
||||
SqlObject * sql_field_new_with_target (const gchar * name
|
||||
,const gchar * target
|
||||
,const gchar * schema);
|
||||
|
||||
const gchar * sql_field_get_name (SqlField * self);
|
||||
void sql_field_set_name (SqlField * obj, const gchar * name);
|
||||
const gchar * sql_field_get_target (SqlField * self);
|
||||
void sql_field_set_target (SqlField * obj, const gchar * target);
|
||||
const gchar * sql_field_get_schema (SqlField * self);
|
||||
void sql_field_set_schema (SqlField * obj, const gchar * schema);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -41,9 +41,9 @@ static void sql_holder_render (SqlHolder * obj, SqlRender * render, SqlBatch * b
|
|||
sql_render_printf (render, "#%s", obj->id);
|
||||
}
|
||||
|
||||
static void sql_holder_find_holders (SqlHolder * obj, GQueue * holders)
|
||||
static void sql_holder_find_holders (SqlHolder * obj, SqlBatch * batch)
|
||||
{
|
||||
g_queue_push_tail (holders, obj->id);
|
||||
sql_batch_add (batch, obj->id, NULL);
|
||||
}
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
|
||||
|
|
|
@ -39,13 +39,14 @@ static void sql_insert_render (SqlInsert * obj, SqlRender * render)
|
|||
|
||||
if (obj->table)
|
||||
{
|
||||
if (obj->values)
|
||||
if (obj->fields && sql_list_length (obj->fields) > 0)
|
||||
{
|
||||
sql_render_add_espace (render);
|
||||
sql_render_append (render, "(");
|
||||
sql_render_add_list (render, FALSE, NULL, obj->fields, ",");
|
||||
sql_render_append (render, ")");
|
||||
sql_render_add_token (render, "VALUES");
|
||||
sql_render_add_espace (render);
|
||||
sql_render_add_list (render, FALSE, NULL, obj->values, ",");
|
||||
}
|
||||
else
|
||||
|
@ -61,7 +62,7 @@ void sql_insert_set_table_from_name (SqlInsert * obj, const gchar * table)
|
|||
g_return_if_fail (table);
|
||||
|
||||
sql_object_remove (obj, obj->table);
|
||||
obj->table = sql_object_add (obj, sql_table_new (table));
|
||||
obj->table = sql_object_add (obj, sql_table_new (table, NULL));
|
||||
}
|
||||
|
||||
void sql_insert_add_expr (SqlInsert * obj, SqlExpr * expr)
|
||||
|
|
|
@ -70,12 +70,12 @@ static gboolean sql_list_is_ready (SqlList * obj)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
static void sql_list_find_holders (SqlList * obj, GQueue * holders)
|
||||
static void sql_list_find_holders (SqlList * obj, SqlBatch * batch)
|
||||
{
|
||||
GList * i;
|
||||
|
||||
for (i = obj->items.head; i; i = i->next)
|
||||
sql_object_get_holders (i->data, holders);
|
||||
sql_object_get_holders (i->data, batch);
|
||||
}
|
||||
|
||||
static void sql_list_item_changed (SqlObject * item, SqlObject * obj)
|
||||
|
|
|
@ -41,7 +41,7 @@ static void sql_object_child_changed (SqlObject * child, SqlObject * obj)
|
|||
sql_object_changed (obj);
|
||||
}
|
||||
|
||||
static void sql_object_find_holders (SqlObject * obj, GQueue * holders)
|
||||
static void sql_object_find_holders (SqlObject * obj, SqlBatch * batch)
|
||||
{
|
||||
guint i;
|
||||
guint nparams;
|
||||
|
@ -52,8 +52,12 @@ static void sql_object_find_holders (SqlObject * obj, GQueue * holders)
|
|||
for (i = 0; i < nparams; i++)
|
||||
if (SQL_IS_PARAM_OBJECT (params[i]) || SQL_IS_PARAM_LIST (params[i]))
|
||||
{
|
||||
SqlObject * child = sql_object_get (obj, params[i]->name);
|
||||
sql_object_get_holders (child, holders);
|
||||
SqlObject * child;
|
||||
|
||||
g_object_get (obj, params[i]->name, &child, NULL);
|
||||
|
||||
if (child)
|
||||
sql_object_get_holders (child, batch);
|
||||
}
|
||||
|
||||
g_free (params);
|
||||
|
@ -131,17 +135,19 @@ gboolean sql_object_is_ready (SqlObject * obj)
|
|||
guint nparams;
|
||||
GParamSpec ** params;
|
||||
gboolean is_ready = TRUE;
|
||||
SqlObjectClass * klass = SQL_OBJECT_GET_CLASS (obj);
|
||||
SqlObjectClass * klass;
|
||||
|
||||
g_return_val_if_fail (SQL_IS_OBJECT (obj), FALSE);
|
||||
|
||||
params = g_object_class_list_properties (G_OBJECT_GET_CLASS (obj), &nparams);
|
||||
|
||||
klass = SQL_OBJECT_GET_CLASS (obj);
|
||||
params = g_object_class_list_properties (G_OBJECT_CLASS (klass), &nparams);
|
||||
|
||||
for (i = 0; i < nparams && is_ready; i++)
|
||||
if (SQL_IS_PARAM_OBJECT (params[i]) || SQL_IS_PARAM_LIST (params[i]))
|
||||
{
|
||||
SqlObject * child = sql_object_get (obj, params[i]->name);
|
||||
is_ready = sql_object_is_ready (child);
|
||||
SqlObject * child;
|
||||
g_object_get (obj, params[i]->name, &child, NULL);
|
||||
is_ready = !child || sql_object_is_ready (child);
|
||||
}
|
||||
|
||||
g_free (params);
|
||||
|
@ -199,12 +205,12 @@ void sql_object_remove_child (SqlObject * obj, const gchar * property, guint n)
|
|||
*
|
||||
* Gets all identifiers of the contained holders.
|
||||
**/
|
||||
void sql_object_get_holders (SqlObject * obj, GQueue * holders)
|
||||
void sql_object_get_holders (SqlObject * obj, SqlBatch * batch)
|
||||
{
|
||||
g_return_if_fail (SQL_IS_OBJECT (obj) || !obj);
|
||||
g_return_if_fail (SQL_IS_OBJECT (obj));
|
||||
g_return_if_fail (SQL_IS_BATCH (batch));
|
||||
|
||||
if (obj)
|
||||
SQL_OBJECT_GET_CLASS (obj)->find_holders (obj, holders);
|
||||
SQL_OBJECT_GET_CLASS (obj)->find_holders (obj, batch);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,7 +32,7 @@ typedef struct _SqlObject SqlObject;
|
|||
typedef struct _SqlObjectClass SqlObjectClass;
|
||||
|
||||
typedef gboolean (* SqlObjectIsReadyFunc) (SqlObject * obj);
|
||||
typedef void (* SqlObjectFindHoldersFunc) (SqlObject * obj, GQueue * holders);
|
||||
typedef void (* SqlObjectFindHoldersFunc) (); // (SqlObject * obj, SqlBatch * holders);
|
||||
typedef void (* SqlRenderFunc) (); // (SqlObject * obj, SqlRender * render, SqlBatch * batch);
|
||||
|
||||
struct _SqlObject
|
||||
|
@ -55,7 +55,7 @@ struct _SqlObjectClass
|
|||
GType sql_object_get_type ();
|
||||
void sql_object_render (SqlObject * obj, SqlRender * render, SqlBatch * batch);
|
||||
gboolean sql_object_is_ready (SqlObject * obj);
|
||||
void sql_object_get_holders (SqlObject * obj, GQueue * holders);
|
||||
void sql_object_get_holders (SqlObject * obj, SqlBatch * batch);
|
||||
|
||||
void sql_object_set (SqlObject * obj, const gchar * property, SqlObject * set);
|
||||
SqlObject * sql_object_get (SqlObject * obj, const gchar * property);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#define SQL_PARSER_H
|
||||
|
||||
#include "sql-object.h"
|
||||
#include "sql-field.h"
|
||||
|
||||
#define SQL_PARSER_LOG_DOMAIN (g_quark_from_string ("SqlParser"))
|
||||
|
||||
|
@ -30,6 +31,8 @@
|
|||
*
|
||||
* Return value: (transfer full): an #SqlObject.
|
||||
*/
|
||||
SqlObject * sql_parser_parse (gchar * sql) G_GNUC_WARN_UNUSED_RESULT;
|
||||
SqlObject * sql_parser_parse (gchar * sql) G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
SqlField * sql_parser_parse_field (const gchar * field_str);
|
||||
|
||||
#endif
|
|
@ -308,7 +308,7 @@ void sql_render_add_list (SqlRender * obj, gboolean required, const gchar * toke
|
|||
SqlList * list, const gchar * separator)
|
||||
{
|
||||
g_return_if_fail (SQL_IS_RENDER (obj));
|
||||
g_return_if_fail (SQL_IS_LIST (list));
|
||||
g_return_if_fail (SQL_IS_LIST (list) || !list);
|
||||
|
||||
sql_render_add_list_with_func (obj, required, token, list, separator, NULL);
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ void sql_render_add_list_with_func (SqlRender * obj, gboolean required, const gc
|
|||
GList * i;
|
||||
|
||||
g_return_if_fail (SQL_IS_RENDER (obj));
|
||||
g_return_if_fail (SQL_IS_LIST (list));
|
||||
g_return_if_fail (SQL_IS_LIST (list) || !list);
|
||||
|
||||
if (list && (i = sql_list_get_items (list)))
|
||||
{
|
||||
|
|
|
@ -33,11 +33,6 @@ SqlObject * sql_set_new ()
|
|||
|
||||
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, ")");
|
||||
|
|
|
@ -59,12 +59,12 @@ static void sql_string_render (SqlString * obj, SqlRender * render)
|
|||
sql_render_append (render, ptr);
|
||||
}
|
||||
|
||||
static void sql_string_find_holders (SqlString * obj, GQueue * holders)
|
||||
static void sql_string_find_holders (SqlString * obj, SqlBatch * batch)
|
||||
{
|
||||
GSList * i;
|
||||
|
||||
for (i = obj->holders; i; i = i->next)
|
||||
sql_object_get_holders (((HolderData *) i->data)->holder, holders);
|
||||
sql_object_get_holders (((HolderData *) i->data)->holder, batch);
|
||||
}
|
||||
|
||||
static void sql_string_free_holder_data (HolderData * holder_data)
|
||||
|
|
|
@ -26,9 +26,9 @@
|
|||
**/
|
||||
G_DEFINE_TYPE (SqlTable, sql_table, SQL_TYPE_TARGET);
|
||||
|
||||
SqlObject * sql_table_new (const gchar * name)
|
||||
SqlObject * sql_table_new (const gchar * name, const gchar * schema)
|
||||
{
|
||||
return g_object_new (SQL_TYPE_TABLE, "name", name, NULL);
|
||||
return g_object_new (SQL_TYPE_TABLE, "name", name, "schema", schema, NULL);
|
||||
}
|
||||
|
||||
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Private
|
||||
|
|
|
@ -41,6 +41,6 @@ struct _SqlTableClass
|
|||
};
|
||||
|
||||
GType sql_table_get_type ();
|
||||
SqlObject * sql_table_new (const gchar * name);
|
||||
SqlObject * sql_table_new (const gchar * name, const gchar * schema);
|
||||
|
||||
#endif
|
||||
|
|
Reference in New Issue