GValue* ast_db_event_new_entry_full(GdaConnection* dbConnection, gdouble time, const gchar* meta, const gchar* type, const gchar* subType, const gchar* state, gint sourceID, gpointer userID) {
	GValue* result = NULL;

	GValue* timeValue = gda_value_new(G_TYPE_DOUBLE);
	g_value_set_double(timeValue, time);

	GValue* metaValue = NULL;
	if (meta != NULL)
		metaValue = gda_value_new_from_string(meta, G_TYPE_STRING);
	else
		metaValue = gda_value_new_null();

	GValue* subTypeIDValue = ast_db_event_sub_types_get_or_register(dbConnection, subType, type);
	if (subTypeIDValue != NULL) {
		GValue* typeIDValue = ast_db_event_types_get_or_register(dbConnection, type);
		if (typeIDValue != NULL) {
			GValue* stateID = NULL;
			if (state != NULL) {
				stateID = ast_db_event_state_get_id(dbConnection, state);
			} else {
				stateID = gda_value_new_null();
			}

			if (stateID != NULL) {
				GValue* sourceIDValue = gda_value_new(G_TYPE_INT);
				g_value_set_int(sourceIDValue, sourceID);

				GValue* userIDValue = NULL;
				if (userID != NULL) {
					userIDValue = gda_value_new(G_TYPE_INT);
					g_value_set_int(userIDValue, GPOINTER_TO_INT(userID));
				} else {
					userIDValue = gda_value_new_null();
				}

				GdaStatement *stmt = NULL;
				GdaSet * set = NULL;
				GdaSet * lastRow = NULL;
				GdaHolder *p = NULL;
				GError * err = NULL;
				GObject * res = NULL;

				stmt = ast_db_common_get_statement(dbConnection, "INSERT INTO Events (time, meta, fk_EventTypes, fk_EventSubTypes, fk_EventState, fk_Sources, fk_Users ) VALUES ( ##the_time::gdouble , ##the_meta::string::null , ##the_type::gint , ##the_subtype::gint, ##the_state::gint::null, ##the_sourceID::gint, ##the_user::gint::null )");
				if (stmt != NULL) {
					gda_statement_get_parameters (stmt, &set, NULL);

					p = gda_set_get_holder (set, "the_time");
					gda_holder_set_value (p, timeValue, NULL);

					p = gda_set_get_holder (set, "the_meta");
					gda_holder_set_value (p, metaValue, NULL);

					p = gda_set_get_holder (set, "the_type");
					gda_holder_set_value (p, typeIDValue, NULL);

					p = gda_set_get_holder (set, "the_subtype");
					gda_holder_set_value (p, subTypeIDValue, NULL);

					p = gda_set_get_holder (set, "the_state");
					gda_holder_set_value (p, stateID, NULL);

					p = gda_set_get_holder (set, "the_sourceID");
					gda_holder_set_value (p, sourceIDValue, NULL);

					p = gda_set_get_holder (set, "the_user");
					gda_holder_set_value (p, userIDValue, NULL);

					res = gda_connection_statement_execute(dbConnection,stmt, set,GDA_STATEMENT_MODEL_RANDOM_ACCESS, &lastRow, &err);
					if ((res != NULL) && (err == NULL)) {
						GdaHolder *h = GDA_HOLDER(lastRow->holders->data);
						const GValue* holderValue = gda_holder_get_value(h);

						result = gda_value_new(G_TYPE_INT);
						g_value_set_int(result, g_value_get_int(holderValue));

						//Segmentation fault
						//g_object_unref(holderValue);
						g_object_unref(lastRow);
						g_object_unref(res);
					} else {
						g_error ("Could not INSERT data into the 'Events' table: %s\n",
								ast_error_get_error_message(err));
					}

					if (err != NULL)
						g_error_free(err);


					g_object_unref(set);
					g_object_unref(stmt);
				}

				gda_value_free(sourceIDValue);
				gda_value_free(userIDValue);
				gda_value_free(stateID);
			} else {
				g_critical("ast:db:Failed to get the event state. State: %s. SubType: %s. Type: %s.", type, subType, state);
			}
			gda_value_free(typeIDValue);
		} else {
			g_critical("Ast:DB: Failed to get the type ID. Type: %s", type);
		}
		gda_value_free(subTypeIDValue);
	} else {
		g_critical("Ast:DB:Failed to get the subType ID. SubType: %s. Type: %s.", subType, type);
	}

	gda_value_free(timeValue);
	gda_value_free(metaValue);
	return result;
}

