gda-holder.c 60.5 KB
Newer Older
1 2 3
/*
 * Copyright (C) 2008 Massimo Cora <maxcvs@email.it>
 * Copyright (C) 2008 - 2011 Murray Cumming <murrayc@murrayc.com>
4
 * Copyright (C) 2008 - 2014 Vivien Malerba <malerba@gnome-db.org>
5 6 7
 * Copyright (C) 2009 Bas Driessen <bas.driessen@xobas.com>
 * Copyright (C) 2010 David King <davidk@openismus.com>
 * Copyright (C) 2010 Jonh Wendell <jwendell@gnome.org>
8
 * Copyright (C) 2011 Daniel Espinosa <despinosa@src.gnome.org>
9
 * Copyright (C) 2015 Corentin Noël <corentin@elementary.io>
10
 *
11 12 13 14
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
15
 *
16
 * This library is distributed in the hope that it will be useful,
17 18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19
 * Lesser General Public License for more details.
20
 *
21 22 23 24
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301, USA.
25 26
 */

27
#include <glib/gi18n-lib.h>
28 29 30 31 32 33 34
#include <stdarg.h>
#include <string.h>
#include "gda-holder.h"
#include "gda-statement.h"
#include "gda-data-model.h"
#include "gda-data-handler.h"
#include "gda-marshal.h"
35 36
#include "gda-util.h"
#include <libgda.h>
37
#include <libgda/gda-custom-marshal.h>
38

39
/*
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
 * Main static functions 
 */
static void gda_holder_class_init (GdaHolderClass * class);
static void gda_holder_init (GdaHolder *holder);
static void gda_holder_dispose (GObject *object);
static void gda_holder_finalize (GObject *object);

static void gda_holder_set_property (GObject *object,
				     guint param_id,
				     const GValue *value,
				     GParamSpec *pspec);
static void gda_holder_get_property (GObject *object,
				     guint param_id,
				     GValue *value,
				     GParamSpec *pspec);

56
/* GdaLockable interface */
57
static void                 gda_holder_lockable_init (GdaLockableInterface *iface);
58 59 60 61 62 63 64
static void                 gda_holder_lock      (GdaLockable *lockable);
static gboolean             gda_holder_trylock   (GdaLockable *lockable);
static void                 gda_holder_unlock    (GdaLockable *lockable);


static void bound_holder_changed_cb (GdaHolder *alias_of, GdaHolder *holder);
static void full_bound_holder_changed_cb (GdaHolder *alias_of, GdaHolder *holder);
65 66 67 68 69 70
static void gda_holder_set_full_bind (GdaHolder *holder, GdaHolder *alias_of);

/* signals */
enum
{
	CHANGED,
71
	SOURCE_CHANGED,
72
	VALIDATE_CHANGE,
73
	LAST_SIGNAL
74 75
};

76
static gint gda_holder_signals[LAST_SIGNAL] = { 0, 0, 0 };
77 78 79 80 81 82 83 84 85 86 87 88 89 90


/* properties */
enum
{
        PROP_0,
	PROP_ID,
	PROP_NAME,
	PROP_DESCR,
	PROP_SIMPLE_BIND,
	PROP_FULL_BIND,
	PROP_SOURCE_MODEL,
	PROP_SOURCE_COLUMN,
	PROP_GDA_TYPE,
91
	PROP_NOT_NULL,
92 93
	PROP_VALIDATE_CHANGES,
	PROP_PLUGIN
94 95 96
};


97
typedef struct {
98 99 100 101 102
	gchar           *id;

	GType            g_type;
	GdaHolder       *full_bind;     /* FULL bind to holder */
	GdaHolder       *simple_bind;  /* SIMPLE bind to holder */
103
	gulong           simple_bind_type_changed_id;
104 105
	
	gboolean         invalid_forced;
106
	GError          *invalid_error;
107
	gboolean         valid;
108
	gboolean         is_freeable;
109 110 111 112 113 114 115 116

	GValue           *value;
	GValue          *default_value; /* CAN be either NULL or of any type */
	gboolean         default_forced;
	gboolean         not_null;      /* TRUE if 'value' must not be NULL when passed to destination fields */

	GdaDataModel    *source_model;
	gint             source_col;
117

118
	GRecMutex        mutex;
119 120

	gboolean         validate_changes;
121 122 123
	gchar           *name;
	gchar           *desc;
	gchar           *plugin;
124
} GdaHolderPrivate;
125 126 127
G_DEFINE_TYPE_WITH_CODE (GdaHolder, gda_holder, G_TYPE_OBJECT,
                         G_ADD_PRIVATE (GdaHolder)
                         G_IMPLEMENT_INTERFACE(GDA_TYPE_LOCKABLE, gda_holder_lockable_init))
128 129 130 131 132 133 134 135 136
/* module error */
GQuark gda_holder_error_quark (void)
{
        static GQuark quark;
        if (!quark)
                quark = g_quark_from_static_string ("gda_holder_error");
        return quark;
}

137
static gboolean
138
validate_change_accumulator (G_GNUC_UNUSED GSignalInvocationHint *ihint,
139 140
			   GValue *return_accu,
			   const GValue *handler_return,
141
			   G_GNUC_UNUSED gpointer data)
142 143 144
{
	GError *error;

145 146
	error = g_value_get_boxed (handler_return);
	g_value_set_boxed (return_accu, error);
147

148
	return error ? FALSE : TRUE; /* stop signal if error has been set */
149 150 151
}

static GError *
152
m_validate_change (G_GNUC_UNUSED GdaHolder *holder, G_GNUC_UNUSED const GValue *new_value)
153 154 155 156
{
	return NULL;
}

157 158 159 160 161
static void
gda_holder_class_init (GdaHolderClass *class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (class);

162
	/**
163
	 * GdaHolder::source-changed:
164 165 166 167
	 * @holder: the #GdaHolder
	 * 
	 * Gets emitted when the data model in which @holder's values should be has changed
	 */
168
	gda_holder_signals[SOURCE_CHANGED] =
169
                g_signal_new ("source-changed",
170 171 172 173
                              G_TYPE_FROM_CLASS (object_class),
                              G_SIGNAL_RUN_FIRST,
                              G_STRUCT_OFFSET (GdaHolderClass, source_changed),
                              NULL, NULL,
174
                              _gda_marshal_VOID__VOID, G_TYPE_NONE, 0);
175
	/**
176
	 * GdaHolder::changed:
177 178 179 180
	 * @holder: the #GdaHolder
	 * 
	 * Gets emitted when @holder's value has changed
	 */
181 182 183 184 185 186
	gda_holder_signals[CHANGED] =
                g_signal_new ("changed",
                              G_TYPE_FROM_CLASS (object_class),
                              G_SIGNAL_RUN_FIRST,
                              G_STRUCT_OFFSET (GdaHolderClass, changed),
                              NULL, NULL,
187
                              _gda_marshal_VOID__VOID, G_TYPE_NONE, 0);
188

189
	/**
190
	 * GdaHolder::validate-change:
191 192 193 194 195 196
	 * @holder: the object which received the signal
	 * @new_value: the proposed new value for @holder
	 * 
	 * Gets emitted when @holder is going to change its value. One can connect to
	 * this signal to control which values @holder can have (for example to implement some business rules)
	 *
Vivien Malerba's avatar
Vivien Malerba committed
197
	 * Returns: NULL if @holder is allowed to change its value to @new_value, or a #GError
198 199
	 * otherwise.
	 */
200 201
	gda_holder_signals[VALIDATE_CHANGE] =
		g_signal_new ("validate-change",
202 203
                              G_TYPE_FROM_CLASS (object_class),
                              G_SIGNAL_RUN_LAST,
204 205
                              G_STRUCT_OFFSET (GdaHolderClass, validate_change),
                              validate_change_accumulator, NULL,
206
                              _gda_marshal_ERROR__VALUE, G_TYPE_ERROR, 1, G_TYPE_VALUE);
207 208 209

        class->changed = NULL;
        class->source_changed = NULL;
210
        class->validate_change = m_validate_change;
211
	class->att_changed = NULL;
212 213 214 215 216 217 218 219 220

	/* virtual functions */
	object_class->dispose = gda_holder_dispose;
	object_class->finalize = gda_holder_finalize;

	/* Properties */
	object_class->set_property = gda_holder_set_property;
	object_class->get_property = gda_holder_get_property;
	g_object_class_install_property (object_class, PROP_ID,
221
					 g_param_spec_string ("id", NULL, "Holder's ID", NULL, 
222 223
							      (G_PARAM_READABLE | G_PARAM_WRITABLE)));
	g_object_class_install_property (object_class, PROP_NAME,
224
					 g_param_spec_string ("name", NULL, "Holder's name", NULL, 
225 226
							      (G_PARAM_READABLE | G_PARAM_WRITABLE)));
	g_object_class_install_property (object_class, PROP_DESCR,
227
					 g_param_spec_string ("description", NULL, "Holder's description", NULL, 
228
							      (G_PARAM_READABLE | G_PARAM_WRITABLE)));
Vivien Malerba's avatar
Vivien Malerba committed
229
	g_object_class_install_property (object_class, PROP_GDA_TYPE,
230
					 g_param_spec_gtype ("g-type", NULL, "Holder's GType", G_TYPE_NONE, 
Vivien Malerba's avatar
Vivien Malerba committed
231
							     (G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT)));
232
	g_object_class_install_property (object_class, PROP_NOT_NULL,
233
					 g_param_spec_boolean ("not-null", NULL, "Can the value holder be NULL?", FALSE,
234 235
							       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
	g_object_class_install_property (object_class, PROP_SIMPLE_BIND,
236 237
					 g_param_spec_object ("simple-bind", NULL, 
							      "Make value holder follow other GdaHolder's changes", 
238 239 240
                                                               GDA_TYPE_HOLDER,
							       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
	g_object_class_install_property (object_class, PROP_FULL_BIND,
241 242 243
					 g_param_spec_object ("full-bind", NULL,
							      "Make value holder follow other GdaHolder's changes "
							      "and the other way around", 
244 245 246
                                                               GDA_TYPE_HOLDER,
							       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
	g_object_class_install_property (object_class, PROP_SOURCE_MODEL,
247 248 249
                                         g_param_spec_object ("source-model", NULL, "Data model among which the holder's "
							      "value should be",
							      GDA_TYPE_DATA_MODEL,
250 251
                                                               (G_PARAM_READABLE | G_PARAM_WRITABLE)));
        g_object_class_install_property (object_class, PROP_SOURCE_COLUMN,
252 253
                                         g_param_spec_int ("source-column", NULL, "Column number to use in coordination "
							   "with the source-model property",
254 255
							   0, G_MAXINT, 0,
							   (G_PARAM_READABLE | G_PARAM_WRITABLE)));
256 257 258
	g_object_class_install_property (object_class, PROP_PLUGIN,
					 g_param_spec_string ("plugin", NULL, "Holder's plugin", NULL,
							      (G_PARAM_READABLE | G_PARAM_WRITABLE)));
259 260 261 262 263 264 265 266 267 268 269 270

	/**
	 * GdaHolder:validate-changes:
	 *
	 * Defines if the "validate-change" signal gets emitted when
	 * the holder's value changes.
	 *
	 * Since: 5.2.0
	 */
	g_object_class_install_property (object_class, PROP_VALIDATE_CHANGES,
					 g_param_spec_boolean ("validate-changes", NULL, "Defines if the validate-change signal is emitted on value change", TRUE,
							       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
271 272
}

273
static void
274
gda_holder_lockable_init (GdaLockableInterface *iface)
275
{
276 277 278
	iface->lock = gda_holder_lock;
	iface->trylock = gda_holder_trylock;
	iface->unlock = gda_holder_unlock;
279 280
}

281 282 283
static void
gda_holder_init (GdaHolder *holder)
{
284
	GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
285

286
	priv->id = g_strdup ("id");
287

288 289 290 291
	priv->g_type = GDA_TYPE_NULL;
	priv->full_bind = NULL;
	priv->simple_bind = NULL;
	priv->simple_bind_type_changed_id = 0;
292

293 294 295 296 297 298 299
	priv->invalid_forced = FALSE;
	priv->invalid_error = NULL;
	priv->valid = TRUE;
	priv->default_forced = FALSE;
	priv->is_freeable = TRUE;
	priv->value = NULL;
	priv->default_value = NULL;
300

301 302 303
	priv->not_null = FALSE;
	priv->source_model = NULL;
	priv->source_col = 0;
304

305
	g_rec_mutex_init (& (priv->mutex));
306

307
	priv->validate_changes = TRUE;
308 309 310
	priv->name = NULL;
	priv->desc = NULL;
	priv->plugin = NULL;
311 312 313
}

/**
314
 * gda_holder_new:
315
 * @type: the #GType requested
316
 * @id: an identifiation
317 318 319 320 321 322
 *
 * Creates a new holder of type @type
 *
 * Returns: a new #GdaHolder object
 */
GdaHolder *
323
gda_holder_new (GType type, const gchar *id)
324
{
325 326
	g_return_val_if_fail (id != NULL, NULL);
	return (GdaHolder*) g_object_new (GDA_TYPE_HOLDER, "g-type", type, "id", id, NULL);
327 328 329
}

/**
330
 * gda_holder_copy:
331 332 333
 * @orig: a #GdaHolder object to copy
 *
 * Copy constructor.
334
 * 
335
 * Note1: if @orig is set with a static value (see gda_holder_take_static_value()) 
336
 * its copy will have a fresh new allocated GValue, so that user should free it when done.
337
 *
Jonh Wendell's avatar
Jonh Wendell committed
338
 * Returns: (transfer full): a new #GdaHolder object
339 340 341 342 343 344
 */
GdaHolder *
gda_holder_copy (GdaHolder *orig)
{
	GObject *obj;
	GdaHolder *holder;
345
	gboolean allok = TRUE;
346 347

	g_return_val_if_fail (orig && GDA_IS_HOLDER (orig), NULL);
348
	GdaHolderPrivate *priv = gda_holder_get_instance_private (orig);
349

350
	gda_holder_lock ((GdaLockable*) orig);
351
	obj = g_object_new (GDA_TYPE_HOLDER, "g-type", priv->g_type, NULL);
352
	holder = GDA_HOLDER (obj);
353
	GdaHolderPrivate *cpriv = gda_holder_get_instance_private (holder);
354

355 356
	if (priv->id)
		cpriv->id = g_strdup (priv->id);
357 358 359 360 361 362
	if (priv->name)
		cpriv->name = g_strdup (priv->name);
	if (priv->desc)
		cpriv->desc = g_strdup (priv->desc);
	if (priv->plugin)
		cpriv->plugin = g_strdup (priv->plugin);
363

364 365 366 367
	if (priv->full_bind)
		gda_holder_set_full_bind (holder, priv->full_bind);
	if (priv->simple_bind)
		allok = gda_holder_set_bind (holder, priv->simple_bind, NULL);
368
	
369
	if (allok && priv->source_model) {
370
		/*g_print ("Source holder %p\n", holder);*/
371
		allok = gda_holder_set_source_model (holder, priv->source_model, priv->source_col,
372
						     NULL);
373 374
	}

375 376
	if (allok) {
		/* direct settings */
377 378 379 380 381 382 383 384 385 386 387
		cpriv->invalid_forced = priv->invalid_forced;
		if (priv->invalid_error)
			cpriv->invalid_error = g_error_copy (priv->invalid_error);
		cpriv->valid = priv->valid;
		cpriv->is_freeable = TRUE;
		cpriv->default_forced = priv->default_forced;
		if (priv->value)
			cpriv->value = gda_value_copy (priv->value);
		if (priv->default_value)
			cpriv->default_value = gda_value_copy (priv->default_value);
		cpriv->not_null = priv->not_null;
388

389
		gda_holder_unlock ((GdaLockable*) orig);
390 391 392 393 394
		return holder;
	}
	else {
		g_warning ("Internal error: could not copy GdaHolder (please report a bug).");
		g_object_unref (holder);
395
		gda_holder_unlock ((GdaLockable*) orig);
396 397
		return NULL;
	}
398 399 400
}

/**
401
 * gda_holder_new_inline:
402
 * @type: a valid GLib type
403
 * @id: (nullable): the id of the holder to create, or %NULL
404 405
 * @...: value to set
 *
Vivien Malerba's avatar
Vivien Malerba committed
406 407
 * Creates a new #GdaHolder object with an ID set to @id, of type @type, 
 * and containing the value passed as the last argument.
408
 *
409
 * Note that this function is a utility function and that only a limited set of types are supported. Trying
410 411 412 413 414 415 416 417 418
 * to use an unsupported type will result in a warning, and the returned value holder holding a safe default
 * value.
 *
 * Returns: a new #GdaHolder object
 */
GdaHolder *
gda_holder_new_inline (GType type, const gchar *id, ...)
{
	GdaHolder *holder;
419

420
	static GMutex serial_mutex;
421
	static guint serial = 0;
422 423 424
	const gchar *idm = NULL;

	g_print ("Creating inline: %s", id);
425

426 427 428 429 430 431 432
	if (id != NULL) {
		idm = id;
	} else {
		idm = g_strdup_printf ("%d", serial++);
	}

	holder = gda_holder_new (type, idm);
433
	GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
434 435 436
	if (holder) {
		GValue *value;
		va_list ap;
437
		GError *lerror = NULL;
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461

		va_start (ap, id);
		value = gda_value_new (type);
		if (type == G_TYPE_BOOLEAN) 
			g_value_set_boolean (value, va_arg (ap, int));
                else if (type == G_TYPE_STRING)
			g_value_set_string (value, va_arg (ap, gchar *));
                else if (type == G_TYPE_OBJECT)
			g_value_set_object (value, va_arg (ap, gpointer));
		else if (type == G_TYPE_INT)
			g_value_set_int (value, va_arg (ap, gint));
		else if (type == G_TYPE_UINT)
			g_value_set_uint (value, va_arg (ap, guint));
		else if (type == GDA_TYPE_BINARY)
			gda_value_set_binary (value, va_arg (ap, GdaBinary *));
		else if (type == G_TYPE_INT64)
			g_value_set_int64 (value, va_arg (ap, gint64));
		else if (type == G_TYPE_UINT64)
			g_value_set_uint64 (value, va_arg (ap, guint64));
		else if (type == GDA_TYPE_SHORT)
			gda_value_set_short (value, va_arg (ap, int));
		else if (type == GDA_TYPE_USHORT)
			gda_value_set_ushort (value, va_arg (ap, guint));
		else if (type == G_TYPE_CHAR)
462
			g_value_set_schar (value, va_arg (ap, int));
463 464 465 466 467 468
		else if (type == G_TYPE_UCHAR)
			g_value_set_uchar (value, va_arg (ap, guint));
		else if (type == G_TYPE_FLOAT)
			g_value_set_float (value, va_arg (ap, double));
		else if (type == G_TYPE_DOUBLE)
			g_value_set_double (value, va_arg (ap, gdouble));
Vivien Malerba's avatar
Vivien Malerba committed
469 470 471 472 473 474
		else if (type == G_TYPE_GTYPE)
			g_value_set_gtype (value, va_arg (ap, GType));
		else if (type == G_TYPE_LONG)
			g_value_set_long (value, va_arg (ap, glong));
		else if (type == G_TYPE_ULONG)
			g_value_set_ulong (value, va_arg (ap, gulong));
475 476 477 478
		else if (type == GDA_TYPE_NUMERIC)
			gda_value_set_numeric (value, va_arg (ap, GdaNumeric *));
		else if (type == G_TYPE_DATE)
			g_value_set_boxed (value, va_arg (ap, GDate *));
479
		else {
480 481
			g_warning ("%s() does not handle values of type %s, value will not be assigned.",
				   __FUNCTION__, g_type_name (type));
482 483 484
			g_object_unref (holder);
			holder = NULL;
		}
485 486
		va_end (ap);

487 488 489 490 491 492 493 494
		if (holder && !gda_holder_set_value (holder, value, &lerror)) {
			g_warning (_("Unable to set holder's value: %s"),
				   lerror && lerror->message ? lerror->message : _("No detail"));
			if (lerror)
				g_error_free (lerror);
			g_object_unref (holder);
			holder = NULL;
		}
495 496 497 498 499 500 501 502 503 504 505 506
		gda_value_free (value);
	}

	return holder;
}

static void
gda_holder_dispose (GObject *object)
{
	GdaHolder *holder;

	holder = GDA_HOLDER (object);
507 508
	GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
	if (priv) {
509
		gda_holder_set_bind (holder, NULL, NULL);
510 511
		gda_holder_set_full_bind (holder, NULL);

512 513 514
		if (priv->source_model) {
			g_object_unref (priv->source_model);
			priv->source_model = NULL;
515 516
		}

517
		priv->g_type = G_TYPE_INVALID;
518

519 520 521 522
		if (priv->value) {
			if (priv->is_freeable)
				gda_value_free (priv->value);
			priv->value = NULL;
523 524
		}

525 526 527
		if (priv->default_value) {
			gda_value_free (priv->default_value);
			priv->default_value = NULL;
528
		}
529

530 531 532
		if (priv->invalid_error) {
			g_error_free (priv->invalid_error);
			priv->invalid_error = NULL;
533
		}
534 535 536
	}

	/* parent class */
537
	G_OBJECT_CLASS (gda_holder_parent_class)->dispose (object);
538 539 540 541 542 543 544 545 546 547 548
}

static void
gda_holder_finalize (GObject   * object)
{
	GdaHolder *holder;

	g_return_if_fail (object != NULL);
	g_return_if_fail (GDA_IS_HOLDER (object));

	holder = GDA_HOLDER (object);
549
	GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
	if (priv->id != NULL) {
		g_free (priv->id);
		priv->id = NULL;
	}
	if (priv->name != NULL) {
		g_free (priv->name);
		priv->name = NULL;
	}
	if (priv->desc != NULL) {
		g_free (priv->desc);
		priv->desc = NULL;
	}
	if (priv->plugin != NULL) {
		g_free (priv->plugin);
		priv->plugin = NULL;
	}
566
	g_rec_mutex_clear (& (priv->mutex));
567 568

	/* parent class */
569
	G_OBJECT_CLASS (gda_holder_parent_class)->finalize (object);
570 571 572 573 574 575 576
}


static void 
gda_holder_set_property (GObject *object,
			 guint param_id,
			 const GValue *value,
577
			 GParamSpec *pspec)
578 579 580 581
{
	GdaHolder *holder;

	holder = GDA_HOLDER (object);
582 583
	GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
	if (priv) {
584 585
		switch (param_id) {
		case PROP_ID:
586 587 588 589
			if (priv->id != NULL) {
				g_free (priv->id);
				priv->id = NULL;
			}
590
			priv->id = g_value_dup_string (value);
591 592
			break;
		case PROP_NAME:
593 594 595 596 597 598
			if (priv->name != NULL) {
				g_free (priv->name);
				priv->name = NULL;
			}
			priv->name = g_value_dup_string (value);
      g_signal_emit (holder, gda_holder_signals[CHANGED], 0);
599 600
			break;
		case PROP_DESCR:
601 602 603 604 605 606 607 608 609 610 611 612 613 614
			if (priv->desc != NULL) {
				g_free (priv->desc);
				priv->desc = NULL;
			}
			priv->desc = g_value_dup_string (value);
      g_signal_emit (holder, gda_holder_signals[CHANGED], 0);
			break;
		case PROP_PLUGIN:
			if (priv->plugin != NULL) {
				g_free (priv->plugin);
				priv->plugin = NULL;
			}
			priv->plugin = g_value_dup_string (value);
      g_signal_emit (holder, gda_holder_signals[CHANGED], 0);
615 616
			break;
		case PROP_GDA_TYPE:
617 618
			if (priv->g_type == GDA_TYPE_NULL) {
				priv->g_type = g_value_get_gtype (value);
619 620
				g_object_notify ((GObject*) holder, "g-type");
			}
621 622
			else
				g_warning (_("The 'g-type' property cannot be changed"));
623 624 625
			break;
		case PROP_NOT_NULL: {
			gboolean not_null = g_value_get_boolean (value);
626 627
			if (not_null != priv->not_null) {
				priv->not_null = not_null;
628 629 630
				
				/* updating the holder's validity regarding the NULL value */
				if (!not_null && 
631 632
				    (!priv->value || GDA_VALUE_HOLDS_NULL (priv->value)))
					priv->valid = TRUE;
633 634
				
				if (not_null && 
635 636
				    (!priv->value || GDA_VALUE_HOLDS_NULL (priv->value)))
					priv->valid = FALSE;
637 638 639 640 641 642
				
				g_signal_emit (holder, gda_holder_signals[CHANGED], 0);
			}
			break;
		}
		case PROP_SIMPLE_BIND:
643
			if (!gda_holder_set_bind (holder, (GdaHolder*) g_value_get_object (value), NULL))
644
				g_warning ("Could not set the 'simple-bind' property");
645 646
			break;
		case PROP_FULL_BIND:
647
			gda_holder_set_full_bind (holder, (GdaHolder*) g_value_get_object (value));
648 649 650 651
			break;
		case PROP_SOURCE_MODEL: {
			GdaDataModel* ptr = g_value_get_object (value);
			g_return_if_fail (gda_holder_set_source_model (holder, 
652
								       (GdaDataModel *)ptr, -1, NULL));
653 654 655
			break;
                }
		case PROP_SOURCE_COLUMN:
656
			priv->source_col = g_value_get_int (value);
657
			break;
658
		case PROP_VALIDATE_CHANGES:
659
			priv->validate_changes = g_value_get_boolean (value);
660
			break;
661 662 663
		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
			break;
664 665 666 667 668 669 670 671
		}
	}
}

static void
gda_holder_get_property (GObject *object,
			 guint param_id,
			 GValue *value,
672
			 GParamSpec *pspec)
673 674
{
	GdaHolder *holder;
675
	const GValue *cvalue;
676 677

	holder = GDA_HOLDER (object);
678 679
	GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
	if (priv) {
680 681
		switch (param_id) {
		case PROP_ID:
682
			g_value_set_string (value, priv->id);
683 684
			break;
		case PROP_NAME:
685 686
			if (priv->name != NULL)
				g_value_set_string (value, priv->name);
687
			else
688
				g_value_set_string (value, priv->id);
689 690
			break;
		case PROP_DESCR:
691 692
			if (priv->desc != NULL)
				g_value_set_string (value, priv->desc);
693 694
			else
				g_value_set_string (value, NULL);
695
			break;
696 697 698 699 700 701
		case PROP_PLUGIN:
			if (priv->plugin != NULL)
				g_value_set_string (value, priv->desc);
			else
				g_value_set_string (value, NULL);
			break;
702
		case PROP_GDA_TYPE:
703
			g_value_set_gtype (value, priv->g_type);
704 705 706 707 708
			break;
		case PROP_NOT_NULL:
			g_value_set_boolean (value, gda_holder_get_not_null (holder));
			break;
		case PROP_SIMPLE_BIND:
709
			g_value_set_object (value, (GObject*) priv->simple_bind);
710 711
			break;
		case PROP_FULL_BIND:
712
			g_value_set_object (value, (GObject*) priv->full_bind);
713 714
			break;
		case PROP_SOURCE_MODEL:
715
			g_value_set_object (value, (GObject*) priv->source_model);
716 717
			break;
		case PROP_SOURCE_COLUMN:
718
			g_value_set_int (value, priv->source_col);
719 720
			break;
		case PROP_VALIDATE_CHANGES:
721
			g_value_set_boolean (value, priv->validate_changes);
722
			break;
723 724 725
		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
			break;
726 727 728 729 730
		}
	}
}

/**
731
 * gda_holder_get_g_type:
732 733 734 735
 * @holder: a #GdaHolder object
 * 
 * Get @holder's type
 *
736
 * Returns: the data type
737 738 739 740 741
 */
GType
gda_holder_get_g_type (GdaHolder *holder)
{
	g_return_val_if_fail (GDA_IS_HOLDER (holder), G_TYPE_INVALID);
742
	GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
743

744
	return priv->g_type;
745 746 747
}

/**
748
 * gda_holder_get_id:
749 750 751 752 753 754 755 756 757 758
 * @holder: a #GdaHolder object
 *
 * Get the ID of @holder. The ID can be set using @holder's "id" property
 *
 * Returns: the ID (don't modify the string).
 */
const gchar *
gda_holder_get_id (GdaHolder *holder)
{
	g_return_val_if_fail (GDA_IS_HOLDER (holder), NULL);
759
	GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
760

761
	return priv->id;
762 763 764 765
}


/**
766
 * gda_holder_get_value:
767 768 769 770 771
 * @holder: a #GdaHolder object
 *
 * Get the value held into the holder. If @holder is set to use its default value
 * and that default value is not of the same type as @holder, then %NULL is returned.
 *
772
 * If @holder is set to NULL, then the returned value is a #GDA_TYPE_NULL GValue.
773
 *
774 775
 * If @holder is invalid, then the returned value is %NULL.
 *
776
 * Returns: (nullable) (transfer none): the value, or %NULL
777 778 779 780 781
 */
const GValue *
gda_holder_get_value (GdaHolder *holder)
{
	g_return_val_if_fail (GDA_IS_HOLDER (holder), NULL);
782
	GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
783

784 785
	if (priv->full_bind)
		return gda_holder_get_value (priv->full_bind);
786
	else {
787
		if (priv->valid) {
788
			/* return default value if possible */
789 790 791 792
			if (priv->default_forced) {
				g_assert (priv->default_value);
				if (G_VALUE_TYPE (priv->default_value) == priv->g_type)
					return priv->default_value;
793 794 795 796
				else
					return NULL;
			}
			
797 798 799
			if (!priv->value)
				priv->value = gda_value_new_null ();
			return priv->value;
800
		}
801 802
		else
			return NULL;
803 804 805
	}
}

806
/**
807
 * gda_holder_get_value_str:
808
 * @holder: a #GdaHolder object
809
 * @dh: (nullable): a #GdaDataHandler to use, or %NULL
810 811 812 813
 *
 * Same functionality as gda_holder_get_value() except that it returns the value as a string
 * (the conversion is done using @dh if not %NULL, or the default data handler otherwise).
 *
814
 * Returns: (transfer full): the value, or %NULL
815 816 817 818 819 820 821
 */
gchar *
gda_holder_get_value_str (GdaHolder *holder, GdaDataHandler *dh)
{
	const GValue *current_val;

	g_return_val_if_fail (GDA_IS_HOLDER (holder), NULL);
822
	GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
823

824
	gda_holder_lock ((GdaLockable*) holder);
825
	current_val = gda_holder_get_value (holder);
826 827
        if (!current_val || GDA_VALUE_HOLDS_NULL (current_val)) {
		gda_holder_unlock ((GdaLockable*) holder);
828
                return NULL;
829
	}
830
        else {
831
		gchar *retval = NULL;
832
                if (!dh)
833
			dh = gda_data_handler_get_default (priv->g_type);
834
		if (dh)
835 836 837
                        retval = gda_data_handler_get_str_from_value (dh, current_val);
		gda_holder_unlock ((GdaLockable*) holder);
		return retval;
838 839 840
        }
}

841
static gboolean real_gda_holder_set_value (GdaHolder *holder, GValue *value, gboolean do_copy, GError **error);
842 843

/**
844
 * gda_holder_set_value:
845
 * @holder: a #GdaHolder object
846
 * @value: (nullable): a value to set the holder to, or %NULL
847
 * @error: a place to store errors, or %NULL
848 849 850 851
 *
 * Sets the value within the holder. If @holder is an alias for another
 * holder, then the value is also set for that other holder.
 *
852 853
 * On success, the action of any call to gda_holder_force_invalid() is cancelled
 * as soon as this method is called (even if @holder's value does not actually change)
854 855
 * 
 * If the value is not different from the one already contained within @holder,
856 857 858 859 860 861
 * then @holder is not changed and no signal is emitted.
 *
 * Note1: the @value argument is treated the same way if it is %NULL or if it is a #GDA_TYPE_NULL value
 *
 * Note2: if @holder can't accept the @value value, then this method returns FALSE, and @holder will be left
 * in an invalid state.
862
 *
863
 * Note3: before the change is accepted by @holder, the "validate-change" signal will be emitted (the value
864 865 866
 * of which can prevent the change from happening) which can be connected to to have a greater control
 * of which values @holder can have, or implement some business rules.
 *
867 868 869
 * Returns: TRUE if value has been set
 */
gboolean
870
gda_holder_set_value (GdaHolder *holder, const GValue *value, GError **error)
871 872 873
{
	g_return_val_if_fail (GDA_IS_HOLDER (holder), FALSE);

874
	return real_gda_holder_set_value (holder, (GValue*) value, TRUE, error);
875 876
}

877
/**
878
 * gda_holder_set_value_str:
879 880 881
 * @holder: a #GdaHolder object
 * @dh: a #GdaDataHandler to use, or %NULL
 * @value: a value to set the holder to, as a string
882
 * @error: a place to store errors, or %NULL
883 884 885 886 887
 *
 * Same functionality as gda_holder_set_value() except that it uses a string representation
 * of the value to set, which will be converted into a GValue first (using default data handler if
 * @dh is %NULL).
 *
888 889 890
 * Note1: if @value is %NULL or is the "NULL" string, then @holder's value is set to %NULL.
 * Note2: if @holder can't accept the @value value, then this method returns FALSE, and @holder will be left
 * in an invalid state.
891 892 893 894
 *
 * Returns: TRUE if value has been set
 */
gboolean
895
gda_holder_set_value_str (GdaHolder *holder, GdaDataHandler *dh, const gchar *value, GError **error)
896 897 898
{
	g_return_val_if_fail (GDA_IS_HOLDER (holder), FALSE);
	g_return_val_if_fail (!dh || GDA_IS_DATA_HANDLER (dh), FALSE);
899
	GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
900

901 902
	if (!value || !g_ascii_strcasecmp (value, "NULL")) 
                return gda_holder_set_value (holder, NULL, error);
903
	else {
904
		GValue *gdaval = NULL;
905 906 907
		gboolean retval = FALSE;

		gda_holder_lock ((GdaLockable*) holder);
908
		if (!dh)
909
			dh = gda_data_handler_get_default (priv->g_type);
910
		if (dh)
911
			gdaval = gda_data_handler_get_value_from_str (dh, value, priv->g_type);
912
		
913
		if (gdaval)
914 915
			retval = real_gda_holder_set_value (holder, gdaval, FALSE, error);
		else
916 917
			g_set_error (error, GDA_HOLDER_ERROR, GDA_HOLDER_STRING_CONVERSION_ERROR,
				     _("Unable to convert string to '%s' type"), 
918
				     gda_g_type_to_string (priv->g_type));
919 920
		gda_holder_unlock ((GdaLockable*) holder);
		return retval;
921
	}
922 923
}

924
/**
925
 * gda_holder_take_value:
926
 * @holder: a #GdaHolder object
927
 * @value: (transfer full): a value to set the holder to
928
 * @error: a place to store errors, or %NULL
929 930 931 932
 *
 * Sets the value within the holder. If @holder is an alias for another
 * holder, then the value is also set for that other holder.
 *
933 934
 * On success, the action of any call to gda_holder_force_invalid() is cancelled
 * as soon as this method is called (even if @holder's value does not actually change).
935 936
 * 
 * If the value is not different from the one already contained within @holder,
937
 * then @holder is not changed and no signal is emitted.
938
 *
939
 * Note1: if @holder can't accept the @value value, then this method returns FALSE, and @holder will be left
940 941
 * in an invalid state.
 *
942
 * Note2: before the change is accepted by @holder, the "validate-change" signal will be emitted (the value
943 944 945
 * of which can prevent the change from happening) which can be connected to to have a greater control
 * of which values @holder can have, or implement some business rules.
 *
946 947 948 949
 * Note3: if user previously set this holder with gda_holder_take_static_value () the GValue
 * stored internally will be forgiven and replaced by the @value. User should then
 * take care of the 'old' static GValue.
 *
950 951 952
 * Note4: in any case, the caller should not use @value anymore after this function returns because it may
 * have been freed. If necessary, use gda_holder_get_value() to get the real value.
 *
953 954 955
 * Returns: TRUE if value has been set
 */
gboolean
956
gda_holder_take_value (GdaHolder *holder, GValue *value, GError **error)
957 958 959
{
	g_return_val_if_fail (GDA_IS_HOLDER (holder), FALSE);

960
	return real_gda_holder_set_value (holder, (GValue*) value, FALSE, error);
961 962 963
}

static gboolean
964
real_gda_holder_set_value (GdaHolder *holder, GValue *value, gboolean do_copy, GError **error)
965
{
966
	GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
967 968 969
	gboolean changed = TRUE;
	gboolean newvalid;
	const GValue *current_val;
970
	gboolean newnull;
971
	gboolean was_valid;
972
	GValue *new_value = NULL;
973 974 975
#define DEBUG_HOLDER
#undef DEBUG_HOLDER

976 977
	gda_holder_lock ((GdaLockable*) holder);
	was_valid = gda_holder_is_valid (holder);
978

979 980 981
	/* if the value has been set with gda_holder_take_static_value () you'll be able
	 * to change the value only with another call to real_gda_holder_set_value 
	 */
982
	if (!priv->is_freeable) {
983
		gda_holder_unlock ((GdaLockable*) holder);
984 985 986
		g_warning (_("Can't use this method to set value because there is already a static value"));
		return FALSE;
	}
987 988 989 990 991 992 993 994 995 996 997
	// If value's type is compatible to current holder's value's type transform it
	if (value && priv->g_type != G_VALUE_TYPE (value)
	   && g_value_type_transformable (G_VALUE_TYPE (value), priv->g_type))
	{
		new_value = gda_value_new (priv->g_type);
		g_value_transform (value, new_value);
		if (!do_copy && value)
			gda_value_free (value);
	} else {
		new_value = value;
	}
998
	/* holder will be changed? */
999
	newnull = !new_value || GDA_VALUE_HOLDS_NULL (new_value);
1000
	current_val = gda_holder_get_value (holder);
1001
	if (current_val == new_value)
1002
		changed = FALSE;
1003
	else if ((!current_val || GDA_VALUE_HOLDS_NULL ((GValue *)current_val)) && newnull)
1004
		changed = FALSE;
1005 1006 1007
	else if (new_value && current_val &&
		 (G_VALUE_TYPE (new_value) == G_VALUE_TYPE ((GValue *)current_val)))
		changed = gda_value_differ (new_value, (GValue *)current_val);
1008 1009 1010
		
	/* holder's validity */
	newvalid = TRUE;
1011
	if (newnull && priv->not_null) {
1012
		g_set_error (error, GDA_HOLDER_ERROR, GDA_HOLDER_VALUE_NULL_ERROR,
1013
			     _("(%s): Holder does not allow NULL values"),
1014
			     priv->id);
1015 1016 1017
		newvalid = FALSE;
		changed = TRUE;
	}
1018
	else if (!newnull && (G_VALUE_TYPE (new_value) != priv->g_type)) {
1019
		g_set_error (error, GDA_HOLDER_ERROR, GDA_HOLDER_VALUE_TYPE_ERROR,
1020
			     _("(%s): Wrong Holder value type, expected type '%s' when value's type is '%s'"),
1021 1022
			     priv->id,
			     gda_g_type_to_string (priv->g_type),
1023
			     gda_g_type_to_string (G_VALUE_TYPE (new_value)));
1024
		newvalid = FALSE;
1025 1026
		changed = TRUE;
	}
1027

1028 1029 1030
	if (was_valid != newvalid)
		changed = TRUE;

1031
#ifdef DEBUG_HOLDER
1032
	g_print ("Holder to change %p (%s): value %s --> %s \t(type %d -> %d) VALID: %d->%d CHANGED: %d\n", 
1033
		 holder, priv->id,
1034
		 gda_value_stringify ((GValue *)current_val),
1035
		 gda_value_stringify ((new_value)),
1036
		 current_val ? G_VALUE_TYPE ((GValue *)current_val) : 0,
1037
		 new_value ? G_VALUE_TYPE (new_value) : 0,
1038 1039 1040 1041 1042
		 was_valid, newvalid, changed);
#endif

	/* end of procedure if the value has not been changed, after calculating the holder's validity */
	if (!changed) {
1043 1044
		if (!do_copy && new_value)
			gda_value_free (new_value);
1045 1046 1047 1048
		priv->invalid_forced = FALSE;
		if (priv->invalid_error) {
			g_error_free (priv->invalid_error);
			priv->invalid_error = NULL;
1049
		}
1050
		priv->valid = newvalid;
1051
		gda_holder_unlock ((GdaLockable*) holder);
1052 1053 1054
		return TRUE;
	}

1055
	/* check if we are allowed to change value */
1056
	if (priv->validate_changes) {
1057
		GError *lerror = NULL;
1058
		g_signal_emit (holder, gda_holder_signals[VALIDATE_CHANGE], 0, new_value, &lerror);
1059 1060
		if (lerror) {
			/* change refused by signal callback */
1061
#ifdef DEBUG_HOLDER
1062 1063
			g_print ("Holder change refused %p (ERROR %s)\n", holder,
				 lerror->message);
1064
#endif
1065 1066
			g_propagate_error (error, lerror);
			if (!do_copy) 
1067
				gda_value_free (new_value);
1068 1069 1070
			gda_holder_unlock ((GdaLockable*) holder);
			return FALSE;
		}
1071 1072 1073
	}

	/* new valid status */
1074 1075 1076 1077
	priv->invalid_forced = FALSE;
	if (priv->invalid_error) {
		g_error_free (priv->invalid_error);
		priv->invalid_error = NULL;
1078
	}
1079
	priv->valid = newvalid;
1080
	/* we're setting a non-static value, so be sure to flag is as freeable */
1081
	priv->is_freeable = TRUE;
1082 1083

	/* check is the new value is the default one */
1084 1085 1086 1087 1088
	priv->default_forced = FALSE;
	if (priv->default_value) {
		if ((G_VALUE_TYPE (priv->default_value) == GDA_TYPE_NULL) && newnull)
			priv->default_forced = TRUE;
		else if ((G_VALUE_TYPE (priv->default_value) == priv->g_type) &&
1089 1090
			 new_value && (G_VALUE_TYPE (new_value) == priv->g_type))
			priv->default_forced = !gda_value_compare (priv->default_value, new_value);
1091 1092 1093
	}

	/* real setting of the value */
1094
	if (priv->full_bind) {
1095 1096
#ifdef DEBUG_HOLDER
		g_print ("Holder %p is alias of holder %p => propagating changes to holder %p\n",
1097
			 holder, priv->full_bind, priv->full_bind);
1098
#endif
1099
		gda_holder_unlock ((GdaLockable*) holder);
1100
		return real_gda_holder_set_value (priv->full_bind, new_value, do_copy, error);
1101 1102
	}
	else {
1103 1104 1105
		if (priv->value) {
			gda_value_free (priv->value);
			priv->value = NULL;
1106 1107
		}

1108
		if (new_value) {
1109 1110
			if (newvalid) {
				if (do_copy)
1111
					priv->value = gda_value_copy (new_value);
1112
				else
1113
					priv->value = new_value;
1114 1115
			}
			else if (!do_copy) 
1116
				gda_value_free (new_value);
1117 1118
		}

1119
		gda_holder_unlock ((GdaLockable*) holder);
1120 1121 1122
		g_signal_emit (holder, gda_holder_signals[CHANGED], 0);
	}

1123
	return newvalid;
1124 1125
}

1126
static GValue *
1127 1128
real_gda_holder_set_const_value (GdaHolder *holder, const GValue *value, 
								 gboolean *value_changed, GError **error)
1129
{
1130 1131 1132
	g_return_val_if_fail (GDA_IS_HOLDER (holder), NULL);

	GdaHolderPrivate *priv = gda_holder_get_instance_private (holder);
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145
	gboolean changed = TRUE;
	gboolean newvalid;
	const GValue *current_val;
	GValue *value_to_return = NULL;
	gboolean newnull;
#define DEBUG_HOLDER
#undef DEBUG_HOLDER

#ifdef DEBUG_HOLDER
	gboolean was_valid = gda_holder_is_valid (holder);
#endif

	/* holder will be changed? */
1146
	newnull = !value || GDA_VALUE_HOLDS_NULL (value);
1147 1148 1149
	current_val = gda_holder_get_value (holder);
	if (current_val == value)
		changed = FALSE;
1150
	else if ((!current_val || GDA_VALUE_HOLDS_NULL (current_val)) && newnull) 
1151 1152
		changed = FALSE;
	else if (value && current_val &&
1153 1154
		 (G_VALUE_TYPE (value) == G_VALUE_TYPE (current_val))) 
		changed = gda_value_differ (value, current_val);
1155 1156 1157
		
	/* holder's validity */
	newvalid = TRUE;
1158
	if (newnull && priv->not_null) {
1159
		g_set_error (error, GDA_HOLDER_ERROR, GDA_HOLDER_VALUE_NULL_ERROR,
1160
			     _("(%s): Holder does not allow NULL values"),
1161
			     priv->id);
1162 1163 1164
		newvalid = FALSE;
		changed = TRUE;
	}
1165
	else if (!newnull && (G_VALUE_TYPE (value) != priv->g_type)) {
1166
		g_set_error (error, GDA_HOLDER_ERROR, GDA_HOLDER_VALUE_TYPE_ERROR,
1167
			     _("(%s): Wrong value type: expected type '%s' when value's type is '%s'"),
1168 1169
			     priv->id,
			     gda_g_type_to_string (priv->g_type),
1170 1171 1172 1173
			     gda_g_type_to_string (G_VALUE_TYPE (value)));
		newvalid = FALSE;
		changed = TRUE;
	}
1174

1175 1176
#ifdef DEBUG_HOLDER
	g_print ("Changed holder %p (%s): value %s --> %s \t(type %d -> %d) VALID: %d->%d CHANGED: %d\n", 
1177
		 holder, priv->id,
1178 1179 1180 1181 1182 1183
		 current_val ? gda_value_stringify ((GValue *)current_val) : "_NULL_",
		 value ? gda_value_stringify ((value)) : "_NULL_",
		 current_val ? G_VALUE_TYPE ((GValue *)current_val) : 0,
		 value ? G_VALUE_TYPE (value) : 0, 
		 was_valid, newvalid, changed);
#endif
1184
	
1185 1186 1187

	/* end of procedure if the value has not been changed, after calculating the holder's validity */
	if (!changed) {
1188 1189 1190 1191
		priv->invalid_forced = FALSE;
		if (priv->invalid_error) {
			g_error_free (priv->invalid_error);
			priv->invalid_error = NULL;
1192
		}
1193
		priv->valid = newvalid;
1194
#ifdef DEBUG_HOLDER		
1195
		g_print ("Holder is not changed");
1196 1197 1198 1199 1200 1201
#endif		
		/* set the changed status */
		*value_changed = FALSE;
	}
	else {
		*value_changed = TRUE;
1202 1203 1204
	}

	/* check if we are allowed to change value */
1205
	if (priv->validate_changes) {
1206 1207 1208 1209 1210 1211 1212
		GError *lerror = NULL;
		g_signal_emit (holder, gda_holder_signals[VALIDATE_CHANGE], 0, value, &lerror);
		if (lerror) {
			/* change refused by signal callback */
			g_propagate_error (error, lerror);
			return NULL;
		}
1213 1214 1215
	}

	/* new valid status */
1216 1217 1218 1219
	priv->invalid_forced = FALSE;
	if (priv->invalid_error) {
		g_error_free (priv->invalid_error);
		priv->invalid_error = NULL;