From 67bd1ad79c2767455da0457db379bf9ccc656474 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 14 Oct 2013 13:59:07 +0200 Subject: [PATCH] Actualizado con los ultimos cambios locales del proyecto subversion --- module/data/users.glade | 5 ++-- module/src/vn-users.c | 16 ++++++----- sql/Makefile.am | 2 ++ sql/parser/gram.y | 53 +++++++----------------------------- sql/sql-delete.h | 4 +-- sql/sql-dml.c | 2 +- sql/sql-dml.h | 6 ++--- sql/sql-function.c | 12 +++------ sql/sql-function.h | 2 +- sql/sql-holder.c | 6 ++--- sql/sql-holder.h | 2 +- sql/sql-join.c | 2 +- sql/sql-join.h | 2 +- sql/sql-multi-stmt.c | 2 +- sql/sql-multi-stmt.h | 2 +- sql/sql-object.c | 60 ++--------------------------------------- sql/sql-object.h | 5 ---- sql/sql-operation.c | 2 +- sql/sql-render.c | 34 +++++++++-------------- sql/sql-select-field.c | 2 +- sql/sql-select-field.h | 4 +-- sql/sql-select-order.c | 2 +- sql/sql-select-order.h | 6 ++--- sql/sql-select.c | 9 ++++--- sql/sql-select.h | 9 +++---- sql/sql-set.c | 4 +-- sql/sql-set.h | 2 +- sql/sql-string.c | 50 ++++++---------------------------- sql/sql-string.h | 5 +--- sql/sql-subquery.c | 2 +- sql/sql-subquery.h | 2 +- sql/sql-update-set.c | 2 +- sql/sql-update-set.h | 2 +- sql/sql-update.c | 2 +- sql/sql-value.c | 8 +++--- sql/sql.h | 1 + 36 files changed, 95 insertions(+), 236 deletions(-) diff --git a/module/data/users.glade b/module/data/users.glade index 400bf00..95af7fe 100644 --- a/module/data/users.glade +++ b/module/data/users.glade @@ -3,8 +3,8 @@ - SELECT user_id, group_id, uid, last_change, expire FROM account WHERE #p on-iter + SELECT user_id, group_id, uid, last_change, expire FROM account WHERE #p SELECT mail_alias_id, user_id FROM mail_alias_account WHERE #p @@ -707,6 +707,7 @@ 6 end sip + True False @@ -899,8 +900,8 @@ - SELECT user_id, extension, secret, callerid, callgroup FROM account_sip WHERE #p on-iter + SELECT user_id, extension, secret, callerid, callgroup FROM account_sip WHERE #p 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 diff --git a/module/src/vn-users.c b/module/src/vn-users.c index 8c008ae..9eb2618 100644 --- a/module/src/vn-users.c +++ b/module/src/vn-users.c @@ -77,20 +77,22 @@ 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 - ); + ); } } else diff --git a/sql/Makefile.am b/sql/Makefile.am index 66d2c13..996a978 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -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 \ diff --git a/sql/parser/gram.y b/sql/parser/gram.y index 07fac6e..980b284 100644 --- a/sql/parser/gram.y +++ b/sql/parser/gram.y @@ -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. diff --git a/sql/sql-delete.h b/sql/sql-delete.h index fcb0783..c2ecc72 100644 --- a/sql/sql-delete.h +++ b/sql/sql-delete.h @@ -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 diff --git a/sql/sql-dml.c b/sql/sql-dml.c index 7d61719..bd9055e 100644 --- a/sql/sql-dml.c +++ b/sql/sql-dml.c @@ -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); diff --git a/sql/sql-dml.h b/sql/sql-dml.h index d7c528f..f125877 100644 --- a/sql/sql-dml.h +++ b/sql/sql-dml.h @@ -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 diff --git a/sql/sql-function.c b/sql/sql-function.c index d5c7249..d02a67c 100644 --- a/sql/sql-function.c +++ b/sql/sql-function.c @@ -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 diff --git a/sql/sql-function.h b/sql/sql-function.h index ac4190c..b8262df 100644 --- a/sql/sql-function.h +++ b/sql/sql-function.h @@ -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 diff --git a/sql/sql-holder.c b/sql/sql-holder.c index b3c3fe2..13c3f33 100644 --- a/sql/sql-holder.c +++ b/sql/sql-holder.c @@ -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); @@ -78,7 +78,7 @@ static void sql_holder_set_property (SqlHolder * obj, guint id, g_free (obj->id); obj->id = g_value_dup_string (value); break; - default: + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, id, pspec); } } diff --git a/sql/sql-holder.h b/sql/sql-holder.h index ab18735..c06d849 100644 --- a/sql/sql-holder.h +++ b/sql/sql-holder.h @@ -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 \ No newline at end of file diff --git a/sql/sql-join.c b/sql/sql-join.c index 4836962..69815a2 100644 --- a/sql/sql-join.c +++ b/sql/sql-join.c @@ -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 diff --git a/sql/sql-join.h b/sql/sql-join.h index 91a929c..7e342c4 100644 --- a/sql/sql-join.h +++ b/sql/sql-join.h @@ -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); diff --git a/sql/sql-multi-stmt.c b/sql/sql-multi-stmt.c index 2f7047e..ffcfcf6 100644 --- a/sql/sql-multi-stmt.c +++ b/sql/sql-multi-stmt.c @@ -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); } diff --git a/sql/sql-multi-stmt.h b/sql/sql-multi-stmt.h index 2b544be..1b587c9 100644 --- a/sql/sql-multi-stmt.h +++ b/sql/sql-multi-stmt.h @@ -44,6 +44,6 @@ struct _SqlMultiStmtClass }; GType sql_multi_stmt_get_type (); -SqlMultiStmt * sql_multi_stmt_new (); +SqlObject * sql_multi_stmt_new (); #endif diff --git a/sql/sql-object.c b/sql/sql-object.c index d3363b0..8715a88 100644 --- a/sql/sql-object.c +++ b/sql/sql-object.c @@ -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)); } diff --git a/sql/sql-object.h b/sql/sql-object.h index fc81513..fa4694a 100644 --- a/sql/sql-object.h +++ b/sql/sql-object.h @@ -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); diff --git a/sql/sql-operation.c b/sql/sql-operation.c index b0fa96f..5d735e0 100644 --- a/sql/sql-operation.c +++ b/sql/sql-operation.c @@ -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 )); } diff --git a/sql/sql-render.c b/sql/sql-render.c index ce7dfa9..754e485 100644 --- a/sql/sql-render.c +++ b/sql/sql-render.c @@ -296,32 +296,18 @@ 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: * * **/ void sql_render_add_list (SqlRender * obj, gboolean required, const gchar * token, SqlList * list, const gchar * separator) -{ +{ 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); diff --git a/sql/sql-select-field.c b/sql/sql-select-field.c index f6915d9..14c4b5f 100644 --- a/sql/sql-select-field.c +++ b/sql/sql-select-field.c @@ -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); } diff --git a/sql/sql-select-field.h b/sql/sql-select-field.h index 61ffd7d..465ed64 100644 --- a/sql/sql-select-field.h +++ b/sql/sql-select-field.h @@ -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 diff --git a/sql/sql-select-order.c b/sql/sql-select-order.c index 8735789..027530b 100644 --- a/sql/sql-select-order.c +++ b/sql/sql-select-order.c @@ -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); } diff --git a/sql/sql-select-order.h b/sql/sql-select-order.h index 6454c79..c7bd38f 100644 --- a/sql/sql-select-order.h +++ b/sql/sql-select-order.h @@ -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 diff --git a/sql/sql-select.c b/sql/sql-select.c index dfc4179..096c068 100644 --- a/sql/sql-select.c +++ b/sql/sql-select.c @@ -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 diff --git a/sql/sql-select.h b/sql/sql-select.h index 420deb3..c9f5e28 100644 --- a/sql/sql-select.h +++ b/sql/sql-select.h @@ -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; diff --git a/sql/sql-set.c b/sql/sql-set.c index 521b6fc..e096246 100644 --- a/sql/sql-set.c +++ b/sql/sql-set.c @@ -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 )); } diff --git a/sql/sql-set.h b/sql/sql-set.h index 14419e6..55ca012 100644 --- a/sql/sql-set.h +++ b/sql/sql-set.h @@ -40,6 +40,6 @@ struct _SqlSetClass }; GType sql_set_get_type (); -SqlSet * sql_set_new (); +SqlObject * sql_set_new (); #endif diff --git a/sql/sql-string.c b/sql/sql-string.c index 8d119b1..8dad5fb 100644 --- a/sql/sql-string.c +++ b/sql/sql-string.c @@ -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; } diff --git a/sql/sql-string.h b/sql/sql-string.h index 75193d5..b18a564 100644 --- a/sql/sql-string.h +++ b/sql/sql-string.h @@ -21,7 +21,6 @@ #include #include #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 diff --git a/sql/sql-subquery.c b/sql/sql-subquery.c index c7cdbf0..a12d1ce 100644 --- a/sql/sql-subquery.c +++ b/sql/sql-subquery.c @@ -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); } diff --git a/sql/sql-subquery.h b/sql/sql-subquery.h index 24581fc..cbb8c85 100644 --- a/sql/sql-subquery.h +++ b/sql/sql-subquery.h @@ -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 diff --git a/sql/sql-update-set.c b/sql/sql-update-set.c index 2b204e1..5b00e38 100644 --- a/sql/sql-update-set.c +++ b/sql/sql-update-set.c @@ -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); } diff --git a/sql/sql-update-set.h b/sql/sql-update-set.h index ffa1037..c7fc381 100644 --- a/sql/sql-update-set.h +++ b/sql/sql-update-set.h @@ -43,6 +43,6 @@ struct _SqlUpdateSetClass }; GType sql_update_set_get_type (); -SqlUpdateSet * sql_update_set_new (); +SqlObject * sql_update_set_new (); #endif diff --git a/sql/sql-update.c b/sql/sql-update.c index b582722..b3af9aa 100644 --- a/sql/sql-update.c +++ b/sql/sql-update.c @@ -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 )); } diff --git a/sql/sql-value.c b/sql/sql-value.c index 7940aa5..42267bc 100644 --- a/sql/sql-value.c +++ b/sql/sql-value.c @@ -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)); } } diff --git a/sql/sql.h b/sql/sql.h index 91c5d28..2899b14 100644 --- a/sql/sql.h +++ b/sql/sql.h @@ -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"