Actualizado con los ultimos cambios locales del proyecto subversion

This commit is contained in:
Juan Ferrer Toribio 2013-10-14 13:59:07 +02:00
parent beeb26a19e
commit 67bd1ad79c
36 changed files with 95 additions and 236 deletions

View File

@ -3,8 +3,8 @@
<!-- interface-requires vn 0.0 -->
<!-- interface-requires gtk+ 3.0 -->
<object class="DbIterator" id="account">
<property name="sql">SELECT user_id, group_id, uid, last_change, expire FROM account WHERE #p</property>
<property name="mode">on-iter</property>
<property name="sql">SELECT user_id, group_id, uid, last_change, expire FROM account WHERE #p</property>
</object>
<object class="DbIterator" id="alias">
<property name="sql">SELECT mail_alias_id, user_id FROM mail_alias_account WHERE #p</property>
@ -707,6 +707,7 @@
<property name="spacing">6</property>
<property name="layout_style">end</property>
<property name="iterator">sip</property>
<property name="simple_record">True</property>
</object>
<packing>
<property name="expand">False</property>
@ -899,8 +900,8 @@
</object>
<object class="DbParam" id="search-user"/>
<object class="DbIterator" id="sip">
<property name="sql">SELECT user_id, extension, secret, callerid, callgroup FROM account_sip WHERE #p</property>
<property name="mode">on-iter</property>
<property name="sql">SELECT user_id, extension, secret, callerid, callgroup FROM account_sip WHERE #p</property>
</object>
<object class="DbIterator" id="users">
<property name="sql">SELECT u.id, u.name, u.mysql_user_id, m.user, u.active FROM `user` u JOIN mysql_user m ON u.mysql_user_id = m.id</property>

View File

@ -77,16 +77,18 @@ void vn_users_on_dialog_response (GtkDialog * dialog, gint response_id, VnUsers
vn_users_reset_dialog (obj, _("Passwords do not match."));
else
{
SqlString * query;
SqlObject * query;
SqlBatch * batch;
query = sql_string_new ("SELECT user_set_password (#user, #password)"
,"user", GVN_TYPE_PARAM, obj->user_id
,"password", G_TYPE_STRING, password
,NULL
);
query = sql_string_new ("SELECT user_set_password (#user, #password)");
batch = sql_batch_new ();
sql_batch_add_from_param ("user", obj->user_id);
sql_batch_add_from_value ("password", G_TYPE_STRING, password);
db_conn_query_with_stmt_async (VN_FORM (obj)->conn
,SQL_STMT (query)
,batch
,(DbRequestDoneCallback) vn_users_on_password_changed
,g_object_ref (obj)
,g_object_unref

View File

@ -10,6 +10,7 @@ sql_include_HEADERS = \
sql-param-list.h \
sql-holder.h \
sql-list.h \
sql-batch.h \
sql-set.h \
sql-multi-stmt.h \
sql-string.h \
@ -47,6 +48,7 @@ libsql_la_SOURCES = \
sql-param-list.c \
sql-holder.c \
sql-list.c \
sql-batch.c \
sql-set.c \
sql-expr.c \
sql-insert.c \

View File

@ -44,6 +44,7 @@
}
}
%default_type {SqlObject *}
%token_type {gchar *}
%token_destructor {g_free ($$);}
%token_prefix SQL_PARSER_
@ -94,7 +95,6 @@
// Start symbol:
%start_symbol start
%type start {SqlObject *}
start ::= multi_stmt (A).
{
state->object = SQL_OBJECT (A);
@ -102,7 +102,6 @@ start ::= multi_stmt (A).
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Multi statement
%type multi_stmt {SqlStmt *}
multi_stmt(A) ::= stmt_list(stmts).
{
guint len = sql_list_length (stmts);
@ -123,7 +122,6 @@ stmt_list(A) ::= stmt(X) SC stmt_list(B). { A = list_add (X, B); }
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Statemet
%type stmt {SqlStmt *}
stmt(A) ::= select_stmt(X). { A = X; }
stmt(A) ::= delete_stmt(X). { A = X; }
stmt(A) ::= update_stmt(X). { A = X; }
@ -131,7 +129,6 @@ stmt(A) ::= insert_stmt(X). { A = X; }
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Select
%type select_stmt {SqlStmt *}
select_stmt(A) ::= select_stmt(B) set_op(type) simple_select(X).
{
g_object_set (B, "type", type, "next", X, NULL);
@ -146,7 +143,6 @@ set_op(A) ::= UNION. { A = SQL_SELECT_UNION_ALL; }
set_op(A) ::= INTERSECT. { A = SQL_SELECT_INTERSECT; }
set_op(A) ::= EXCEPT. { A = SQL_SELECT_EXCEPT; }
%type simple_select {SqlStmt *}
simple_select(A) ::= LP simple_select(X) RP. { A = X; }
simple_select(A) ::= SELECT
distinct(distinct)
@ -182,7 +178,6 @@ distinct(A) ::= DISTINCT. { A = TRUE; }
distinct(A) ::= ALL. { A = FALSE; }
distinct(A) ::= . { A = FALSE; }
%type select_field {SqlSelectField *}
select_field(A) ::= expr(X).
{ A = g_object_new (SQL_TYPE_SELECT_FIELD, "expr", X, NULL); }
select_field(A) ::= expr(X) alias(Y).
@ -200,7 +195,6 @@ from(A) ::= . { A = NULL; }
group(A) ::= GROUP expr_list(X). { A = X; }
group(A) ::= . { A = NULL; }
%type having {SqlExpr *}
having(A) ::= HAVING expr(X). { A = X; }
having(A) ::= . { A = NULL; }
@ -212,7 +206,6 @@ order(A) ::= . { A = NULL; }
order_list(A) ::= order_expr(X). { A = list_new (X, SQL_TYPE_SELECT_ORDER); }
order_list(A) ::= order_list(B) CM order_expr(X). { A = list_add (X, B); }
%type order_expr {SqlSelectOrder *}
order_expr(A) ::= expr(X) order_way(Y). { A = g_object_new (SQL_TYPE_SELECT_ORDER, "expr", X, "way", Y, NULL); }
%type order_way {SqlSelectOrderWay}
@ -247,7 +240,6 @@ limit(A) ::= . { A = NULL; }
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Delete
%type delete_stmt {SqlStmt *}
delete_stmt(A) ::= DELETE table_list(targets) del_using(tables) where(where).
{
A = g_object_new (SQL_TYPE_DELETE
@ -268,7 +260,6 @@ del_using(A) ::= . { A = NULL; }
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Update
%type update_stmt {SqlStmt *}
update_stmt(A) ::= UPDATE table(table) SET update_list(sets) where(where).
{
A = g_object_new (SQL_TYPE_UPDATE
@ -283,7 +274,6 @@ update_stmt(A) ::= UPDATE table(table) SET update_list(sets) where(where).
update_list(A) ::= update_set(X). { A = list_new (X, SQL_TYPE_UPDATE_SET); }
update_list(A) ::= update_list(B) CM update_set(X). { A = list_add (X, B); }
%type update_set {SqlUpdateSet *}
update_set(A) ::= field(X) EQ def_expr(Y).
{
A = g_object_new (SQL_TYPE_UPDATE_SET
@ -295,7 +285,6 @@ update_set(A) ::= field(X) EQ def_expr(Y).
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Insert
%type insert_stmt {SqlStmt *}
insert_stmt(A) ::= INSERT table(table) insert_fields(fields) insert_values(values).
{
A = g_object_new (SQL_TYPE_INSERT
@ -323,7 +312,6 @@ insert_values(A) ::= VALUES set_list(X). { A = X; }
set_list(A) ::= set(X). { A = list_new (X, SQL_TYPE_SET); }
set_list(A) ::= set_list(B) CM set(X). { A = list_add (X, B); }
%type set {SqlSet *}
set(A) ::= LP def_expr_list(X) RP. { A = g_object_new (SQL_TYPE_SET, "exprs", X, NULL); }
%type def_expr_list {SqlList *}
@ -332,17 +320,14 @@ def_expr_list(A) ::= def_expr_list(B) CM def_expr(X). { A = list_add (X, B); }
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Common to statements
%type where {SqlExpr *}
where(A) ::= WHERE expr(X). { A = SQL_EXPR (X); }
where(A) ::= WHERE expr(X). { A = X; }
where(A) ::= . { A = NULL; }
%type def_expr {SqlExpr *}
def_expr(A) ::= expr(X). { A = X; }
def_expr(A) ::= DEFAULT. { A = NULL; }
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Target
%type target {SqlTarget *}
target(A) ::= unaliased_target(X). { A = X; }
target(A) ::= unaliased_target(X) alias(Y).
{
@ -355,14 +340,12 @@ target(A) ::= unaliased_target(X) alias(Y).
target_list(A) ::= target(X). { A = list_new (X, SQL_TYPE_TARGET); }
target_list(A) ::= target_list(B) CM target(X). { A = list_add (X, B); }
%type unaliased_target {SqlTarget *}
unaliased_target(A) ::= join(X). { A = X; }
unaliased_target(A) ::= subquery(X). { A = X; }
unaliased_target(A) ::= table(X). { A = X; }
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Join
%type join {SqlTarget *}
join(A) ::= target(left) join_type(type) target(right) join_cond(condition).
{
A = g_object_new (SQL_TYPE_JOIN
@ -391,15 +374,14 @@ join(A) ::= target(left) join_type(type) target(right) join_cond(condition).
,NULL
);
gchar * target = left->alias ?
left->alias : SQL_TABLE (left)->name;
gchar * target = SQL_TARGET (left)->alias ? SQL_TARGET (left)->alias : SQL_TABLE (left)->name;
gchar * schema = SQL_IS_TABLE(left) && SQL_TABLE (left)->schema ?
SQL_TABLE (left)->schema : NULL;
g_object_set (n->data, "target", target, "schema", schema, NULL);
sql_list_add (equal, n->data);
target = right->alias ? right->alias : SQL_TABLE (right)->name;
target = SQL_TARGET (right)->alias ? SQL_TARGET (right)->alias : SQL_TABLE (right)->name;
schema = SQL_IS_TABLE (right) && SQL_TABLE (right)->schema ?
SQL_TABLE (right)->schema : NULL;
@ -428,7 +410,6 @@ join_cond(A) ::= USING LP field_list(X) RP. { A = X; }
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Subquery
%type subquery {SqlTarget *}
subquery(A) ::= LP select_stmt(stmts) RP.
{
A = g_object_new (SQL_TYPE_SUBQUERY, "stms", stmts, NULL);
@ -436,19 +417,17 @@ subquery(A) ::= LP select_stmt(stmts) RP.
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Table
%type table {SqlTarget *}
table(A) ::= identifier(X).
{
A = g_object_new (SQL_TYPE_TABLE, "table", X, NULL);
A = g_object_new (SQL_TYPE_TABLE, "name", X, NULL);
}
table(A) ::= identifier(Y) DOT identifier(X).
{
A = g_object_new (SQL_TYPE_TABLE, "table", X, "schema", Y, NULL);
A = g_object_new (SQL_TYPE_TABLE, "name", X, "schema", Y, NULL);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Expr
%type expr {SqlExpr *}
expr(A) ::= LP expr(X) RP. { A = X; }
%type expr_list {SqlList *}
@ -462,7 +441,6 @@ expr(A) ::= value(X). { A = X; }
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Field
%type field {SqlExpr *}
field(A) ::= unqualified_field(X). { A = X; }
field(A) ::= identifier(Y) DOT unqualified_field(X).
{
@ -475,7 +453,6 @@ field(A) ::= identifier(Z) DOT identifier(Y) DOT unqualified_field(X).
A = X;
}
%type unqualified_field {SqlExpr *}
unqualified_field(A) ::= identifier(X).
{
A = g_object_new (SQL_TYPE_FIELD, "name", X, NULL);
@ -491,7 +468,6 @@ field_list(A) ::= field_list(B) CM field(X). { A = list_add (X, B); }
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Function
%type function {SqlExpr *}
function(A) ::= unqualified_function(X). { A = X; }
function(A) ::= identifier(Z) DOT unqualified_function(X).
{
@ -499,7 +475,6 @@ function(A) ::= identifier(Z) DOT unqualified_function(X).
A = X;
}
%type unqualified_function {SqlExpr *}
unqualified_function(A) ::= identifier(X) LP function_expr_list(Y) RP.
{
A = g_object_new (SQL_TYPE_FUNCTION, "name", X, "params", Y, NULL);
@ -511,10 +486,9 @@ function_expr_list(A) ::= expr_list(X). { A = X; }
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Operation
%type operation {SqlExpr *}
%include
{
static inline SqlExpr * create_operation
static inline SqlObject * create_operation
(const gpointer X, const gpointer Y, const SqlOperationType type)
{
SqlList * exprs = sql_list_new (SQL_TYPE_EXPR);
@ -529,7 +503,7 @@ function_expr_list(A) ::= expr_list(X). { A = X; }
operation(A) ::= MINUS expr(X). [SIGN]
{
GValue value = {0};
SqlExpr * minus = sql_value_new ();
SqlObject * minus = sql_value_new ();
g_value_init (&value, G_TYPE_INT);
g_value_set_int (&value, -1);
sql_value_set_value (SQL_VALUE (minus), &value);
@ -594,8 +568,6 @@ operation(A) ::= expr(X) MOD expr(Y).
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Value
%type value {SqlExpr *}
value(A) ::= INTEGER(X).
{
GValue value = {0};
@ -603,7 +575,6 @@ value(A) ::= INTEGER(X).
A = g_object_new (SQL_TYPE_VALUE, "value", &value, NULL);
g_value_unset (&value);
}
value(A) ::= FLOAT(X).
{
GValue value = {0};
@ -612,7 +583,6 @@ value(A) ::= FLOAT(X).
A = g_object_new (SQL_TYPE_VALUE, "value", &value, NULL);
g_value_unset (&value);
}
value(A) ::= STRING(X).
{
GValue value = {0};
@ -620,7 +590,6 @@ value(A) ::= STRING(X).
A = g_object_new (SQL_TYPE_VALUE, "value", &value, NULL);
g_value_unset (&value);
}
value(A) ::= BOOLEAN(X).
{
GValue value = {0};
@ -633,17 +602,15 @@ value(A) ::= BOOLEAN(X).
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Alias
%type alias {gchar *}
%destructor alias {g_free ($$);}
alias(A) ::= AS identifier(X). { A = X; }
alias(A) ::= identifier(X). { A = X; }
%type identifier {gchar *}
identifier(A) ::= IDENTIFIER(X). { A = X; }
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Placeholder
%type placeholder {gchar *}
%destructor expr {g_free ($$);}
placeholder(A) ::= PLACEHOLDER(X). { A = X; }
placeholder(A) ::= PLACEHOLDER(X). { A = g_object_new (SQL_TYPE_HOLDER, "id", X, NULL); }
stmt ::= placeholder.
target ::= placeholder.

View File

@ -30,12 +30,12 @@ typedef struct _SqlDeleteClass SqlDeleteClass;
/**
* SqlDelete:
* @table: (element-type Sql.Table): list of targeted tables
* @table: list of targeted tables
**/
struct _SqlDelete
{
SqlDml parent;
SqlList * tables;
SqlList * tables; // List of SqlTable
};
struct _SqlDeleteClass

View File

@ -28,7 +28,7 @@ G_DEFINE_ABSTRACT_TYPE (SqlDml, sql_dml, SQL_TYPE_STMT);
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
void sql_dml_set_where (SqlDml * obj, SqlExpr * where)
void sql_dml_set_where (SqlDml * obj, SqlObject * where)
{
g_return_if_fail (SQL_IS_DML (obj));
g_return_if_fail (SQL_IS_EXPR (where) || SQL_IS_HOLDER (where) || !where);

View File

@ -31,13 +31,13 @@ typedef struct _SqlDmlClass SqlDmlClass;
/**
* SqlDml:
* @target: (element-type Sql.Target): list of targets for the DML query
* @target: list of targets for the DML query
* @where: an #SqlExpr
**/
struct _SqlDml
{
SqlStmt parent;
SqlList * targets;
SqlList * targets; // List of SqlTarget
SqlExpr * where;
};
@ -48,6 +48,6 @@ struct _SqlDmlClass
};
GType sql_dml_get_type ();
void sql_dml_set_where (SqlDml * obj, SqlExpr * expr);
void sql_dml_set_where (SqlDml * obj, SqlObject * expr);
#endif

View File

@ -26,7 +26,7 @@
**/
G_DEFINE_TYPE (SqlFunction, sql_function, SQL_TYPE_EXPR);
SqlFunction * sql_function_new (const gchar * name, const gchar * schema)
SqlObject * sql_function_new (const gchar * name, const gchar * schema)
{
return g_object_new (SQL_TYPE_FUNCTION, "name", name, "schema", schema, NULL);
}
@ -42,13 +42,9 @@ static void sql_function_render (SqlFunction * obj, SqlRender * render)
}
sql_render_add_identifier (render, obj->name);
if (obj->name)
{
sql_render_append (render, "(");
sql_render_add_list (render, FALSE, NULL, obj->params, ",");
sql_render_append (render, ")");
}
sql_render_append (render, "(");
sql_render_add_list (render, FALSE, NULL, obj->params, ",");
sql_render_append (render, ")");
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties

View File

@ -47,6 +47,6 @@ struct _SqlFunctionClass
};
GType sql_function_get_type ();
SqlFunction * sql_function_new (const gchar * name, const gchar * schema);
SqlObject * sql_function_new (const gchar * name, const gchar * schema);
#endif

View File

@ -24,7 +24,7 @@
**/
G_DEFINE_TYPE (SqlHolder, sql_holder, SQL_TYPE_OBJECT);
SqlHolder * sql_holder_new (const gchar * id)
SqlObject * sql_holder_new (const gchar * id)
{
return g_object_new (SQL_TYPE_HOLDER, "id", id, NULL);
}
@ -37,7 +37,7 @@ static void sql_holder_render (SqlHolder * obj, SqlRender * render)
GSList * i = sql_render_get_ancestors (render);
for (; i && !held_object; i = i->next)
held_object = sql_object_get_held_object (held_object, obj->id);
held_object = sql_object_get_held (held_object, obj->id);
if (held_object)
sql_render_add_object (render, held_object);

View File

@ -40,7 +40,7 @@ struct _SqlHolderClass
};
GType sql_holder_get_type ();
SqlHolder * sql_holder_new (const gchar * id);
SqlObject * sql_holder_new (const gchar * id);
const gchar * sql_holder_get_id (SqlHolder * obj);
#endif

View File

@ -27,7 +27,7 @@
**/
G_DEFINE_TYPE (SqlJoin, sql_join, SQL_TYPE_TARGET);
SqlTarget * sql_join_new (SqlTarget * left, SqlTarget * right, SqlJoinType type)
SqlObject * sql_join_new (SqlTarget * left, SqlTarget * right, SqlJoinType type)
{
return g_object_new (SQL_TYPE_JOIN
,"target-left" ,left

View File

@ -59,7 +59,7 @@ struct _SqlJoinClass
GType sql_join_get_type ();
GType sql_join_type_get_type ();
SqlTarget * 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);
void sql_join_set_target_right (SqlJoin * obj, SqlTarget * target);
void sql_join_set_target_left (SqlJoin * obj, SqlTarget * target);

View File

@ -26,7 +26,7 @@
**/
G_DEFINE_TYPE (SqlMultiStmt, sql_multi_stmt, SQL_TYPE_STMT);
SqlMultiStmt * sql_multi_stmt_new ()
SqlObject * sql_multi_stmt_new ()
{
return g_object_new (SQL_TYPE_MULTI_STMT, NULL);
}

View File

@ -44,6 +44,6 @@ struct _SqlMultiStmtClass
};
GType sql_multi_stmt_get_type ();
SqlMultiStmt * sql_multi_stmt_new ();
SqlObject * sql_multi_stmt_new ();
#endif

View File

@ -16,6 +16,7 @@
*/
#include "sql-object.h"
#include "sql-value.h"
/**
* SECTION: sql-object
@ -176,54 +177,6 @@ void sql_object_remove_child (SqlObject * obj, const gchar * property, guint n)
sql_list_remove (list, n);
}
/**
* sql_object_add_held_object:
* @obj: a #SqlObject
* @id: the id of the #SqlHolder
* @held_object: the held object
*
* Adds a held object.
**/
void sql_object_add_held_object (SqlObject * obj, const gchar * id, SqlObject * held_object)
{
g_return_if_fail (SQL_IS_OBJECT (obj));
g_return_if_fail (id);
if (!obj->held_objects)
obj->held_objects = g_hash_table_new_full (
g_str_hash
,g_str_equal
,g_free
,g_object_unref
);
g_signal_connect (held_object, "changed",
G_CALLBACK (sql_object_child_changed), obj
);
g_hash_table_replace (obj->held_objects,
g_strdup (id), g_object_ref_sink (held_object));
}
/**
* sql_object_get_held_object:
* @obj: a #SqlObject
* @id: the id of the #SqlHolder
*
* Gets a held object by its id.
*
* Return value: the #SqlObject if an object with that id exists, %NULL otherwise
**/
SqlObject * sql_object_get_held_object (SqlObject * obj, const gchar * id)
{
g_return_val_if_fail (SQL_IS_OBJECT (obj), NULL);
g_return_val_if_fail (id, NULL);
if (obj->held_objects)
return g_hash_table_lookup (obj->held_objects, id);
return NULL;
}
/**
* sql_object_changed:
* @obj: a #SqlObject
@ -237,19 +190,10 @@ void sql_object_changed (SqlObject * obj)
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Class
static void sql_object_init (SqlObject * obj)
{
obj->child_groups = NULL;
obj->held_objects = NULL;
}
static void sql_object_init (SqlObject * obj) {}
static void sql_object_finalize (SqlObject * obj)
{
if (obj->child_groups)
g_hash_table_destroy (obj->child_groups);
if (obj->held_objects)
g_hash_table_destroy (obj->held_objects);
G_OBJECT_CLASS (sql_object_parent_class)->finalize (G_OBJECT (obj));
}

View File

@ -36,8 +36,6 @@ typedef gboolean (* SqlObjectIsReadyFunc) (SqlObject * obj);
struct _SqlObject
{
GInitiallyUnowned parent;
GHashTable * child_groups;
GHashTable * held_objects;
};
struct _SqlObjectClass
@ -60,9 +58,6 @@ void sql_object_set (SqlObject * obj, const gchar * property, SqlObject * se
SqlObject * sql_object_get (SqlObject * obj, const gchar * property);
void sql_object_add_child (SqlObject * obj, const gchar * property, SqlObject * child);
void sql_object_remove_child (SqlObject * obj, const gchar * property, guint n);
void sql_object_add_held_object (SqlObject * obj, const gchar * id, SqlObject * held_object);
SqlObject * sql_object_get_held_object (SqlObject * obj, const gchar * id);
void sql_object_changed (SqlObject * obj);
gpointer sql_object_add (gpointer obj, gpointer child);

View File

@ -145,7 +145,7 @@ static void sql_operation_class_init (SqlOperationClass * klass)
,"Operators"
,"The list of operators"
,SQL_TYPE_EXPR
,G_PARAM_READWRITE
,G_PARAM_READWRITE | G_PARAM_CONSTRUCT
));
}

View File

@ -296,7 +296,7 @@ void sql_render_add_item (SqlRender * obj, gboolean required, const gchar * toke
* @obj: a #SqlRender
* @required:
* @token:
* @list: (element-type GObject.Object): a list of objects to add
* @list: a list of objects to add
* @separator:
*
*
@ -307,21 +307,7 @@ void sql_render_add_list (SqlRender * obj, gboolean required, const gchar * toke
g_return_if_fail (SQL_IS_RENDER (obj));
g_return_if_fail (SQL_IS_LIST (list));
if (list)
{
GList * n;
sql_render_add_token (obj, token);
for (n = sql_list_get_items (list); n; n = n->next)
{
sql_render_add_object (obj, n->data);
if (n->next)
g_string_append_printf (obj->buffer, " %s", separator);
}
}
else if (required)
sql_render_set_error (obj);
sql_render_add_list_with_func (obj, required, token, list, separator, NULL);
}
/**
@ -329,7 +315,7 @@ void sql_render_add_list (SqlRender * obj, gboolean required, const gchar * toke
* @obj: a #SqlRender
* @required:
* @token:
* @list: (element-type GObject.Object):
* @list:
* @separator:
* @function: (scope call):
*
@ -338,17 +324,21 @@ void sql_render_add_list (SqlRender * obj, gboolean required, const gchar * toke
void sql_render_add_list_with_func (SqlRender * obj, gboolean required, const gchar * token,
SqlList * list, const gchar * separator, SqlRenderFunc function)
{
GList * n;
g_return_if_fail (SQL_IS_RENDER (obj));
g_return_if_fail (SQL_IS_LIST (list));
if (list)
if (list && (n = sql_list_get_items (list)))
{
GList * n;
sql_render_add_token (obj, token);
for (n = sql_list_get_items (list); n; n = n->next)
for (; n; n = n->next)
{
function (n->data, obj);
if (function)
function (n->data, obj);
else
sql_render_add_object (obj, n->data);
if (n->next)
g_string_append_printf (obj->buffer, " %s", separator);

View File

@ -24,7 +24,7 @@
**/
G_DEFINE_TYPE (SqlSelectField, sql_select_field, SQL_TYPE_OBJECT);
SqlSelectField * sql_select_field_new ()
SqlObject * sql_select_field_new ()
{
return g_object_new (SQL_TYPE_SELECT_FIELD, NULL);
}

View File

@ -41,7 +41,7 @@ struct _SqlSelectFieldClass
SqlObjectClass parent;
};
GType sql_select_field_get_type ();
SqlSelectField * sql_select_field_new ();
GType sql_select_field_get_type ();
SqlObject * sql_select_field_new ();
#endif

View File

@ -24,7 +24,7 @@
**/
G_DEFINE_TYPE (SqlSelectOrder, sql_select_order, SQL_TYPE_OBJECT);
SqlSelectOrder * sql_select_order_new ()
SqlObject * sql_select_order_new ()
{
return g_object_new (SQL_TYPE_SELECT_ORDER, NULL);
}

View File

@ -55,9 +55,9 @@ struct _SqlSelectOrderClass
SqlObjectClass parent;
};
GType sql_select_order_get_type ();
GType sql_select_order_way_get_type ();
GType sql_select_order_get_type ();
GType sql_select_order_way_get_type ();
SqlSelectOrder * sql_select_order_new ();
SqlObject * sql_select_order_new ();
#endif

View File

@ -254,14 +254,14 @@ static void sql_select_class_init (SqlSelectClass * klass)
,"Fields"
,"The list of fields"
,SQL_TYPE_EXPR
,G_PARAM_READWRITE
,G_PARAM_READWRITE | G_PARAM_CONSTRUCT
));
g_object_class_install_property (k, PROP_GROUP,
sql_param_object ("group"
sql_param_list ("group"
,"Group"
,"The GROUP BY section"
,SQL_TYPE_EXPR
,G_PARAM_READWRITE
,G_PARAM_READWRITE | G_PARAM_CONSTRUCT
));
g_object_class_install_property (k, PROP_HAVING,
sql_param_object ("having"
@ -275,11 +275,12 @@ static void sql_select_class_init (SqlSelectClass * klass)
,"Order"
,"The ORDER BY section"
,SQL_TYPE_SELECT_ORDER
,G_PARAM_READWRITE
,G_PARAM_READWRITE | G_PARAM_CONSTRUCT
));
g_object_class_install_property (k, PROP_LIMIT_COUNT,
g_param_spec_uint ("limit-count"
,"Limit count"
,"The COUNT field of the LIMIT clause"
,0, G_MAXUINT, 0
,G_PARAM_READWRITE

View File

@ -42,18 +42,15 @@ SqlSelectType;
/**
* SqlSelect:
* @expr: (element-type Sql.Expr):
* @group: (element-type Sql.Expr):
* @order: (element-type Sql.Expr):
**/
struct _SqlSelect
{
SqlDml parent;
gboolean distinct;
SqlList * fields;
SqlList * group;
SqlList * fields; // List of SqlSelectField
SqlList * group; // List of SqlExpr
SqlExpr * having;
SqlList * order;
SqlList * order; // List of SqlSelectOrder
guint limit_offset;
guint limit_count;

View File

@ -24,7 +24,7 @@
**/
G_DEFINE_TYPE (SqlSet, sql_set, SQL_TYPE_EXPR);
SqlSet * sql_set_new ()
SqlObject * sql_set_new ()
{
return g_object_new (SQL_TYPE_SET, NULL);
}
@ -103,6 +103,6 @@ static void sql_set_class_init (SqlSetClass * klass)
,"Expressions"
,"The list of expressions"
,SQL_TYPE_EXPR
,G_PARAM_READWRITE
,G_PARAM_READWRITE | G_PARAM_CONSTRUCT
));
}

View File

@ -40,6 +40,6 @@ struct _SqlSetClass
};
GType sql_set_get_type ();
SqlSet * sql_set_new ();
SqlObject * sql_set_new ();
#endif

View File

@ -22,7 +22,7 @@ typedef struct
{
gchar * start;
gchar * end;
SqlHolder * holder;
SqlObject * holder;
}
HolderData;
@ -35,7 +35,7 @@ HolderData;
**/
G_DEFINE_TYPE (SqlString, sql_string, SQL_TYPE_STMT);
SqlString * sql_string_new (const gchar * sql)
SqlObject * sql_string_new (const gchar * sql)
{
return g_object_new (SQL_TYPE_STRING, "sql", sql, NULL);
}
@ -65,44 +65,6 @@ static void sql_string_free_holder_data (HolderData * holder_data)
g_free (holder_data);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
/**
* sql_string_add_param:
* @obj: the #SqlString
* @id: the id assigned to the item
**/
void sql_string_add_param (SqlString * obj, const gchar * id, GvnParam * param)
{
g_return_if_fail (SQL_IS_STRING (obj));
g_return_if_fail (GVN_IS_PARAM (param));
SqlExpr * value = sql_value_new ();
sql_value_set_param (SQL_VALUE (value), param);
sql_object_add_held_object (SQL_OBJECT (obj), id, SQL_OBJECT (value));
g_object_unref (value);
}
/**
* sql_string_add_value:
* @obj: the #SqlString
* @id: the id assigned to the item
**/
void sql_string_add_value (SqlString * obj, const gchar * id, GType type, gpointer content)
{
g_return_if_fail (SQL_IS_STRING (obj));
GValue gvalue = {0};
SqlExpr * value;
gvn_value_new_with_content (&gvalue, type, content);
value = sql_value_new ();
sql_value_set_value (SQL_VALUE (value), &gvalue);
sql_object_add_held_object (SQL_OBJECT (obj), id, SQL_OBJECT (value));
g_object_unref (value);
g_value_unset (&gvalue);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Properties
enum
@ -122,7 +84,7 @@ static void sql_string_set_property (SqlString * obj, guint id,
obj->sql = g_value_dup_string (value);
if (obj->sql)
for (i = obj->sql; ; i++)
for (i = obj->sql; TRUE; i++)
{
switch (*i)
{
@ -141,7 +103,7 @@ static void sql_string_set_property (SqlString * obj, guint id,
obj->holders = g_slist_prepend (obj->holders, holder_data);
holder_id = g_strndup (ptr, i - ptr);
holder_data->holder = sql_holder_new (holder_id);
holder_data->holder = g_object_ref_sink (sql_holder_new (holder_id));
g_free (holder_id);
break;
@ -153,8 +115,12 @@ static void sql_string_set_property (SqlString * obj, guint id,
gchar delimiter = *i;
while (*(++i) != delimiter)
{
if (*i == '\\')
i++;
if (*i == '\0')
break;
}
break;
}

View File

@ -21,7 +21,6 @@
#include <gvn/gvn-param.h>
#include <gvn/gvn-value.h>
#include "sql-stmt.h"
#include "sql-value.h"
#define SQL_TYPE_STRING (sql_string_get_type ())
#define SQL_IS_STRING(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, SQL_TYPE_STRING))
@ -48,8 +47,6 @@ struct _SqlStringClass
};
GType sql_string_get_type ();
SqlString * sql_string_new (const gchar * sql);
void sql_string_add_param (SqlString * obj, const gchar * id, GvnParam * param);
void sql_string_add_value (SqlString * obj, const gchar * id, GType type, gpointer content);
SqlObject * sql_string_new (const gchar * sql);
#endif

View File

@ -27,7 +27,7 @@
**/
G_DEFINE_TYPE (SqlSubquery, sql_subquery, SQL_TYPE_TARGET);
SqlSubquery * sql_subquery_new (SqlSelect * select)
SqlObject * sql_subquery_new (SqlSelect * select)
{
return g_object_new (SQL_TYPE_SUBQUERY, "select", select, NULL);
}

View File

@ -41,7 +41,7 @@ struct _SqlSubqueryClass
};
GType sql_subquery_get_type ();
SqlSubquery * sql_subquery_new (SqlSelect * select);
SqlObject * sql_subquery_new (SqlSelect * select);
void sql_subquery_set_select (SqlSubquery * obj, SqlSelect * select);
#endif

View File

@ -24,7 +24,7 @@
**/
G_DEFINE_TYPE (SqlUpdateSet, sql_update_set, SQL_TYPE_OBJECT);
SqlUpdateSet * sql_update_set_new ()
SqlObject * sql_update_set_new ()
{
return g_object_new (SQL_TYPE_UPDATE_SET, NULL);
}

View File

@ -43,6 +43,6 @@ struct _SqlUpdateSetClass
};
GType sql_update_set_get_type ();
SqlUpdateSet * sql_update_set_new ();
SqlObject * sql_update_set_new ();
#endif

View File

@ -112,6 +112,6 @@ static void sql_update_class_init (SqlUpdateClass * klass)
,"Sets"
,"A list of sets"
,SQL_TYPE_UPDATE_SET
,G_PARAM_READWRITE
,G_PARAM_READWRITE | G_PARAM_CONSTRUCT
));
}

View File

@ -111,7 +111,7 @@ static gboolean sql_value_is_ready (SqlValue * obj)
return !gvn_value_is_null (obj->value);
}
static void sql_value_set_real_value (SqlValue * obj, const GValue * value)
static void sql_value_put_value (SqlValue * obj, const GValue * value)
{
if (gvn_value_ccopy (value, obj->value))
g_signal_emit_by_name (obj, "changed");
@ -119,7 +119,7 @@ static void sql_value_set_real_value (SqlValue * obj, const GValue * value)
static void sql_value_cb_value_changed (GvnParam * param, const GValue * value, SqlValue * obj)
{
sql_value_set_real_value (obj, value);
sql_value_put_value (obj, value);
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++ Public
@ -136,7 +136,7 @@ void sql_value_set_value (SqlValue * obj, const GValue * value)
g_return_if_fail (SQL_IS_VALUE (obj));
g_return_if_fail (!obj->param);
sql_value_set_real_value (obj, value);
sql_value_put_value (obj, value);
}
void sql_value_set_param (SqlValue * obj, GvnParam * param)
@ -155,7 +155,7 @@ void sql_value_set_param (SqlValue * obj, GvnParam * param)
obj->param = g_object_ref_sink (param);
g_signal_connect (param, "value-changed",
G_CALLBACK (sql_value_cb_value_changed), obj);
sql_value_set_real_value (obj, gvn_param_get_value (param));
sql_value_put_value (obj, gvn_param_get_value (param));
}
}

View File

@ -22,6 +22,7 @@
#include "sql-object.h"
#include "sql-holder.h"
#include "sql-list.h"
#include "sql-batch.h"
#include "sql-set.h"
#include "sql-string.h"
#include "sql-stmt.h"