diff --git a/db/db-model-private.c b/db/db-model-private.c index b9bd08a..0bd446e 100644 --- a/db/db-model-private.c +++ b/db/db-model-private.c @@ -76,7 +76,7 @@ DbOperation; **/ typedef struct { - DbModel * obj; + DbModel * self; GQueue * operations; SqlList * stmts; } @@ -180,8 +180,6 @@ typedef struct gchar * alias; GSList * pkeys; GHashTable * columns; - GSList * parent_columns; - GSList * child_columns; } TableInfo; @@ -192,8 +190,6 @@ static void table_info_free (TableInfo * table_info) g_free (table_info->alias); g_slist_free (table_info->pkeys); g_hash_table_unref (table_info->columns); - g_slist_free (table_info->parent_columns); - g_slist_free (table_info->child_columns); } //----------------------------------------------- ColumnDef diff --git a/db/db-model.c b/db/db-model.c index c2fdb3c..7d4005d 100644 --- a/db/db-model.c +++ b/db/db-model.c @@ -22,7 +22,7 @@ #include "db-row.h" #include "db-model-private.c" -#define MODEL_NOT_READY(obj) (obj->priv->status != DB_MODEL_STATUS_READY) +#define MODEL_NOT_READY(self) (self->priv->status != DB_MODEL_STATUS_READY) #define VALID_ITER(iter, model) (iter->data && iter->stamp == model->priv->stamp) #define DB_ROW_FIELD(row, field) (&((DbRow *) row)->value[field]) #define DB_ROW_POSITION(row) (((DbRow *) row)->position) @@ -97,7 +97,7 @@ struct _DbModelPrivate typedef struct { - DbModel * obj; + DbModel * self; DbIter * iter; gint col; } @@ -116,6 +116,8 @@ typedef struct { DbModelField * left; DbModelField * right; + Field * master; + Field * slave; } DbJoin; @@ -177,13 +179,13 @@ DbModel * db_model_new_with_file (DbConn * conn, const gchar * file) // Prototypes -static void db_model_on_batch_changed (SqlBatch * batch, DbModel * obj); -static void db_model_set_status (DbModel * obj +static void db_model_on_batch_changed (SqlBatch * batch, DbModel * self); +static void db_model_set_status (DbModel * self ,DbModelStatus status); -static void db_model_clear (DbModel * obj); -static void db_model_free_operation (DbModel * obj +static void db_model_clear (DbModel * self); +static void db_model_free_operation (DbModel * self ,DbOperation * op); -static void db_model_manage_join (DbModel * obj +static void db_model_manage_join (DbModel * self ,DbIter * iter ,gint col); @@ -207,43 +209,43 @@ static guint db_model_signal[LAST_SIGNAL] = {0}; // Default signal handlers -static void db_model_on_line_updated (DbModel * obj, DbIter * iter) +static void db_model_on_line_updated (DbModel * self, DbIter * iter) { - GValue * updated_value = obj->priv->updated_value; + GValue * updated_value = self->priv->updated_value; gint col; if (!updated_value || !G_IS_VALUE (updated_value)) return; - col = obj->priv->updated_col; + col = self->priv->updated_col; gvn_value_ccopy (updated_value, DB_ROW_FIELD (iter->data, col)); - db_model_manage_join (obj, iter, col); + db_model_manage_join (self, iter, col); g_value_unset (updated_value); g_free (updated_value); - obj->priv->updated_value = NULL; + self->priv->updated_value = NULL; } -static void db_model_on_line_deleted (DbModel * obj, gint position) +static void db_model_on_line_deleted (DbModel * self, gint position) { gint r_ind; - for (r_ind = position + 1; r_ind < obj->priv->result->nrows; r_ind++) - DB_ROW_POSITION (g_ptr_array_index (obj->priv->data, (guint) r_ind))--; + for (r_ind = position + 1; r_ind < self->priv->result->nrows; r_ind++) + DB_ROW_POSITION (g_ptr_array_index (self->priv->data, (guint) r_ind))--; - g_ptr_array_remove_index (obj->priv->data, (guint) position); + g_ptr_array_remove_index (self->priv->data, (guint) position); - obj->priv->result->nrows--; + self->priv->result->nrows--; } // External signal handlers -static void db_model_calculate_update_flags (DbModel * obj) +static void db_model_calculate_update_flags (DbModel * self) { gint i; Table table; TableInfo * tinfo; - DbModelPrivate * priv = obj->priv; + DbModelPrivate * priv = self->priv; // Allocates aditional memory when the model is updatable @@ -296,8 +298,6 @@ static void db_model_calculate_update_flags (DbModel * obj) ,(GDestroyNotify) g_array_free ); tinfo->pkeys = NULL; - tinfo->parent_columns = NULL; - tinfo->child_columns = NULL; g_hash_table_insert (priv->tables, table_copy (&table), tinfo); } @@ -348,11 +348,11 @@ static void db_model_calculate_update_flags (DbModel * obj) } } -static void db_model_on_data_ready (DbRequest * request, DbModel * obj) +static void db_model_on_data_ready (DbRequest * request, DbModel * self) { gint i; DbResult * r; - DbModelPrivate * priv = obj->priv; + DbModelPrivate * priv = self->priv; if (priv->request != request) { @@ -371,7 +371,7 @@ static void db_model_on_data_ready (DbRequest * request, DbModel * obj) if (!r->data && !r->column) { db_result_free (r); - db_model_set_status (obj, DB_MODEL_STATUS_CLEAN); + db_model_set_status (self, DB_MODEL_STATUS_CLEAN); } else { @@ -384,25 +384,40 @@ static void db_model_on_data_ready (DbRequest * request, DbModel * obj) g_strdup (priv->column[i].alias), GINT_TO_POINTER (i)); } else - db_model_set_sort_column_id (obj, + db_model_set_sort_column_id (self, priv->old_sort_column_id, priv->old_order); - db_model_calculate_update_flags (obj); + db_model_calculate_update_flags (self); priv->fresh = FALSE; - db_model_set_status (obj, DB_MODEL_STATUS_READY); + db_model_set_status (self, DB_MODEL_STATUS_READY); } } else - db_model_set_status (obj, DB_MODEL_STATUS_ERROR); + db_model_set_status (self, DB_MODEL_STATUS_ERROR); g_clear_object (&priv->request); } -static void db_model_process_insert (DbModel * obj, DbRequest * request, DbRow * row, GError * err) +static void db_model_set_table_fields_null (DbModel * self, TableInfo * tinfo, DbIter * iter) +{ + gint i; + DbModelPrivate * priv = self->priv; + + for (i = 0; i < priv->result->ncols; i++) + if (priv->column_table[i] == tinfo) + { + priv->updated_col = i; + priv->updated_value = + g_value_init (g_new0 (GValue, 1), GVN_TYPE_NULL); + g_signal_emit (self, db_model_signal[LINE_UPDATED], 0, &iter); + } +} + +static void db_model_process_select (DbModel * self, DbRequest * request, DbRow * row, GError * err) { gint i, j; - DbModelPrivate * priv = obj->priv; + DbModelPrivate * priv = self->priv; DbResult * result; DbRow * req_row; DbIter iter; @@ -411,7 +426,7 @@ static void db_model_process_insert (DbModel * obj, DbRequest * request, DbRow * result = db_request_fetch_result (request, &err); - if (!(result && result->data && result->nrows > 0)) + if (!(result && result->data && result->ncols > 0)) goto exit; iter.data = row; @@ -421,7 +436,12 @@ static void db_model_process_insert (DbModel * obj, DbRequest * request, DbRow * table.name = result->column[0].table_alias; table.schema = result->column[0].schema; - if ((tinfo = g_hash_table_lookup (priv->tables, &table))) + tinfo = g_hash_table_lookup (priv->tables, &table); + + if (!tinfo) + goto exit; + + if (result->nrows > 0) for (i = 0; i < result->ncols; i++) { GArray * cols = g_hash_table_lookup (tinfo->columns, result->column[i].name); @@ -438,11 +458,13 @@ static void db_model_process_insert (DbModel * obj, DbRequest * request, DbRow * g_value_copy (new_value, priv->updated_value); priv->updated_col = g_array_index (cols, gint, j); - g_signal_emit (obj, db_model_signal[LINE_UPDATED], 0, &iter); + g_signal_emit (self, db_model_signal[LINE_UPDATED], 0, &iter); } } + else + db_model_set_table_fields_null (self, tinfo, &iter); - exit: +exit: db_result_free (result); } @@ -453,8 +475,8 @@ static void db_model_on_operations_done (DbRequest * request, DbModelRequest * d DbIter iter; DbOperation * op; GError * err = NULL; - DbModel * obj = data->obj; - DbModelPrivate * priv = obj->priv; + DbModel * self = data->self; + DbModelPrivate * priv = self->priv; for (l = data->operations->head; l; l = l->next) { @@ -465,7 +487,7 @@ static void db_model_on_operations_done (DbRequest * request, DbModelRequest * d if (op->type & DB_MODEL_ROW_OP_INSERT && op->type & DB_MODEL_ROW_OP_DELETE) // INSERT + DELETE { - g_signal_emit (obj, + g_signal_emit (self, db_model_signal[LINE_DELETED], 0, DB_ROW_POSITION (op->row)); continue; } @@ -477,24 +499,15 @@ static void db_model_on_operations_done (DbRequest * request, DbModelRequest * d if (op->type & DB_MODEL_ROW_OP_DELETE) // DELETE { - if (priv->partial_delete) - { - for (i = 0; i < priv->result->ncols; i++) - if (priv->column_table[i] == priv->main_table) - { - priv->updated_col = i; - priv->updated_value = - g_value_init (g_new0 (GValue, 1), GVN_TYPE_NULL); - g_signal_emit (obj, db_model_signal[LINE_UPDATED], 0, &iter); - } - } - else - g_signal_emit (obj, + if (!priv->partial_delete) + g_signal_emit (self, db_model_signal[LINE_DELETED], 0, DB_ROW_POSITION (op->row)); + else + db_model_set_table_fields_null (self, priv->main_table, &iter); } else if (op->type & DB_MODEL_ROW_OP_INSERT) // INSERT + SELECT { - db_model_process_insert (obj, request, op->row, err); + db_model_process_select (self, request, op->row, err); } else if (op->type & DB_MODEL_ROW_OP_UPDATE) // UPDATE || INSERT + SELECT { @@ -510,10 +523,10 @@ static void db_model_on_operations_done (DbRequest * request, DbModelRequest * d db_request_fetch_non_select (request, &err); if (G_OBJECT_TYPE (sql_list_get (list, j)) == SQL_TYPE_MULTI_STMT) - db_model_process_insert (obj, request, op->row, err); + db_model_process_select (self, request, op->row, err); } - g_signal_emit (obj, db_model_signal[LINE_UPDATED], 0, &iter); + g_signal_emit (self, db_model_signal[LINE_UPDATED], 0, &iter); } i++; @@ -529,97 +542,54 @@ static void db_model_on_operations_done (DbRequest * request, DbModelRequest * d if (!err) { while ((op = g_queue_pop_head (data->operations))) - db_model_free_operation (obj, op); + db_model_free_operation (self, op); - g_signal_emit (obj, db_model_signal[OPERATIONS_DONE], 0); + g_signal_emit (self, db_model_signal[OPERATIONS_DONE], 0); } } -static void db_model_on_stmt_changed (SqlStmt * stmt, DbModel * obj) +static void db_model_on_stmt_changed (SqlStmt * stmt, DbModel * self) { - obj->priv->fresh = TRUE; - db_model_refresh (obj); + self->priv->fresh = TRUE; + db_model_refresh (self); } -static void db_model_on_batch_changed (SqlBatch * batch, DbModel * obj) +static void db_model_on_batch_changed (SqlBatch * batch, DbModel * self) { - db_model_refresh (obj); + db_model_refresh (self); } static void db_model_on_join_query_done (DbRequest * request, JoinData * join_data) { - gint i, j; - DbResult * r; - DbIter * iter = join_data->iter; - GError * err = NULL; - DbModel * obj = join_data->obj; - DbModelPrivate * priv = obj->priv; - - while ((r = db_request_fetch_result (request, &err))) - { - for (i = 0; i < priv->result->ncols; i++) - for (j = 0; j < r->ncols; j++) - if (!g_strcmp0 (r->column[j].name, priv->column[i].name) - && !g_strcmp0 (r->column[j].table, priv->column[i].table) - && !g_strcmp0 (r->column[j].schema, priv->column[i].schema)) - { - if (r->nrows > 0) - { - GValue * new_value = - DB_ROW_FIELD (g_ptr_array_index (r->data, 0), j); - - priv->updated_value = g_new0 (GValue, 1); - g_value_init (priv->updated_value, G_VALUE_TYPE (new_value)); - gvn_value_copy (new_value, priv->updated_value); - } - else - priv->updated_value = - g_value_init (g_new0 (GValue, 1), GVN_TYPE_NULL); - - priv->updated_col = i; - g_signal_emit (obj, db_model_signal[LINE_UPDATED], 0, iter); - } - - db_result_free (r); - } - - if (err) - { - g_message ("%s", err->message); - g_error_free (err); - } - - priv->pending_request = - g_slist_remove (obj->priv->pending_request, request); - g_object_unref (request); + // db_model_process_select (self, request, row, err); } // Private helper methods and functions static void join_data_free (JoinData * join_data) { - g_object_unref (join_data->obj); + g_object_unref (join_data->self); db_iter_free (join_data->iter); g_free (join_data); } -static void db_model_free_operation (DbModel * obj, DbOperation * op) +static void db_model_free_operation (DbModel * self, DbOperation * op) { if (op->updated) g_slist_free_full (op->updated, (GDestroyNotify) db_updated_field_free); - g_hash_table_remove (obj->priv->row_ops, op->row); + g_hash_table_remove (self->priv->row_ops, op->row); g_free (op); } -static void db_model_clean_operations (DbModel * obj) +static void db_model_clean_operations (DbModel * self) { DbOperation * op; - DbModelPrivate * priv = obj->priv; + DbModelPrivate * priv = self->priv; while ((op = g_queue_pop_head (priv->operation))) - db_model_free_operation (obj, op); + db_model_free_operation (self, op); } static void db_model_request_free (DbModelRequest * req) @@ -631,11 +601,11 @@ static void db_model_request_free (DbModelRequest * req) while ((op = g_queue_pop_head (req->operations))) { op->locked = FALSE; - g_queue_push_tail (req->obj->priv->operation, op); + g_queue_push_tail (req->self->priv->operation, op); } g_queue_free (req->operations); - g_object_unref (req->obj); + g_object_unref (req->self); g_object_unref (req->stmts); } @@ -652,18 +622,19 @@ static void db_operation_add_updated (DbOperation * op, gint col) return; u = g_new (DbUpdatedField, 1); - gvn_value_copy (DB_ROW_FIELD (op->row, col) - ,g_value_init (u->value = g_new0 (GValue, 1) - ,G_VALUE_TYPE (DB_ROW_FIELD (op->row, col)))); u->column = col; + u->value = g_value_init (g_new0 (GValue, 1) + ,G_VALUE_TYPE (DB_ROW_FIELD (op->row, col))); + g_value_copy (DB_ROW_FIELD (op->row, col), u->value); + op->type |= DB_MODEL_ROW_OP_UPDATE; op->updated = g_slist_prepend (op->updated, u); } -static gboolean db_model_set_row_operation (DbModel * obj, +static gboolean db_model_set_row_operation (DbModel * self, DbRow * row, DbModelRowOp type, gint col) { - DbOperation * op = g_hash_table_lookup (obj->priv->row_ops, row); + DbOperation * op = g_hash_table_lookup (self->priv->row_ops, row); if (!op) { @@ -676,8 +647,8 @@ static gboolean db_model_set_row_operation (DbModel * obj, if (type & DB_MODEL_ROW_OP_UPDATE) db_operation_add_updated (new_op, col); - g_hash_table_insert (obj->priv->row_ops, row, new_op); - g_queue_push_tail (obj->priv->operation, new_op); + g_hash_table_insert (self->priv->row_ops, row, new_op); + g_queue_push_tail (self->priv->operation, new_op); } else if (!op->locked) { @@ -693,12 +664,12 @@ static gboolean db_model_set_row_operation (DbModel * obj, return TRUE; } -void db_model_reverse_operations (DbModel * obj) +void db_model_reverse_operations (DbModel * self) { - DbModelPrivate * priv = obj->priv; + DbModelPrivate * priv = self->priv; DbOperation * op; - g_return_if_fail (DB_IS_MODEL (obj)); + g_return_if_fail (DB_IS_MODEL (self)); while ((op = g_queue_pop_tail (priv->operation))) { @@ -712,15 +683,15 @@ void db_model_reverse_operations (DbModel * obj) { if (op->type & DB_MODEL_ROW_OP_INSERT) { - g_signal_emit (obj, + g_signal_emit (self, db_model_signal[LINE_DELETED], 0, DB_ROW_POSITION (op->row)); } else - g_signal_emit (obj, db_model_signal[LINE_TOGGLED], 0, &iter); + g_signal_emit (self, db_model_signal[LINE_TOGGLED], 0, &iter); } else if (op->type & DB_MODEL_ROW_OP_INSERT) { - g_signal_emit (obj, + g_signal_emit (self, db_model_signal[LINE_DELETED], 0, DB_ROW_POSITION (op->row)); } else if (op->type & DB_MODEL_ROW_OP_UPDATE) @@ -733,14 +704,14 @@ void db_model_reverse_operations (DbModel * obj) priv->updated_value = g_new0 (GValue, 1); g_value_init (priv->updated_value, G_VALUE_TYPE (u->value)); - gvn_value_copy (u->value, priv->updated_value); + g_value_copy (u->value, priv->updated_value); priv->updated_col = u->column; - g_signal_emit (obj, db_model_signal[LINE_UPDATED], 0, &iter); + g_signal_emit (self, db_model_signal[LINE_UPDATED], 0, &iter); } } - db_model_free_operation (obj, op); + db_model_free_operation (self, op); } } @@ -833,29 +804,29 @@ static gint db_model_valcmp_desc (gpointer * a, gpointer * b, gpointer col) } -static void db_model_set_status (DbModel * obj, DbModelStatus status) +static void db_model_set_status (DbModel * self, DbModelStatus status) { - obj->priv->status = status; - g_signal_emit (obj, db_model_signal[STATUS_CHANGED], 0, status); + self->priv->status = status; + g_signal_emit (self, db_model_signal[STATUS_CHANGED], 0, status); } -static void db_model_cancel_pending_requests (DbModel * obj) +static void db_model_cancel_pending_requests (DbModel * self) { GSList * n; - for (n = obj->priv->pending_request; n; n = n->next) + for (n = self->priv->pending_request; n; n = n->next) db_request_cancel (n->data); } -static void db_model_add_pending_request (DbModel * obj, DbRequest * request) +static void db_model_add_pending_request (DbModel * self, DbRequest * request) { - obj->priv->pending_request = g_slist_prepend (obj->priv->pending_request, + self->priv->pending_request = g_slist_prepend (self->priv->pending_request, request); } -static void db_model_clear (DbModel * obj) +static void db_model_clear (DbModel * self) { - DbModelPrivate * priv = obj->priv; + DbModelPrivate * priv = self->priv; if (priv->request) { @@ -864,8 +835,8 @@ static void db_model_clear (DbModel * obj) } else if (priv->result) { - db_model_clean_operations (obj); - db_model_cancel_pending_requests (obj); + db_model_clean_operations (self); + db_model_cancel_pending_requests (self); db_result_free (priv->result); priv->result = NULL; @@ -884,9 +855,9 @@ static void db_model_clear (DbModel * obj) // Join related functions -static void db_model_manage_join (DbModel * obj, DbIter * iter, gint col) +static void db_model_manage_join (DbModel * self, DbIter * iter, gint col) { - DbModelPrivate * priv = obj->priv; + DbModelPrivate * priv = self->priv; if (priv->join && gvn_param_spec_get_editable (priv->column[col].spec) @@ -897,18 +868,6 @@ static void db_model_manage_join (DbModel * obj, DbIter * iter, gint col) gboolean send_request = FALSE, end = FALSE; SqlList * stmts = g_object_ref_sink (sql_list_new (SQL_TYPE_MULTI_STMT)); -// FIXME -// for (i = 0; i < obj->ncols; i++) -// // Check for multi-field pkeys to be fully set -// // need to know the total number of pkey fields -// if (i != col && obj->column[i].info & DB_COLUMN_PRI_KEY -// && gvn_value_is_null (DB_ROW_FIELD (iter->data, i)) -// && !g_strcmp0 (obj->column[i].table, obj->column[col].table)) -// { -// end = TRUE; -// break; -// } - if (!end) for (n = priv->join; n; n = n->next) { @@ -981,7 +940,7 @@ static void db_model_manage_join (DbModel * obj, DbIter * iter, gint col) DbRequest * request; join_data = g_new (JoinData, 1); - join_data->obj = g_object_ref (obj); + join_data->self = g_object_ref (self); join_data->iter = db_iter_copy (iter); join_data->col = col; @@ -992,7 +951,7 @@ static void db_model_manage_join (DbModel * obj, DbIter * iter, gint col) ,join_data ,(GDestroyNotify) join_data_free ); - db_model_add_pending_request (obj, request); + db_model_add_pending_request (self, request); } g_object_unref (stmts); @@ -1037,12 +996,12 @@ static void db_join_free (DbJoin * join) g_free (join); } -static void db_model_calculate_col_def (DbModel * obj, SqlJoin * join, +static void db_model_calculate_col_def (DbModel * self, SqlJoin * join, SqlField * l_field, SqlField * r_field) { gint i, col = -1; gchar * dst = NULL; - DbModelPrivate * priv = obj->priv; + DbModelPrivate * priv = self->priv; SqlField * f = NULL; SqlTarget * l_table = join->target_left, * r_table = join->target_right; @@ -1090,10 +1049,10 @@ static void db_model_calculate_col_def (DbModel * obj, SqlJoin * join, } if (f) - db_model_set_default_value_from_column (obj, dst, col); + db_model_set_default_value_from_column (self, dst, col); } -static void db_model_set_join_fields (DbModel * obj, SqlJoin * join, +static void db_model_set_join_fields (DbModel * self, SqlJoin * join, SqlField * lsql_field, SqlField * rsql_field, DbModelField * lfield, DbModelField * rfield) { @@ -1113,119 +1072,7 @@ static void db_model_set_join_fields (DbModel * obj, SqlJoin * join, g_strdup (check ? rsql_field->name : lsql_field->name)); } -static void db_model_post_process_query (DbModel * obj) -{ -// TODO When parser gets fully functional, these 3 lines won't be needed, -// because obj->stmt will be a parsed stmt: - gchar * rend = db_conn_render (obj->priv->conn, obj->priv->stmt, obj->priv->batch, NULL); - SqlObject * stmt = sql_parser_parse (rend); - - g_free (rend); - - if (stmt && SQL_IS_SELECT (stmt)) - { - DbModelField * lfield, * rfield; - SqlJoin * join; - GList * n; - SqlSelect * select = SQL_SELECT (stmt); - gboolean calculate_join = FALSE; - - for (n = sql_list_get_items (SQL_DML (select)->targets); n; n = n->next) - if ((join = n->data) - && SQL_IS_JOIN (join) - && SQL_IS_TABLE (join->target_left) - && SQL_IS_TABLE (join->target_right) - && SQL_IS_OPERATION (join->condition)) - { -// DbJoin and ColDef creation - GList * operators; - SqlOperation * op = SQL_OPERATION (join->condition); - SqlField * lsql_field = NULL, * rsql_field = NULL; - - lfield = db_model_field_new (SQL_TABLE (join->target_left)->name, NULL); - rfield = db_model_field_new (SQL_TABLE (join->target_right)->name, NULL); - - if (join->type == SQL_JOIN_TYPE_RIGHT) - rfield->main = TRUE; - else - lfield->main = TRUE; - - if (op->type == SQL_OPERATION_TYPE_AND) - { - GList * l; - - for (l = sql_list_get_items (op->operators); l; l = l->next) - { - SqlOperation * subop = l->data; - operators = sql_list_get_items (subop->operators); - - if (SQL_IS_OPERATION (subop) - && subop->type == SQL_OPERATION_TYPE_EQUAL - && operators->data // Left Field - && operators->next && operators->next->data) // Right Field - { - lsql_field = SQL_FIELD (operators->data); - rsql_field = SQL_FIELD (operators->next->data); - - db_model_set_join_fields (obj, join, - lsql_field, rsql_field, lfield, rfield); - - calculate_join = TRUE; - - if (join->type != SQL_JOIN_TYPE_INNER) - db_model_calculate_col_def - (obj, join, lsql_field, rsql_field); - } - else - { - calculate_join = FALSE; - break; - } - } - } - else - { - operators = sql_list_get_items (op->operators); - - if (op->type == SQL_OPERATION_TYPE_EQUAL && operators->data - && operators->next && operators->next->data) - { - lsql_field = SQL_FIELD (operators->data); - rsql_field = SQL_FIELD (operators->next->data); - - db_model_set_join_fields (obj, join, - lsql_field, rsql_field, lfield, rfield); - - calculate_join = TRUE; - - if (join->type != SQL_JOIN_TYPE_INNER) - db_model_calculate_col_def - (obj, join ,lsql_field, rsql_field); - } - } - - if (calculate_join) - { - DbJoin * join_res = g_new (DbJoin, 1); - join_res->left = lfield; - join_res->right = rfield; - - obj->priv->join = g_slist_prepend (obj->priv->join, join_res); - } - else - { - db_model_field_free (lfield); - db_model_field_free (rfield); - } - } - } - - if (G_IS_OBJECT (stmt)) - g_object_unref (stmt); - -} - -static gboolean db_model_analyse_join_op (DbModel * obj, SqlOperation * op) +static gboolean db_model_analyse_join_op (DbModel * self, SqlOperation * op) { gint i; gint noperands; @@ -1250,7 +1097,7 @@ static gboolean db_model_analyse_join_op (DbModel * obj, SqlOperation * op) else if (operator == SQL_OPERATION_TYPE_AND) { for (i = 0; i < noperands; i++) - if (!db_model_analyse_join_op (obj, sql_list_get (operands, i))) + if (!db_model_analyse_join_op (self, sql_list_get (operands, i))) return FALSE; return TRUE; @@ -1259,7 +1106,7 @@ static gboolean db_model_analyse_join_op (DbModel * obj, SqlOperation * op) return FALSE; } -static void db_model_analyse_join (DbModel * obj, SqlTarget * target) +static void db_model_analyse_join (DbModel * self, SqlTarget * target) { SqlJoin * join; SqlTarget * left; @@ -1278,7 +1125,7 @@ static void db_model_analyse_join (DbModel * obj, SqlTarget * target) ); if (SQL_IS_TABLE (left) || SQL_IS_TABLE (right)) - db_model_analyse_join_op (obj, on); + db_model_analyse_join_op (self, on); switch ((gint) sql_join_get_join_type (join)) { @@ -1290,18 +1137,18 @@ static void db_model_analyse_join (DbModel * obj, SqlTarget * target) break; } - db_model_analyse_join (obj, left); - db_model_analyse_join (obj, right); + db_model_analyse_join (self, left); + db_model_analyse_join (self, right); } -static void db_model_load_join (DbModel * obj) +static void db_model_load_join (DbModel * self) { gchar * sql; SqlObject * stmt; SqlObject * select; - DbModelPrivate * priv = obj->priv; + DbModelPrivate * priv = self->priv; - sql = db_conn_render (obj->priv->conn, obj->priv->stmt, NULL, NULL); + sql = db_conn_render (self->priv->conn, self->priv->stmt, NULL, NULL); stmt = sql_parser_parse (sql); g_free (sql); @@ -1328,7 +1175,7 @@ static void db_model_load_join (DbModel * obj) g_object_get (select, "targets", &targets, NULL); for (i = 0; i < sql_list_length (targets); i++) - db_model_analyse_join (obj, sql_list_get (targets, i)); + db_model_analyse_join (self, sql_list_get (targets, i)); exit: g_object_unref (stmt); @@ -1340,23 +1187,23 @@ static void db_model_load_join (DbModel * obj) /** * db_model_set_conn: - * @obj: a #DbModel + * @self: a #DbModel * @conn: (allow-none): a #DbConn * * Sets the connection through which the communication is established with * the database. **/ -void db_model_set_conn (DbModel * obj, DbConn * conn) +void db_model_set_conn (DbModel * self, DbConn * conn) { - g_return_if_fail (DB_IS_MODEL (obj)); + g_return_if_fail (DB_IS_MODEL (self)); g_return_if_fail (DB_IS_CONN (conn) || !conn); if (conn) { - if (!obj->priv->conn) + if (!self->priv->conn) { - obj->priv->conn = g_object_ref (conn); - db_model_on_stmt_changed (obj->priv->stmt, obj); + self->priv->conn = g_object_ref (conn); + db_model_on_stmt_changed (self->priv->stmt, self); } else g_warning ("DbModel: The connection can only be set once"); @@ -1365,298 +1212,302 @@ void db_model_set_conn (DbModel * obj, DbConn * conn) /** * db_model_get_conn: - * @obj: a #DbModel + * @self: a #DbModel * * Returns the connection through which the communication is established with * the database. * * Return value: (transfer none): the #DbConn of the model **/ -DbConn * db_model_get_conn (DbModel * obj) +DbConn * db_model_get_conn (DbModel * self) { - g_return_val_if_fail (DB_IS_MODEL (obj), NULL); + g_return_val_if_fail (DB_IS_MODEL (self), NULL); - return obj->priv->conn; + return self->priv->conn; } /** * db_model_get_spec: - * @obj: a #DbModel - * @col: the number of a column of @obj + * @self: a #DbModel + * @col: the number of a column of @self * - * Returns the #GvnParamSpec of a field in the position @col of @obj. + * Returns the #GvnParamSpec of a field in the position @col of @self. * * Return value: (transfer none): the #GvnParamSpec of the column with number @col **/ -const GvnParamSpec * db_model_get_spec (DbModel * obj, gint col) +const GvnParamSpec * db_model_get_spec (DbModel * self, gint col) { - g_return_val_if_fail (DB_IS_MODEL (obj), NULL); + g_return_val_if_fail (DB_IS_MODEL (self), NULL); - if ((obj->priv->result && 0 <= col - && col < obj->priv->result->ncols) - && obj->priv->column) - return obj->priv->column[col].spec; + if ((self->priv->result && 0 <= col + && col < self->priv->result->ncols) + && self->priv->column) + return self->priv->column[col].spec; return NULL; } /** * db_model_get_column_name: - * @obj: a #DbModel - * @col: the number of a column of @obj + * @self: a #DbModel + * @col: the number of a column of @self * - * Retrieves the name of a field in the position @col of @obj. + * Retrieves the name of a field in the position @col of @self. * * Return value: the name of the column with number @col **/ -const gchar * db_model_get_column_name (DbModel * obj, gint col) +const gchar * db_model_get_column_name (DbModel * self, gint col) { - g_return_val_if_fail (DB_IS_MODEL (obj), NULL); + g_return_val_if_fail (DB_IS_MODEL (self), NULL); - if ((obj->priv->result + if ((self->priv->result && 0 <= col - && col < obj->priv->result->ncols) - && obj->priv->column) - return obj->priv->column[col].alias; + && col < self->priv->result->ncols) + && self->priv->column) + return self->priv->column[col].alias; return NULL; } /** * db_model_get_column_index: - * @obj: a #DbModel - * @name: the name of a column of @obj + * @self: a #DbModel + * @name: the name of a column of @self * * Retrieves the position in the query of the column called @name. * * Return value: the index of the column with name @name or -1 if there isn't * a column called @name or if @name is NULL **/ -gint db_model_get_column_index (DbModel * obj, const gchar * name) +gint db_model_get_column_index (DbModel * self, const gchar * name) { - g_return_val_if_fail (DB_IS_MODEL (obj), -1); + g_return_val_if_fail (DB_IS_MODEL (self), -1); - if (!name || !obj->priv->column_index) + if (!name || !self->priv->column_index) return -1; - return GPOINTER_TO_INT (g_hash_table_lookup (obj->priv->column_index, name)); + return GPOINTER_TO_INT (g_hash_table_lookup (self->priv->column_index, name)); } /** * db_model_get_status: - * @obj: a #DbModel + * @self: a #DbModel * - * Returns the current #DbModelStatus of @obj. + * Returns the current #DbModelStatus of @self. * - * Return value: the status of @obj + * Return value: the status of @self **/ -DbModelStatus db_model_get_status (DbModel * obj) +DbModelStatus db_model_get_status (DbModel * self) { - g_return_val_if_fail (DB_IS_MODEL (obj), -1); - return obj->priv->status; + g_return_val_if_fail (DB_IS_MODEL (self), -1); + return self->priv->status; } /** * db_model_get_mode: - * @obj: a #DbModel + * @self: a #DbModel * - * Retrieves the current working mode of @obj. See #DbModelMode. + * Retrieves the current working mode of @self. See #DbModelMode. * * Return value: the current mode **/ -DbModelMode db_model_get_mode (DbModel * obj) +DbModelMode db_model_get_mode (DbModel * self) { - g_return_val_if_fail (DB_IS_MODEL (obj), -1); - return (obj->priv->mode); + g_return_val_if_fail (DB_IS_MODEL (self), -1); + return (self->priv->mode); } /** * db_model_set_mode: - * @obj: a #DbModel + * @self: a #DbModel * @mode: a #DbModelMode to set the model on * - * Sets the working mode of @obj to @mode. See #DbModelMode. + * Sets the working mode of @self to @mode. See #DbModelMode. **/ -void db_model_set_mode (DbModel * obj, DbModelMode mode) +void db_model_set_mode (DbModel * self, DbModelMode mode) { - g_return_if_fail (DB_IS_MODEL (obj)); - obj->priv->mode = mode; + g_return_if_fail (DB_IS_MODEL (self)); + self->priv->mode = mode; } /** * db_model_toggle_mode: - * @obj: a #DbModel + * @self: a #DbModel * - * Toogles the working mode of @obj. See #DbModelMode to see the two possible + * Toogles the working mode of @self. See #DbModelMode to see the two possible * modes. **/ -void db_model_toggle_mode (DbModel * obj) +void db_model_toggle_mode (DbModel * self) { - g_return_if_fail (DB_IS_MODEL (obj)); + g_return_if_fail (DB_IS_MODEL (self)); - obj->priv->mode = (obj->priv->mode == DB_MODEL_MODE_ON_DEMAND)? + self->priv->mode = (self->priv->mode == DB_MODEL_MODE_ON_DEMAND)? DB_MODEL_MODE_ON_CHANGE: DB_MODEL_MODE_ON_DEMAND; } /** * db_model_set_result_pos: - * @obj: a #DbModel + * @self: a #DbModel * @pos: position of the query * * Sets the position where the query that will fill @model with data will be * placed in a multi-query statement. **/ -void db_model_set_result_pos (DbModel * obj, guint pos) +void db_model_set_result_pos (DbModel * self, guint pos) { - g_return_if_fail (DB_IS_MODEL (obj)); + g_return_if_fail (DB_IS_MODEL (self)); - obj->priv->result_pos = pos; + self->priv->result_pos = pos; } /** * db_model_get_update_flags: - * @obj: a #DbModel + * @self: a #DbModel * - * Retrieves the update flags of @obj. See #DbModelUpdateFlags for the details + * Retrieves the update flags of @self. See #DbModelUpdateFlags for the details * of those flags. See also db_model_request_update_flags(). * - * Return value: the #DbModelUpdateFlags of @obj + * Return value: the #DbModelUpdateFlags of @self **/ -DbModelUpdateFlags db_model_get_update_flags (DbModel * obj) +DbModelUpdateFlags db_model_get_update_flags (DbModel * self) { - g_return_val_if_fail (DB_IS_MODEL (obj), FALSE); + g_return_val_if_fail (DB_IS_MODEL (self), FALSE); - return obj->priv->update_flags; + return self->priv->update_flags; } /** * db_model_request_update_flags: - * @obj: a #DbModel - * @flags: the set of #DbModelUpdateFlags to be set to @obj + * @self: a #DbModel + * @flags: the set of #DbModelUpdateFlags to be set to @self * - * Requests the update flags of @obj. See #DbModelUpdateFlags for the details - * of those flags. If @obj does not allow an operation by itself, it will + * Requests the update flags of @self. See #DbModelUpdateFlags for the details + * of those flags. If @self does not allow an operation by itself, it will * log a warning when trying to set this operation. If the flag set is * #DB_MODEL_UPDATE it may not log until trying to update a non-updatable * field, see db_model_set_value(). See also db_model_get_update_flags() and * db_model_unset_update_flags(). **/ -void db_model_request_update_flags (DbModel * obj, DbModelUpdateFlags flags) +void db_model_request_update_flags (DbModel * self, DbModelUpdateFlags flags) { - g_return_if_fail (DB_IS_MODEL (obj)); + g_return_if_fail (DB_IS_MODEL (self)); - obj->priv->user_update_flags = flags; - db_model_calculate_update_flags (obj); + self->priv->user_update_flags = flags; + db_model_calculate_update_flags (self); } /** * db_model_unset_update_flags: - * @obj: a #DbModel - * @flags: the set of #DbModelUpdateFlags to be unset in @obj + * @self: a #DbModel + * @flags: the set of #DbModelUpdateFlags to be unset in @self * - * Unsets the update flags of @obj. See #DbModelUpdateFlags for the details + * Unsets the update flags of @self. See #DbModelUpdateFlags for the details * of those flags. See also db_model_get_update_flags() and * db_model_request_update_flags(). **/ -void db_model_unset_update_flags (DbModel * obj, DbModelUpdateFlags flags) +void db_model_unset_update_flags (DbModel * self, DbModelUpdateFlags flags) { - g_return_if_fail (DB_IS_MODEL (obj)); + g_return_if_fail (DB_IS_MODEL (self)); - obj->priv->user_update_flags &= ~flags; - db_model_calculate_update_flags (obj); + self->priv->user_update_flags &= ~flags; + db_model_calculate_update_flags (self); } /** * db_model_get_last: - * @obj: a @DbModel + * @self: a @DbModel * @iter: (out): an unitialized #DbIter * - * Points @iter to the last row of @obj. + * Points @iter to the last row of @self. * - * Return value: %FALSE if @obj is a valid #DbModel, %TRUE otherwise + * Return value: %FALSE if @self is a valid #DbModel, %TRUE otherwise **/ -gboolean db_model_get_last (DbModel * obj, DbIter * iter) +gboolean db_model_get_last (DbModel * self, DbIter * iter) { - g_return_val_if_fail (DB_IS_MODEL (obj), FALSE); + g_return_val_if_fail (DB_IS_MODEL (self), FALSE); iter->data = g_ptr_array_index - (obj->priv->data, (guint) obj->priv->data->len - 1); - iter->stamp = obj->priv->stamp; + (self->priv->data, (guint) self->priv->data->len - 1); + iter->stamp = self->priv->stamp; return TRUE; } /** - * db_model_add_join_columns: - * @obj: a #DbModel - * @left: the field on the left of the join - * @right: the field on the right of the join + * db_model_add_join: + * @self: a #DbModel + * @master_field: the field on the left of the join + * @slave_field: the field on the right of the join * * Sets the binding betwen two joined fields. This will generate a SELECT query * to the database to change the corresponding values in the model. Currently * it's used by the internal parser. **/ -void db_model_add_join_columns (DbModel * obj, const gchar * left, const gchar * right) +void db_model_add_join (DbModel * self, + const gchar * master_field, const gchar * slave_field) { - g_return_if_fail (DB_IS_MODEL (obj)); + DbJoin * join; - DbJoin * join = g_new (DbJoin, 1); -// join->left = db_model_field_new_from_string (left); -// join->right = db_model_field_new_from_string (right); - - obj->priv->join = g_slist_prepend (obj->priv->join, join); + g_return_if_fail (DB_IS_MODEL (self)); + g_return_if_fail (master_field); + g_return_if_fail (slave_field); + + join = g_new (DbJoin, 1); + join->master = field_new_from_string (master_field); + join->slave = field_new_from_string (slave_field); + self->priv->join = g_slist_prepend (self->priv->join, join); } /** * db_model_get_batch: - * @obj: a #DbModel + * @self: a #DbModel * @return: the #SqlBatch * * Gets the batch used by the model. **/ -SqlBatch * db_model_get_batch (DbModel * obj) +SqlBatch * db_model_get_batch (DbModel * self) { - return obj->priv->batch; + return self->priv->batch; } /** * db_model_set_batch: - * @obj: a #DbModel + * @self: a #DbModel * @batch: the #SqlBatch * * Sets the batch used by the model. **/ -void db_model_set_batch (DbModel * obj, SqlBatch * batch) +void db_model_set_batch (DbModel * self, SqlBatch * batch) { DbModelPrivate * priv; - g_return_if_fail (DB_IS_MODEL (obj)); + g_return_if_fail (DB_IS_MODEL (self)); g_return_if_fail (SQL_IS_BATCH (batch) || !batch); - priv = obj->priv; + priv = self->priv; if (priv->batch) { g_signal_handlers_disconnect_by_func (priv->batch, - db_model_on_batch_changed, obj); + db_model_on_batch_changed, self); g_object_unref (priv->batch); } if (batch) { g_signal_connect (batch, "changed", - G_CALLBACK (db_model_on_batch_changed), obj); + G_CALLBACK (db_model_on_batch_changed), self); g_object_ref_sink (batch); } priv->batch = batch; } -static ColumnDef * db_model_create_column_def (DbModel * obj, const gchar * field_str) +static ColumnDef * db_model_create_column_def (DbModel * self, const gchar * field_str) { Field * field = field_new_from_string (field_str); if (field->name && field->target && !field->schema) { ColumnDef * def = column_def_new (); - g_hash_table_insert (obj->priv->defaults, field, def); + g_hash_table_insert (self->priv->defaults, field, def); return def; } else @@ -1668,27 +1519,27 @@ static ColumnDef * db_model_create_column_def (DbModel * obj, const gchar * fiel return NULL; } -static void db_model_on_param_changed (GvnParam * param, GValue * value, DbModel * obj) +static void db_model_on_param_changed (GvnParam * param, GValue * value, DbModel * self) { - db_model_refresh (obj); + db_model_refresh (self); } /** * db_model_set_default_value_from_column: - * @obj: a #DbModel + * @self: a #DbModel * @field_str: the field to be set * @column_str: field from wich the value is picked **/ -void db_model_set_default_value_from_column (DbModel * obj, +void db_model_set_default_value_from_column (DbModel * self, const gchar * field_str, const gchar * column_str) { ColumnDef * def; - g_return_if_fail (DB_IS_MODEL (obj)); + g_return_if_fail (DB_IS_MODEL (self)); g_return_if_fail (field_str); g_return_if_fail (column_str); - def = db_model_create_column_def (obj, field_str); + def = db_model_create_column_def (self, field_str); if (def) def->src_column = field_new_from_string (column_str); @@ -1696,23 +1547,23 @@ void db_model_set_default_value_from_column (DbModel * obj, /** * db_model_set_default_value_from_param: - * @obj: a #DbModel + * @self: a #DbModel * @field_str: the field to be set * @param: a #GvnParam * @link: * - * Get the default value for @dst_field from @param. + * Get the default value for @field_str from @param. **/ -void db_model_set_default_value_from_param (DbModel * obj, +void db_model_set_default_value_from_param (DbModel * self, const gchar * field_str, GvnParam * param, gboolean link) { ColumnDef * def; - g_return_if_fail (DB_IS_MODEL (obj)); + g_return_if_fail (DB_IS_MODEL (self)); g_return_if_fail (field_str); g_return_if_fail (GVN_IS_PARAM (param)); - def = db_model_create_column_def (obj, field_str); + def = db_model_create_column_def (self, field_str); if (!def) return; @@ -1721,14 +1572,14 @@ void db_model_set_default_value_from_param (DbModel * obj, if (link) def->link = g_signal_connect (param, "value-changed", - G_CALLBACK (db_model_on_param_changed), obj); + G_CALLBACK (db_model_on_param_changed), self); } /** * db_model_get_main_table: - * @obj: a #DbModel + * @self: a #DbModel * - * Returns the string with the name of the main table of @obj. The main table + * Returns the string with the name of the main table of @self. The main table * is the only table on a #DbModel whose rows can be deleted or inserted. By * default the main table is set to the table the first column field belongs. * To override this behaviour, use @db_model_request_main_table. @@ -1736,83 +1587,83 @@ void db_model_set_default_value_from_param (DbModel * obj, * Note that the requested main table may be different fron the actual main * table used by the model * - * Return value: the name of the main table of @obj + * Return value: the name of the main table of @self **/ -const gchar * db_model_get_main_table (DbModel * obj) +const gchar * db_model_get_main_table (DbModel * self) { - g_return_val_if_fail (DB_IS_MODEL (obj), NULL); + g_return_val_if_fail (DB_IS_MODEL (self), NULL); - if (obj->priv->main_table) - return obj->priv->main_table->name; + if (self->priv->main_table) + return self->priv->main_table->name; return NULL; } /** * db_model_get_stmt: - * @obj: a #DbModel + * @self: a #DbModel * - * Returns the #SqlStmt which queries to the database about the data of @obj. + * Returns the #SqlStmt which queries to the database about the data of @self. * - * Return value: (transfer none): the #SqlStmt property of @obj + * Return value: (transfer none): the #SqlStmt property of @self **/ -const SqlStmt * db_model_get_stmt (DbModel * obj) +const SqlStmt * db_model_get_stmt (DbModel * self) { - g_return_val_if_fail (DB_IS_MODEL (obj), NULL); + g_return_val_if_fail (DB_IS_MODEL (self), NULL); - return obj->priv->stmt; + return self->priv->stmt; } /** * db_model_set_stmt: - * @obj: a #DbModel + * @self: a #DbModel * @stmt: the #SqlStmt * * Sets the "stmt" property of the model. **/ -void db_model_set_stmt (DbModel * obj, SqlStmt * stmt) +void db_model_set_stmt (DbModel * self, SqlStmt * stmt) { if (!stmt) return; - g_return_if_fail (!obj->priv->stmt); + g_return_if_fail (!self->priv->stmt); g_return_if_fail (SQL_IS_STRING (stmt) || SQL_IS_SELECT (stmt)); - obj->priv->stmt = g_object_ref_sink (stmt); - g_signal_connect (stmt, "changed", G_CALLBACK (db_model_on_stmt_changed), obj); - db_model_on_stmt_changed (stmt, obj); + self->priv->stmt = g_object_ref_sink (stmt); + g_signal_connect (stmt, "changed", G_CALLBACK (db_model_on_stmt_changed), self); + db_model_on_stmt_changed (stmt, self); } /** * db_model_set_sql: - * @obj: a #DbModel + * @self: a #DbModel * @sql: a value for the "sql property * * Sets the "sql" property to @sql. **/ -void db_model_set_sql (DbModel * obj, const gchar * sql) +void db_model_set_sql (DbModel * self, const gchar * sql) { SqlObject * string; if (!sql) return; - g_return_if_fail (DB_IS_MODEL (obj)); + g_return_if_fail (DB_IS_MODEL (self)); - g_free (obj->priv->sql); - obj->priv->sql = g_strdup (sql); + g_free (self->priv->sql); + self->priv->sql = g_strdup (sql); - if (obj->priv->use_file) - string = db_conn_create_stmt_from_file (obj->priv->conn, sql); + if (self->priv->use_file) + string = db_conn_create_stmt_from_file (self->priv->conn, sql); else string = sql_string_new (sql); - db_model_set_stmt (obj, SQL_STMT (string)); + db_model_set_stmt (self, SQL_STMT (string)); } /** * db_model_get: - * @obj: a #DbModel + * @self: a #DbModel * @iter: a #DbIter * @...: (out callee-allocates): pairs of column number and value return * locations, terminated by -1 @@ -1825,24 +1676,24 @@ void db_model_set_sql (DbModel * obj, const gchar * sql) * type G_TYPE_STRING or G_TYPE_BOXED have to be freed. Other values are passed * by value. **/ -void db_model_get (DbModel * obj, DbIter * iter, ...) +void db_model_get (DbModel * self, DbIter * iter, ...) { va_list va; gint column; GValue * val; - g_return_if_fail (DB_IS_MODEL (obj)); - g_return_if_fail (obj->priv->result); + g_return_if_fail (DB_IS_MODEL (self)); + g_return_if_fail (self->priv->result); g_return_if_fail (iter != NULL); va_start (va, iter); - while ((column = (va_arg (va, gint))) >= 0 && column < obj->priv->result->ncols) + while ((column = (va_arg (va, gint))) >= 0 && column < self->priv->result->ncols) { val = DB_ROW_FIELD (iter->data, column); if (gvn_value_is_null (val)) - switch (gvn_param_spec_get_gtype (obj->priv->column[column].spec)) + switch (gvn_param_spec_get_gtype (self->priv->column[column].spec)) { case G_TYPE_CHAR: *va_arg (va, gchar*) = 0; @@ -1872,7 +1723,7 @@ void db_model_get (DbModel * obj, DbIter * iter, ...) /** * db_model_set: - * @obj: a #DbModel + * @self: a #DbModel * @iter: a #DbIter * @...: pairs of column number and value, terminated by -1 * @@ -1882,25 +1733,25 @@ void db_model_get (DbModel * obj, DbIter * iter, ...) * The value will be referenced by the model if it is a G_TYPE_OBJECT, and it * will be copied if it is a G_TYPE_STRING or G_TYPE_BOXED. **/ -void db_model_set (DbModel * obj, DbIter * iter, ...) +void db_model_set (DbModel * self, DbIter * iter, ...) { gint column; gpointer content; GValue val = {0}; va_list va; - g_return_if_fail (DB_IS_MODEL (obj)); - g_return_if_fail (obj->priv->result); + g_return_if_fail (DB_IS_MODEL (self)); + g_return_if_fail (self->priv->result); g_return_if_fail (iter != NULL); va_start (va, iter); - while ((column = (va_arg (va, gint))) >= 0 && column < obj->priv->result->ncols) + while ((column = (va_arg (va, gint))) >= 0 && column < self->priv->result->ncols) { content = va_arg (va, gpointer); gvn_value_new_with_content (&val, - gvn_param_spec_get_gtype (obj->priv->column[column].spec), content); - gvn_value_copy (&val, DB_ROW_FIELD (iter->data, column)); + gvn_param_spec_get_gtype (self->priv->column[column].spec), content); + db_model_set_value (self, iter, column, &val, NULL); g_value_unset (&val); } @@ -1910,22 +1761,22 @@ void db_model_set (DbModel * obj, DbIter * iter, ...) /** * db_model_get_value: - * @obj: a #DbModel - * @iter: a #DbIter pointing to a row of @obj + * @self: a #DbModel + * @iter: a #DbIter pointing to a row of @self * @col: the number of the field to get the value * @err: (out) (allow-none): a #GError or %NULL to ignore errors * - * Gets a value from @obj pointed to by @iter and @col and puts it in @err. + * Gets a value from @self pointed to by @iter and @col and puts it in @err. * * Return value: the value pointed to by @iter and @col or %NULL in case of error **/ -const GValue * db_model_get_value (DbModel * obj, DbIter * iter, gint col, GError ** err) +const GValue * db_model_get_value (DbModel * self, DbIter * iter, gint col, GError ** err) { - g_return_val_if_fail (DB_IS_MODEL (obj), NULL); - g_return_val_if_fail (obj->priv->data && obj->priv->result, NULL); - g_return_val_if_fail (VALID_ITER (iter, obj), NULL); + g_return_val_if_fail (DB_IS_MODEL (self), NULL); + g_return_val_if_fail (self->priv->data && self->priv->result, NULL); + g_return_val_if_fail (VALID_ITER (iter, self), NULL); - if (MODEL_NOT_READY (obj)) + if (MODEL_NOT_READY (self)) { g_set_error (err ,DB_MODEL_LOG_DOMAIN @@ -1934,7 +1785,7 @@ const GValue * db_model_get_value (DbModel * obj, DbIter * iter, gint col, GErro return NULL; } - if (0 > col || col >= obj->priv->result->ncols) + if (0 > col || col >= self->priv->result->ncols) { g_set_error (err ,DB_MODEL_LOG_DOMAIN @@ -1948,13 +1799,13 @@ const GValue * db_model_get_value (DbModel * obj, DbIter * iter, gint col, GErro /** * db_model_set_value: - * @obj: a #DbModel + * @self: a #DbModel * @iter: a #DbIter pointing to the row to be set * @col: the column of the field to be set * @value: new value for the field pointed to by @iter and @col * @err: (out) (allow-none): a #GError or %NULL to ignore errors * - * Sets the value of a single field to @value on @obj as well as on the database. + * Sets the value of a single field to @value on @self as well as on the database. * If the database update fails, the model is not updated and err is set * if it's not %NULL. * If @iter is pointing a new row (inserted by db_model_insert() but not yet @@ -1963,15 +1814,15 @@ const GValue * db_model_get_value (DbModel * obj, DbIter * iter, gint col, GErro * * Return value: %TRUE on success, %FALSE otherwise **/ -gboolean db_model_set_value (DbModel * obj, DbIter * iter, gint col, const GValue * value, GError ** err) +gboolean db_model_set_value (DbModel * self, DbIter * iter, gint col, const GValue * value, GError ** err) { - DbModelPrivate * priv = obj->priv; + DbModelPrivate * priv = self->priv; gboolean ret = FALSE; - g_return_val_if_fail (DB_IS_MODEL (obj), FALSE); - g_return_val_if_fail (VALID_ITER (iter, obj), FALSE); + g_return_val_if_fail (DB_IS_MODEL (self), FALSE); + g_return_val_if_fail (VALID_ITER (iter, self), FALSE); - if (MODEL_NOT_READY (obj) || !priv->result) + if (MODEL_NOT_READY (self) || !priv->result) { g_set_error (err, DB_MODEL_LOG_DOMAIN ,DB_MODEL_ERROR_NOT_READY, "Model not ready"); @@ -2001,7 +1852,7 @@ gboolean db_model_set_value (DbModel * obj, DbIter * iter, gint col, const GValu { ret = TRUE; } - else if (!db_model_set_row_operation (obj, row, DB_MODEL_ROW_OP_UPDATE, col)) + else if (!db_model_set_row_operation (self, row, DB_MODEL_ROW_OP_UPDATE, col)) { g_set_error (err, DB_MODEL_LOG_DOMAIN ,DB_MODEL_ERROR_NOT_UPDATABLE, "Row locked. " @@ -2011,14 +1862,14 @@ gboolean db_model_set_value (DbModel * obj, DbIter * iter, gint col, const GValu { priv->updated_col = col; priv->updated_value = g_new0 (GValue, 1); - gvn_value_copy (&new_value - ,g_value_init (priv->updated_value, G_VALUE_TYPE (&new_value))); + g_value_init (priv->updated_value, G_VALUE_TYPE (&new_value)); + g_value_copy (&new_value, priv->updated_value); - g_signal_emit (obj, db_model_signal[LINE_UPDATED], 0, iter); + g_signal_emit (self, db_model_signal[LINE_UPDATED], 0, iter); if (priv->mode == DB_MODEL_MODE_ON_CHANGE && !(row_op & DB_MODEL_ROW_OP_INSERT)) - db_model_perform_operations (obj, FALSE); + db_model_perform_operations (self, FALSE); ret = TRUE; } @@ -2031,24 +1882,24 @@ gboolean db_model_set_value (DbModel * obj, DbIter * iter, gint col, const GValu /** * db_model_insert: - * @obj: a #DbModel + * @self: a #DbModel * @iter: (out): a #DbIter that will point to the new row * - * Inserts an empty row at the end of @obj. The values for this row must be + * Inserts an empty row at the end of @self. The values for this row must be * set one by one using db_model_set_value() or all at once with db_model_set(). * And then committed with db_model_perform_operations(). **/ -gboolean db_model_insert (DbModel * obj, DbIter * iter) +gboolean db_model_insert (DbModel * self, DbIter * iter) { gint i; DbRow * row; DbModelPrivate * priv; - g_return_val_if_fail (DB_IS_MODEL (obj), FALSE); + g_return_val_if_fail (DB_IS_MODEL (self), FALSE); - priv = obj->priv; + priv = self->priv; - if (MODEL_NOT_READY (obj) || !priv->result) + if (MODEL_NOT_READY (self) || !priv->result) { g_log (g_quark_to_string (DB_MODEL_LOG_DOMAIN) ,G_LOG_LEVEL_WARNING, "Model not ready"); @@ -2096,36 +1947,36 @@ gboolean db_model_insert (DbModel * obj, DbIter * iter) iter->stamp = priv->stamp; priv->result->nrows++; - db_model_set_row_operation (obj, iter->data, DB_MODEL_ROW_OP_INSERT, 0); + db_model_set_row_operation (self, iter->data, DB_MODEL_ROW_OP_INSERT, 0); - g_signal_emit (obj, db_model_signal[LINE_INSERTED], 0, iter); + g_signal_emit (self, db_model_signal[LINE_INSERTED], 0, iter); return TRUE; } /** * db_model_delete: - * @obj: a #DbModel + * @self: a #DbModel * @iter: a #DbIter pointing to the row to be deleted * - * Deletes the row pointed to by @iter on @obj, as well as on the database (if + * Deletes the row pointed to by @iter on @self, as well as on the database (if * it was already there, i.e. it's not a new row). - * If the deletion on the database fails, then the row on @obj is not deleted + * If the deletion on the database fails, then the row on @self is not deleted * and a log message is emitted. **/ -void db_model_delete (DbModel * obj, DbIter * iter) +void db_model_delete (DbModel * self, DbIter * iter) { - g_return_if_fail (DB_IS_MODEL (obj)); - g_return_if_fail (VALID_ITER (iter, obj)); + g_return_if_fail (DB_IS_MODEL (self)); + g_return_if_fail (VALID_ITER (iter, self)); - if (MODEL_NOT_READY (obj)) + if (MODEL_NOT_READY (self)) { g_log (g_quark_to_string (DB_MODEL_LOG_DOMAIN) ,G_LOG_LEVEL_WARNING, "Model not ready"); return; } - if (!(obj->priv->update_flags & DB_MODEL_DELETE)) + if (!(self->priv->update_flags & DB_MODEL_DELETE)) { g_log (g_quark_to_string (DB_MODEL_LOG_DOMAIN) ,G_LOG_LEVEL_WARNING, "Can't delete from this Model"); @@ -2133,30 +1984,30 @@ void db_model_delete (DbModel * obj, DbIter * iter) } if (!db_model_set_row_operation - (obj, g_ptr_array_index (obj->priv->data, DB_ROW_POSITION (iter->data)), + (self, g_ptr_array_index (self->priv->data, DB_ROW_POSITION (iter->data)), DB_MODEL_ROW_OP_DELETE, 0)) return; - g_signal_emit (obj, db_model_signal[LINE_TOGGLED], 0, iter); + g_signal_emit (self, db_model_signal[LINE_TOGGLED], 0, iter); - if (obj->priv->mode == DB_MODEL_MODE_ON_CHANGE) - db_model_perform_operations (obj, FALSE); + if (self->priv->mode == DB_MODEL_MODE_ON_CHANGE) + db_model_perform_operations (self, FALSE); } /** * db_model_order_by: - * @obj: a #DbModel + * @self: a #DbModel * @col: the number of the column that will be the sort criteria * @order: the order to sort in * - * Sorts @obj in the order indicated by @order and using the data + * Sorts @self in the order indicated by @order and using the data * on the field @col. **/ -void db_model_order_by (DbModel * obj, gint col, DbSortType order) +void db_model_order_by (DbModel * self, gint col, DbSortType order) { DbModelPrivate * priv; - g_return_if_fail (DB_IS_MODEL (obj)); - priv = obj->priv; + g_return_if_fail (DB_IS_MODEL (self)); + priv = self->priv; g_return_if_fail (priv->result && col >= -2 && col < priv->result->ncols); g_return_if_fail (order == DB_SORT_ASCENDING || order == DB_SORT_DESCENDING); @@ -2176,7 +2027,7 @@ void db_model_order_by (DbModel * obj, gint col, DbSortType order) priv->order = order; priv->sort_column_id = col; - g_signal_emit (obj, db_model_signal[SORT_CHANGED], 0, NULL); + g_signal_emit (self, db_model_signal[SORT_CHANGED], 0, NULL); if (order == DB_SORT_DESCENDING) g_ptr_array_sort_with_data (priv->data @@ -2194,12 +2045,12 @@ void db_model_order_by (DbModel * obj, gint col, DbSortType order) DB_ROW_POSITION (row_iter) = i++; } - g_signal_emit (obj, db_model_signal[LINES_REORDERED], 0, col, new_order); + g_signal_emit (self, db_model_signal[LINES_REORDERED], 0, col, new_order); } /** * db_model_search: - * @obj: a #DbModel + * @self: a #DbModel * @col: the field to search in * @iter: a #DbIter that will point the first found element * @content: the value looked for or %NULL @@ -2208,20 +2059,20 @@ void db_model_order_by (DbModel * obj, gint col, DbSortType order) * * Return value: Returns %TRUE if the value is found and %FALSE otherwise **/ -gboolean db_model_search (DbModel * obj, gint col, DbIter * iter, gpointer content) +gboolean db_model_search (DbModel * self, gint col, DbIter * iter, gpointer content) { gboolean ret; GValue value = {0}; - g_return_val_if_fail (DB_IS_MODEL (obj), FALSE); - g_return_val_if_fail (obj->priv->result - && 0 <= obj->priv->result->ncols - && col < obj->priv->result->ncols , FALSE); + g_return_val_if_fail (DB_IS_MODEL (self), FALSE); + g_return_val_if_fail (self->priv->result + && 0 <= self->priv->result->ncols + && col < self->priv->result->ncols , FALSE); gvn_value_new_with_content (&value, - gvn_param_spec_get_gtype (obj->priv->column[col].spec), content); + gvn_param_spec_get_gtype (self->priv->column[col].spec), content); - ret = db_model_search_value (obj, col, iter, &value); + ret = db_model_search_value (self, col, iter, &value); g_value_unset (&value); return ret; @@ -2229,7 +2080,7 @@ gboolean db_model_search (DbModel * obj, gint col, DbIter * iter, gpointer conte /** * db_model_search_value: - * @obj: a #DbModel + * @self: a #DbModel * @col: the field to search in * @iter: a #DbIter that will point the first found element * @value: the value to search for @@ -2239,28 +2090,28 @@ gboolean db_model_search (DbModel * obj, gint col, DbIter * iter, gpointer conte * Return value: Returns %TRUE if the value is found and %FALSE otherwise **/ gboolean db_model_search_value - (DbModel * obj, gint col, DbIter * iter, const GValue * value) + (DbModel * self, gint col, DbIter * iter, const GValue * value) { gint i; GType type; DbRow * row; - g_return_val_if_fail (DB_IS_MODEL (obj), FALSE); + g_return_val_if_fail (DB_IS_MODEL (self), FALSE); g_return_val_if_fail (G_IS_VALUE (value), FALSE); - g_return_val_if_fail (obj->priv->result + g_return_val_if_fail (self->priv->result && 0 <= col - && col < obj->priv->result->ncols, FALSE); + && col < self->priv->result->ncols, FALSE); - type = gvn_param_spec_get_gtype (obj->priv->column[col].spec); + type = gvn_param_spec_get_gtype (self->priv->column[col].spec); if (gvn_value_is_null (value) || G_VALUE_TYPE (value) == type) - for (i = 0; i < obj->priv->result->nrows; i++) + for (i = 0; i < self->priv->result->nrows; i++) { - row = g_ptr_array_index (obj->priv->data, i); + row = g_ptr_array_index (self->priv->data, i); if (gvn_value_compare (DB_ROW_FIELD (row, col), value)) { - iter->stamp = obj->priv->stamp; + iter->stamp = self->priv->stamp; iter->data = row; return TRUE; } @@ -2271,7 +2122,7 @@ gboolean db_model_search_value /** * db_model_get_row_operations: - * @obj: a #DbModel + * @self: a #DbModel * @iter: a #DbIter * * Returns #DbModelRowOp flags indicating the operations being applied to the @@ -2280,36 +2131,36 @@ gboolean db_model_search_value * * Return value: the #DbModelRowOp of the row or 0 **/ -DbModelRowOp db_model_get_row_operations (DbModel * obj, DbIter * iter) +DbModelRowOp db_model_get_row_operations (DbModel * self, DbIter * iter) { DbOperation * op; - g_return_val_if_fail (DB_IS_MODEL (obj), 0); - g_return_val_if_fail (VALID_ITER (iter, obj), 0); + g_return_val_if_fail (DB_IS_MODEL (self), 0); + g_return_val_if_fail (VALID_ITER (iter, self), 0); - op = g_hash_table_lookup (obj->priv->row_ops, (DbRow *) iter->data); + op = g_hash_table_lookup (self->priv->row_ops, (DbRow *) iter->data); return op ? op->type : 0; } /** * db_model_has_pending_operations: - * @obj: a #DbModel + * @self: a #DbModel * * Returns whether there are pending operations in the model. * * Return value: #TRUE if the model has pending operations, #FALSE otherwise **/ -gboolean db_model_has_pending_operations (DbModel * obj) +gboolean db_model_has_pending_operations (DbModel * self) { - g_return_val_if_fail (DB_IS_MODEL (obj), FALSE); + g_return_val_if_fail (DB_IS_MODEL (self), FALSE); - if (obj->priv->row_ops) - return g_hash_table_size (obj->priv->row_ops) > 0; + if (self->priv->row_ops) + return g_hash_table_size (self->priv->row_ops) > 0; return FALSE; } -static SqlObject * db_model_create_where (DbModel * obj, +static SqlObject * db_model_create_where (DbModel * self, TableInfo * tinfo, DbOperation * operation, gboolean for_insert) { GSList * l; @@ -2317,7 +2168,7 @@ static SqlObject * db_model_create_where (DbModel * obj, GValue * g_value; SqlObject * value; DbRow * row = operation->row; - DbModelPrivate * priv = obj->priv; + DbModelPrivate * priv = self->priv; SqlObject * where; SqlList * and_operands; @@ -2375,11 +2226,11 @@ static SqlObject * db_model_create_where (DbModel * obj, return where; } -static SqlObject * db_model_create_insert (DbModel * obj, +static SqlObject * db_model_create_insert (DbModel * self, TableInfo * tinfo, DbOperation * operation) { gint i; - DbModelPrivate * priv = obj->priv; + DbModelPrivate * priv = self->priv; DbRow * row = operation->row; const GValue * value; SqlList * targets, * stmts, * sets, * fields, * values, * select_fields; @@ -2390,7 +2241,7 @@ static SqlObject * db_model_create_insert (DbModel * obj, GArray * cols; gchar * colname; - where = db_model_create_where (obj, tinfo, operation, TRUE); + where = db_model_create_where (self, tinfo, operation, TRUE); if (!where) return NULL; @@ -2470,17 +2321,17 @@ static SqlObject * db_model_create_insert (DbModel * obj, /** * db_model_perform_operations: - * @obj: a #DbModel with a new row, not yet inserted + * @self: a #DbModel with a new row, not yet inserted * @retry: whether to retry the failed operations (not implemented) * * Commits the changes made by db_model_set_value() to a new row, inserted * by db_model_insert(). * Note that if this method is not called after db_model_insert(), all the * changes made on the new row will be lost. - * If the @obj is working in the #DB_MODEL_MODE_ON_DEMAND, non-interactive, + * If the @self is working in the #DB_MODEL_MODE_ON_DEMAND, non-interactive, * mode, this method will perform every actions taken and not yet submitted. **/ -void db_model_perform_operations (DbModel * obj, gboolean retry) +void db_model_perform_operations (DbModel * self, gboolean retry) { GList * l; DbOperation * op; @@ -2491,16 +2342,16 @@ void db_model_perform_operations (DbModel * obj, gboolean retry) DbRequest * request; gboolean error = FALSE; - g_return_if_fail (DB_IS_MODEL (obj)); + g_return_if_fail (DB_IS_MODEL (self)); - if (MODEL_NOT_READY (obj)) + if (MODEL_NOT_READY (self)) { g_log (g_quark_to_string (DB_MODEL_LOG_DOMAIN), G_LOG_LEVEL_WARNING, "Model not ready"); return; } - priv = obj->priv; + priv = self->priv; if (!priv->operation->length) return; @@ -2520,7 +2371,7 @@ void db_model_perform_operations (DbModel * obj, gboolean retry) { if (!(op->type & DB_MODEL_ROW_OP_INSERT)) { - where = db_model_create_where (obj, priv->main_table, op, FALSE); + where = db_model_create_where (self, priv->main_table, op, FALSE); if (where) { @@ -2542,7 +2393,7 @@ void db_model_perform_operations (DbModel * obj, gboolean retry) } else if (op->type & DB_MODEL_ROW_OP_INSERT) // INSERT + SELECT { - stmt = db_model_create_insert (obj, priv->main_table, op); + stmt = db_model_create_insert (self, priv->main_table, op); if (!stmt) error = TRUE; @@ -2583,7 +2434,7 @@ void db_model_perform_operations (DbModel * obj, gboolean retry) while (g_hash_table_iter_next (&iter, (gpointer) &tinfo, (gpointer) &fields)) { - where = db_model_create_where (obj, tinfo, op, FALSE); + where = db_model_create_where (self, tinfo, op, FALSE); if (where) { @@ -2612,7 +2463,7 @@ void db_model_perform_operations (DbModel * obj, gboolean retry) } else { - SqlObject * insert = db_model_create_insert (obj, tinfo, op); + SqlObject * insert = db_model_create_insert (self, tinfo, op); if (insert) sql_list_add (update_list, insert); @@ -2635,7 +2486,7 @@ void db_model_perform_operations (DbModel * obj, gboolean retry) g_queue_push_tail (ops, op); DbModelRequest * data = g_new (DbModelRequest, 1); - data->obj = g_object_ref (obj); + data->self = g_object_ref (self); data->operations = ops; data->stmts = g_object_ref_sink (stmts); @@ -2651,7 +2502,7 @@ void db_model_perform_operations (DbModel * obj, gboolean retry) ,data ,(GDestroyNotify) db_model_request_free ); - db_model_add_pending_request (obj, request); + db_model_add_pending_request (self, request); } else { @@ -2667,19 +2518,19 @@ void db_model_perform_operations (DbModel * obj, gboolean retry) /** * db_model_refresh: - * @obj: a #DbModel + * @self: a #DbModel * - * Executes the SELECT query and fills @obj with the data returned by it. + * Executes the SELECT query and fills @self with the data returned by it. **/ -void db_model_refresh (DbModel * obj) +void db_model_refresh (DbModel * self) { DbModelPrivate * priv; gboolean is_ready = FALSE; - g_return_if_fail (DB_IS_MODEL (obj)); + g_return_if_fail (DB_IS_MODEL (self)); - priv = obj->priv; - db_model_clear (obj); + priv = self->priv; + db_model_clear (self); if (priv->conn && priv->stmt) { @@ -2734,13 +2585,13 @@ void db_model_refresh (DbModel * obj) if (sql_batch_is_ready (tmp_batch)) { is_ready = TRUE; - db_model_set_status (obj, DB_MODEL_STATUS_LOADING); + db_model_set_status (self, DB_MODEL_STATUS_LOADING); priv->request = db_conn_query_with_stmt_async (priv->conn ,priv->stmt ,tmp_batch ,(DbRequestDoneCallback) db_model_on_data_ready - ,g_object_ref (obj) + ,g_object_ref (self) ,(GDestroyNotify) g_object_unref ); } @@ -2750,23 +2601,23 @@ void db_model_refresh (DbModel * obj) } if (!is_ready) - db_model_set_status (obj, DB_MODEL_STATUS_CLEAN); + db_model_set_status (self, DB_MODEL_STATUS_CLEAN); } /** * db_model_get_nrows: - * @obj: a #DbModel + * @self: a #DbModel * - * Returns the current number of rows on #obj. + * Returns the current number of rows on @self. * * Return value: the number of rows **/ -gint db_model_get_nrows (DbModel * obj) +gint db_model_get_nrows (DbModel * self) { - g_return_val_if_fail (DB_IS_MODEL (obj), 0); + g_return_val_if_fail (DB_IS_MODEL (self), 0); - if (obj->priv->result) - return obj->priv->result->nrows; + if (self->priv->result) + return self->priv->result->nrows; else return 0; } @@ -2778,93 +2629,93 @@ gint db_model_get_nrows (DbModel * obj) * * Checks if @iter is a valid #DbIter pointing inside @model. **/ -gboolean db_model_iter_is_valid (DbIter * iter, DbModel * obj) +gboolean db_model_iter_is_valid (DbIter * iter, DbModel * self) { - g_return_val_if_fail (DB_IS_MODEL (obj), FALSE); + g_return_val_if_fail (DB_IS_MODEL (self), FALSE); - return (iter && iter->data && obj->priv->stamp == iter->stamp); + return (iter && iter->data && self->priv->stamp == iter->stamp); } // GtkTreeModel implementation methods. /** * db_model_get_ncols: - * @obj: a #DbModel + * @self: a #DbModel * - * Returns the number of columns supported by @obj. + * Returns the number of columns supported by @self. * * Return value: the number of columns **/ -gint db_model_get_ncols (DbModel * obj) +gint db_model_get_ncols (DbModel * self) { - g_return_val_if_fail (DB_IS_MODEL (obj), -1); + g_return_val_if_fail (DB_IS_MODEL (self), -1); - if (obj->priv->result) - return obj->priv->result->ncols; + if (self->priv->result) + return self->priv->result->ncols; else return 0; } /** * db_model_get_column_type: - * @obj: a #DbModel + * @self: a #DbModel * @index: the number of the column * * Retrieves the type of the column specified by @index. * * Return value: the type of the column **/ -GType db_model_get_column_type (DbModel * obj, gint index) +GType db_model_get_column_type (DbModel * self, gint index) { - g_return_val_if_fail (DB_IS_MODEL (obj), G_TYPE_INVALID); - g_return_val_if_fail (obj->priv->result - && 0 <= index && index < obj->priv->result->ncols, G_TYPE_INVALID); + g_return_val_if_fail (DB_IS_MODEL (self), G_TYPE_INVALID); + g_return_val_if_fail (self->priv->result + && 0 <= index && index < self->priv->result->ncols, G_TYPE_INVALID); - if (obj->priv->column) - if (obj->priv->column[index].spec) - return gvn_param_spec_get_gtype (obj->priv->column[index].spec); + if (self->priv->column) + if (self->priv->column[index].spec) + return gvn_param_spec_get_gtype (self->priv->column[index].spec); return G_TYPE_INVALID; } /** * db_model_get_path: - * @obj: a #DbModel + * @self: a #DbModel * @iter: a #DbIter * * Returns the number of the row pointed to by @iter. * * Return value: the number of the row pointed to by @iter **/ -gint db_model_get_path (DbModel * obj, DbIter * iter) +gint db_model_get_path (DbModel * self, DbIter * iter) { - g_return_val_if_fail (DB_IS_MODEL (obj), 0); - if (MODEL_NOT_READY (obj)) return 0; - g_return_val_if_fail (VALID_ITER (iter, obj), 0); + g_return_val_if_fail (DB_IS_MODEL (self), 0); + if (MODEL_NOT_READY (self)) return 0; + g_return_val_if_fail (VALID_ITER (iter, self), 0); return DB_ROW_POSITION (iter->data); } /** * db_model_get_iter: - * @obj: a #DbModel + * @self: a #DbModel * @iter: (out): an unitialized #DbIter * @path: the number of the row being accessed * - * Sets @iter pointing to the row of @obj specified by @path. + * Sets @iter pointing to the row of @self specified by @path. * * Return value: %TRUE if the position is found, %FALSE otherwise **/ -gboolean db_model_get_iter (DbModel * obj, DbIter * iter, gint path) +gboolean db_model_get_iter (DbModel * self, DbIter * iter, gint path) { - g_return_val_if_fail (DB_IS_MODEL (obj), FALSE); + g_return_val_if_fail (DB_IS_MODEL (self), FALSE); if ((0 > path - || (obj->priv->result && path >= obj->priv->result->nrows)) - || MODEL_NOT_READY (obj)) + || (self->priv->result && path >= self->priv->result->nrows)) + || MODEL_NOT_READY (self)) return FALSE; - iter->stamp = obj->priv->stamp; - iter->data = g_ptr_array_index (obj->priv->data, (guint) path); + iter->stamp = self->priv->stamp; + iter->data = g_ptr_array_index (self->priv->data, (guint) path); if (iter->data) return TRUE; @@ -2873,24 +2724,24 @@ gboolean db_model_get_iter (DbModel * obj, DbIter * iter, gint path) /** * db_model_get_iter_first: - * @obj: a #DbModel + * @self: a #DbModel * @iter: (out): an unitialized #DbIter * - * Sets @iter pointing to the first row of @obj. + * Sets @iter pointing to the first row of @self. * * Return value: %TRUE if @iter is set right **/ -gboolean db_model_get_iter_first (DbModel * obj, DbIter * iter) +gboolean db_model_get_iter_first (DbModel * self, DbIter * iter) { - g_return_val_if_fail (DB_IS_MODEL (obj), FALSE); - if (MODEL_NOT_READY(obj) - || !obj->priv->result || !obj->priv->result->nrows) + g_return_val_if_fail (DB_IS_MODEL (self), FALSE); + if (MODEL_NOT_READY(self) + || !self->priv->result || !self->priv->result->nrows) return FALSE; - if (obj->priv->data) + if (self->priv->data) { - iter->stamp = obj->priv->stamp; - iter->data = g_ptr_array_index (obj->priv->data, 0); + iter->stamp = self->priv->stamp; + iter->data = g_ptr_array_index (self->priv->data, 0); } else return FALSE; @@ -2900,51 +2751,51 @@ gboolean db_model_get_iter_first (DbModel * obj, DbIter * iter) /** * db_model_iter_prev: - * @obj: a #DbModel + * @self: a #DbModel * @iter: (inout): a valid #DbIter * - * Sets @iter pointing to the previous row of @obj. + * Sets @iter pointing to the previous row of @self. * * Return value: %TRUE if the iter has been changed to the previous row **/ -gboolean db_model_iter_prev (DbModel * obj, DbIter * iter) +gboolean db_model_iter_prev (DbModel * self, DbIter * iter) { - g_return_val_if_fail (DB_IS_MODEL (obj), FALSE); - if (MODEL_NOT_READY(obj) - || !obj->priv->result || !obj->priv->result->nrows) + g_return_val_if_fail (DB_IS_MODEL (self), FALSE); + if (MODEL_NOT_READY(self) + || !self->priv->result || !self->priv->result->nrows) return FALSE; - g_return_val_if_fail (VALID_ITER (iter, obj), FALSE); + g_return_val_if_fail (VALID_ITER (iter, self), FALSE); if ((iter->data = g_ptr_array_index - (obj->priv->data, (guint) DB_ROW_POSITION (iter->data) - 1))) + (self->priv->data, (guint) DB_ROW_POSITION (iter->data) - 1))) return TRUE; return FALSE; } /** * db_model_iter_next: - * @obj: a #DbModel + * @self: a #DbModel * @iter: (inout): a valid #DbIter * - * Sets @iter pointing to the next row of @obj. + * Sets @iter pointing to the next row of @self. * * Return value: %TRUE if the iter has been changed to the next row **/ -gboolean db_model_iter_next (DbModel * obj, DbIter * iter) +gboolean db_model_iter_next (DbModel * self, DbIter * iter) { - g_return_val_if_fail (DB_IS_MODEL (obj), FALSE); - if (MODEL_NOT_READY(obj) - || !obj->priv->result || !obj->priv->result->nrows) + g_return_val_if_fail (DB_IS_MODEL (self), FALSE); + if (MODEL_NOT_READY(self) + || !self->priv->result || !self->priv->result->nrows) return FALSE; - g_return_val_if_fail (VALID_ITER (iter, obj), FALSE); + g_return_val_if_fail (VALID_ITER (iter, self), FALSE); gint pos = DB_ROW_POSITION (iter->data); - if (pos < obj->priv->result->nrows-1) + if (pos < self->priv->result->nrows-1) { - iter->data = g_ptr_array_index (obj->priv->data, (guint) pos + 1); + iter->data = g_ptr_array_index (self->priv->data, (guint) pos + 1); return TRUE; } @@ -2957,7 +2808,7 @@ gboolean db_model_iter_next (DbModel * obj, DbIter * iter) /** * db_model_get_sort_column_id: - * @obj: a #DbModel + * @self: a #DbModel * @sort_column_id: (out): an integer * @order: (out): a @DbSortType * @@ -2967,19 +2818,19 @@ gboolean db_model_iter_next (DbModel * obj, DbIter * iter) * Return value: %TRUE if the sort column is not one of the special sort column * ids **/ -gboolean db_model_get_sort_column_id (DbModel * obj, gint * sort_column_id, +gboolean db_model_get_sort_column_id (DbModel * self, gint * sort_column_id, DbSortType * order) { - g_return_val_if_fail (DB_IS_MODEL (obj), FALSE); + g_return_val_if_fail (DB_IS_MODEL (self), FALSE); if (sort_column_id) - * sort_column_id = obj->priv->sort_column_id; + * sort_column_id = self->priv->sort_column_id; if (order) - * order = obj->priv->order; + * order = self->priv->order; - if (obj->priv->sort_column_id == DB_MODEL_DEFAULT_SORT_COLUMN_ID - || obj->priv->sort_column_id == DB_MODEL_UNSORTED_SORT_COLUMN_ID) + if (self->priv->sort_column_id == DB_MODEL_DEFAULT_SORT_COLUMN_ID + || self->priv->sort_column_id == DB_MODEL_UNSORTED_SORT_COLUMN_ID) return FALSE; else return TRUE; @@ -2987,18 +2838,18 @@ gboolean db_model_get_sort_column_id (DbModel * obj, gint * sort_column_id, /** * db_model_set_sort_column_id: - * @obj: a #DbModel + * @self: a #DbModel * @sort_column_id: the column to sort by * @order: the order in which the sort will be done * - * Sets @sort_column_id to be the current sort column. @obj will resort itself + * Sets @sort_column_id to be the current sort column. @self will resort itself * to reflect this change. See #GtkTreeSortable. **/ -void db_model_set_sort_column_id (DbModel * obj, gint sort_column_id, +void db_model_set_sort_column_id (DbModel * self, gint sort_column_id, DbSortType order) { - g_return_if_fail (DB_IS_MODEL (obj)); - db_model_order_by (obj, sort_column_id, order); + g_return_if_fail (DB_IS_MODEL (self)); + db_model_order_by (self, sort_column_id, order); } //+++++++++++++++++++++++++++++++++++++++++++++++++++ Class @@ -3016,75 +2867,75 @@ typedef enum } DbModelProp; -static void db_model_set_property (DbModel * obj, guint property_id, +static void db_model_set_property (DbModel * self, guint property_id, const GValue * value, GParamSpec * pspec) { switch (property_id) { case PROP_CONN: - db_model_set_conn (obj, g_value_get_object (value)); + db_model_set_conn (self, g_value_get_object (value)); break; case PROP_STMT: - db_model_set_stmt (obj, g_value_get_object (value)); + db_model_set_stmt (self, g_value_get_object (value)); break; case PROP_SQL: - db_model_set_sql (obj, g_value_get_string (value)); + db_model_set_sql (self, g_value_get_string (value)); break; case PROP_USE_FILE: - obj->priv->use_file = g_value_get_boolean (value); + self->priv->use_file = g_value_get_boolean (value); break; case PROP_UPDATE_FLAGS: - db_model_request_update_flags (obj, g_value_get_flags (value)); + db_model_request_update_flags (self, g_value_get_flags (value)); break; case PROP_RESULT_POS: - obj->priv->result_pos = g_value_get_uint (value); + self->priv->result_pos = g_value_get_uint (value); break; case PROP_PARTIAL_DELETE: - obj->priv->partial_delete = g_value_get_boolean (value); + self->priv->partial_delete = g_value_get_boolean (value); break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID (self, property_id, pspec); } } -static void db_model_get_property (DbModel * obj, guint property_id, +static void db_model_get_property (DbModel * self, guint property_id, GValue * value, GParamSpec * pspec) { switch (property_id) { case PROP_CONN: - g_value_set_object (value, obj->priv->conn); + g_value_set_object (value, self->priv->conn); break; case PROP_STMT: - g_value_set_object (value, obj->priv->stmt); + g_value_set_object (value, self->priv->stmt); break; case PROP_SQL: - g_value_set_string (value, obj->priv->sql); + g_value_set_string (value, self->priv->sql); break; case PROP_USE_FILE: - g_value_set_boolean (value, obj->priv->use_file); + g_value_set_boolean (value, self->priv->use_file); break; case PROP_MAIN_TABLE: - g_value_set_string (value, db_model_get_main_table (obj)); + g_value_set_string (value, db_model_get_main_table (self)); break; case PROP_UPDATE_FLAGS: - g_value_set_flags (value, obj->priv->update_flags); + g_value_set_flags (value, self->priv->update_flags); break; case PROP_RESULT_POS: - g_value_set_uint (value, obj->priv->result_pos); + g_value_set_uint (value, self->priv->result_pos); break; case PROP_PARTIAL_DELETE: - g_value_set_boolean (value, obj->priv->partial_delete); + g_value_set_boolean (value, self->priv->partial_delete); break; default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); + G_OBJECT_WARN_INVALID_PROPERTY_ID (self, property_id, pspec); } } -static void db_model_init (DbModel *obj) +static void db_model_init (DbModel * self) { - DbModelPrivate * priv = obj->priv = - G_TYPE_INSTANCE_GET_PRIVATE (obj, DB_TYPE_MODEL, DbModelPrivate); + DbModelPrivate * priv = self->priv = + G_TYPE_INSTANCE_GET_PRIVATE (self, DB_TYPE_MODEL, DbModelPrivate); priv->conn = NULL; priv->batch = NULL; @@ -3132,18 +2983,18 @@ static void db_model_init (DbModel *obj) priv->join = NULL; } -static void db_model_finalize (DbModel * obj) +static void db_model_finalize (DbModel * self) { - DbModelPrivate * priv = obj->priv; - GObjectClass * parent = g_type_class_peek_parent (DB_MODEL_GET_CLASS (obj)); + DbModelPrivate * priv = self->priv; + GObjectClass * parent = g_type_class_peek_parent (DB_MODEL_GET_CLASS (self)); - db_model_clear (obj); + db_model_clear (self); g_clear_object (&priv->conn); g_clear_object (&priv->stmt); g_free (priv->sql); g_hash_table_destroy (priv->column_index); - db_model_set_batch (obj, NULL); + db_model_set_batch (self, NULL); g_hash_table_destroy (priv->defaults); if (priv->updatable_data_allocated) @@ -3155,7 +3006,7 @@ static void db_model_finalize (DbModel * obj) // g_slist_free_full (priv->join, (GDestroyNotify) db_join_free); } - parent->finalize (G_OBJECT (obj)); + parent->finalize (G_OBJECT (self)); } static void db_model_class_init (DbModelClass *k) diff --git a/db/db-model.h b/db/db-model.h index b8f6c0f..f58e782 100644 --- a/db/db-model.h +++ b/db/db-model.h @@ -27,11 +27,11 @@ #define DB_MODEL_LOG_DOMAIN (g_quark_from_string ("DbModel")) #define DB_TYPE_MODEL (db_model_get_type()) -#define DB_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DB_TYPE_MODEL, DbModel)) -#define DB_IS_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DB_TYPE_MODEL)) +#define DB_MODEL(self) (G_TYPE_CHECK_INSTANCE_CAST ((self), DB_TYPE_MODEL, DbModel)) +#define DB_IS_MODEL(self) (G_TYPE_CHECK_INSTANCE_TYPE ((self), DB_TYPE_MODEL)) #define DB_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DB_TYPE_MODEL, DbModelClass)) #define DB_IS_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DB_TYPE_MODEL)) -#define DB_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DB_TYPE_MODEL, DbModelClass)) +#define DB_MODEL_GET_CLASS(self) (G_TYPE_INSTANCE_GET_CLASS ((self), DB_TYPE_MODEL, DbModelClass)) #define DB_TYPE_MODEL_UPDATE_FLAGS (db_model_update_flags_get_type()) @@ -185,102 +185,102 @@ GType db_model_update_flags_get_type () G_GNUC_CONST; DbModel * db_model_new (DbConn * conn, SqlStmt * stmt); DbModel * db_model_new_with_sql (DbConn * conn, const gchar * sql); DbModel * db_model_new_with_file (DbConn * conn, const gchar * file); -DbConn * db_model_get_conn (DbModel * obj); -void db_model_set_conn (DbModel * obj, DbConn * conn); -const GvnParamSpec * db_model_get_spec (DbModel * obj, gint col); -const gchar * db_model_get_column_name (DbModel * obj, gint col); -gint db_model_get_column_index (DbModel * obj, const gchar * name); -void db_model_refresh (DbModel * obj); -const SqlStmt * db_model_get_stmt (DbModel * obj); -void db_model_set_stmt (DbModel * obj, SqlStmt * stmt); -void db_model_add_pre_stmt (DbModel * obj, SqlStmt * stmt); -void db_model_add_post_stmt (DbModel * obj, SqlStmt * stmt); -DbModelStatus db_model_get_status (DbModel * obj); -const gchar * db_model_get_main_table (DbModel * obj); -DbModelUpdateFlags db_model_get_update_flags (DbModel * obj); -void db_model_request_update_flags (DbModel * obj +DbConn * db_model_get_conn (DbModel * self); +void db_model_set_conn (DbModel * self, DbConn * conn); +const GvnParamSpec * db_model_get_spec (DbModel * self, gint col); +const gchar * db_model_get_column_name (DbModel * self, gint col); +gint db_model_get_column_index (DbModel * self, const gchar * name); +void db_model_refresh (DbModel * self); +const SqlStmt * db_model_get_stmt (DbModel * self); +void db_model_set_stmt (DbModel * self, SqlStmt * stmt); +void db_model_add_pre_stmt (DbModel * self, SqlStmt * stmt); +void db_model_add_post_stmt (DbModel * self, SqlStmt * stmt); +DbModelStatus db_model_get_status (DbModel * self); +const gchar * db_model_get_main_table (DbModel * self); +DbModelUpdateFlags db_model_get_update_flags (DbModel * self); +void db_model_request_update_flags (DbModel * self ,DbModelUpdateFlags flags); -void db_model_unset_update_flags (DbModel * obj +void db_model_unset_update_flags (DbModel * self ,DbModelUpdateFlags flags); -void db_model_set_mode (DbModel * obj, DbModelMode mode); -DbModelMode db_model_get_mode (DbModel * obj); -void db_model_toggle_mode (DbModel * obj); -gboolean db_model_get_last (DbModel * obj, DbIter * iter); -void db_model_get (DbModel * obj +void db_model_set_mode (DbModel * self, DbModelMode mode); +DbModelMode db_model_get_mode (DbModel * self); +void db_model_toggle_mode (DbModel * self); +gboolean db_model_get_last (DbModel * self, DbIter * iter); +void db_model_get (DbModel * self ,DbIter * iter ,...); -void db_model_set (DbModel * obj +void db_model_set (DbModel * self ,DbIter * iter ,...); -const GValue * db_model_get_value (DbModel * obj, +const GValue * db_model_get_value (DbModel * self, DbIter * iter, gint col, GError ** err); -gboolean db_model_set_value (DbModel * obj, +gboolean db_model_set_value (DbModel * self, DbIter * iter, gint col, const GValue * value, GError ** err); -gboolean db_model_insert (DbModel * obj, DbIter * iter); -void db_model_delete (DbModel * obj, DbIter * iter); -DbModelRowOp db_model_get_row_operations (DbModel * obj, DbIter * iter); -gboolean db_model_has_pending_operations (DbModel * obj); -void db_model_perform_operations (DbModel * obj, gboolean retry); -void db_model_reverse_operations (DbModel * obj); -void db_model_order_by (DbModel * obj, +gboolean db_model_insert (DbModel * self, DbIter * iter); +void db_model_delete (DbModel * self, DbIter * iter); +DbModelRowOp db_model_get_row_operations (DbModel * self, DbIter * iter); +gboolean db_model_has_pending_operations (DbModel * self); +void db_model_perform_operations (DbModel * self, gboolean retry); +void db_model_reverse_operations (DbModel * self); +void db_model_order_by (DbModel * self, gint col, DbSortType order); -gboolean db_model_search (DbModel * obj, +gboolean db_model_search (DbModel * self, gint col, DbIter * iter, gpointer content); -gboolean db_model_search_value (DbModel * obj, +gboolean db_model_search_value (DbModel * self, gint col, DbIter * iter, const GValue * value); -gint db_model_get_nrows (DbModel * obj); +gint db_model_get_nrows (DbModel * self); gboolean db_model_iter_is_valid (DbIter * iter ,DbModel * model); -void db_model_add_join_columns (DbModel * obj - ,const gchar * left - ,const gchar * right); -SqlBatch * db_model_get_batch (DbModel * obj); -void db_model_set_batch (DbModel * obj, SqlBatch * batch); +void db_model_add_join (DbModel * self + ,const gchar * master_field + ,const gchar * slave_field); +SqlBatch * db_model_get_batch (DbModel * self); +void db_model_set_batch (DbModel * self, SqlBatch * batch); -void db_model_set_default_value_from_column (DbModel * obj, const gchar * field, const gchar * column); -void db_model_set_default_value_from_param (DbModel * obj, const gchar * field, GvnParam * param, gboolean link); +void db_model_set_default_value_from_column (DbModel * self, const gchar * field, const gchar * column); +void db_model_set_default_value_from_param (DbModel * self, const gchar * field, GvnParam * param, gboolean link); //GtkTreeModel-like methods -gint db_model_get_ncols (DbModel * obj); -GType db_model_get_column_type (DbModel * obj, gint index); -gboolean db_model_get_iter_first (DbModel * obj, DbIter * iter); -gboolean db_model_get_iter (DbModel * obj, +gint db_model_get_ncols (DbModel * self); +GType db_model_get_column_type (DbModel * self, gint index); +gboolean db_model_get_iter_first (DbModel * self, DbIter * iter); +gboolean db_model_get_iter (DbModel * self, DbIter * iter, gint path); -gint db_model_get_path (DbModel * obj, DbIter * iter); -gboolean db_model_iter_next (DbModel * obj, DbIter * iter); -gboolean db_model_iter_prev (DbModel * obj, DbIter * iter); -void db_model_ref_node (DbModel * obj, DbIter * iter); -void db_model_unref_node (DbModel * obj, DbIter * iter); +gint db_model_get_path (DbModel * self, DbIter * iter); +gboolean db_model_iter_next (DbModel * self, DbIter * iter); +gboolean db_model_iter_prev (DbModel * self, DbIter * iter); +void db_model_ref_node (DbModel * self, DbIter * iter); +void db_model_unref_node (DbModel * self, DbIter * iter); //GtkTreeSortable-like methods -gboolean db_model_get_sort_column_id (DbModel * obj, +gboolean db_model_get_sort_column_id (DbModel * self, gint * sort_column_id, DbSortType * order); -void db_model_set_sort_column_id (DbModel * obj, +void db_model_set_sort_column_id (DbModel * self, gint sort_column_id, DbSortType order); -void db_model_set_sort_func (DbModel * obj, +void db_model_set_sort_func (DbModel * self, gint sort_column_id, DbIterCompareFunc func, gpointer data, GDestroyNotify destroy); -void db_model_set_default_sort_func (DbModel * obj, +void db_model_set_default_sort_func (DbModel * self, DbIterCompareFunc func, gpointer data, GDestroyNotify destroy); -gboolean db_model_has_default_sort_func (DbModel * obj); +gboolean db_model_has_default_sort_func (DbModel * self); #endif