/* sqlheavy-row.c generated by valac 0.16.0, the Vala compiler
 * generated from sqlheavy-row.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include "SQLHeavy.h"
#include <stdlib.h>
#include <string.h>

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_string_free0(var) ((var == NULL) ? NULL : (var = (g_string_free (var, TRUE), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define __vala_GValue_free0(var) ((var == NULL) ? NULL : (var = (_vala_GValue_free (var), NULL)))
#define _g_value_array_free0(var) ((var == NULL) ? NULL : (var = (g_value_array_free (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _SQLHeavyRowPrivate {
	SQLHeavyTable* _table;
	gboolean _auto_save;
	gint64 _id;
	GValue** values;
	gint values_length1;
	gint _values_size_;
	GStaticRecMutex __lock_values;
	GValue** cache;
	gint cache_length1;
	gint _cache_size_;
	GStaticRecMutex __lock_cache;
	gboolean _enable_cache;
};


static gpointer sql_heavy_row_parent_class = NULL;
static SQLHeavyRecordIface* sql_heavy_row_sql_heavy_record_parent_iface = NULL;
static SQLHeavyMutableRecordIface* sql_heavy_row_sql_heavy_mutable_record_parent_iface = NULL;

#define SQL_HEAVY_ROW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SQL_HEAVY_TYPE_ROW, SQLHeavyRowPrivate))
enum  {
	SQL_HEAVY_ROW_DUMMY_PROPERTY,
	SQL_HEAVY_ROW_TABLE,
	SQL_HEAVY_ROW_AUTO_SAVE,
	SQL_HEAVY_ROW_ID,
	SQL_HEAVY_ROW_FIELD_COUNT,
	SQL_HEAVY_ROW_ENABLE_CACHE
};
void sql_heavy_table_unregister_row (SQLHeavyTable* self, SQLHeavyRow* row);
static void _vala_GValue_free (GValue* self);
static void sql_heavy_row_real_save (SQLHeavyMutableRecord* base, GError** error);
void sql_heavy_table_register_row (SQLHeavyTable* self, SQLHeavyRow* row);
void sql_heavy_row_update_cache (SQLHeavyRow* self, GError** error);
static gint sql_heavy_row_real_field_index (SQLHeavyRecord* base, const gchar* field, GError** error);
static gchar* sql_heavy_row_real_field_name (SQLHeavyRecord* base, gint field, GError** error);
static GType sql_heavy_row_real_field_type (SQLHeavyRecord* base, gint field, GError** error);
static void sql_heavy_row_real_put (SQLHeavyMutableRecord* base, gint field, GValue* value, GError** error);
static GValue* _g_value_dup (GValue* self);
void sql_heavy_row_on_delete (SQLHeavyRow* self);
static void sql_heavy_row_real_delete (SQLHeavyMutableRecord* base, GError** error);
static void sql_heavy_row_real_fetch (SQLHeavyRecord* base, gint field, GValue* result, GError** error);
static SQLHeavyRow* sql_heavy_row_real_fetch_foreign_row (SQLHeavyRecord* base, gint field, GError** error);
static SQLHeavyRow* sql_heavy_row_real_get_foreign_row (SQLHeavyRecord* base, const gchar* field, GError** error);
SQLHeavyQueryResult* sql_heavy_query_result_new_no_lock (SQLHeavyQuery* query, GError** error);
SQLHeavyQueryResult* sql_heavy_query_result_construct_no_lock (GType object_type, SQLHeavyQuery* query, GError** error);
gboolean sql_heavy_value_equal (GValue* a, GValue* b);
gint sql_heavy_row_direct_compare (SQLHeavyRow* a, SQLHeavyRow* b);
static GObject * sql_heavy_row_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static void _sql_heavy_row___lambda4_ (SQLHeavyRow* self);
void sql_heavy_database_add_step_unlock_notify_row (SQLHeavyDatabase* self, SQLHeavyRow* row);
static void __sql_heavy_row___lambda4__sql_heavy_row_changed (SQLHeavyRow* _sender, gpointer self);
static void _sql_heavy_row___lambda5_ (SQLHeavyRow* self, GParamSpec* pspec);
static void __sql_heavy_row___lambda5__g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self);
static void sql_heavy_row_finalize (GObject* obj);
static void _vala_sql_heavy_row_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_sql_heavy_row_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


static void _vala_GValue_free (GValue* self) {
	g_value_unset (self);
	g_free (self);
}


/**
     * {@inheritDoc}
     */
static const gchar* string_to_string (const gchar* self) {
	const gchar* result = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}


static void sql_heavy_row_real_save (SQLHeavyMutableRecord* base, GError** error) {
	SQLHeavyRow * self;
	GError * _inner_error_ = NULL;
	self = (SQLHeavyRow*) base;
	{
		GValue** _tmp0_;
		gint _tmp0__length1;
		_tmp0_ = self->priv->values;
		_tmp0__length1 = self->priv->values_length1;
		g_static_rec_mutex_lock (&self->priv->__lock_values);
		{
			GValue** _tmp1_;
			gint _tmp1__length1;
			gint field;
			SQLHeavyTable* _tmp3_;
			gint _tmp4_;
			gint _tmp5_;
			gint field_count;
			GString* _tmp6_;
			GString* sql;
			gboolean first_field;
			gint64 _tmp7_;
			SQLHeavyTable* _tmp67_;
			SQLHeavyQueryable* _tmp68_;
			SQLHeavyQueryable* _tmp69_;
			GString* _tmp70_;
			const gchar* _tmp71_;
			SQLHeavyQuery* _tmp72_;
			SQLHeavyQuery* query;
			gint64 _tmp92_;
			_tmp1_ = self->priv->values;
			_tmp1__length1 = self->priv->values_length1;
			if (_tmp1_ == NULL) {
				{
					GValue** _tmp2_;
					gint _tmp2__length1;
					_tmp2_ = self->priv->values;
					_tmp2__length1 = self->priv->values_length1;
					g_static_rec_mutex_unlock (&self->priv->__lock_values);
				}
				return;
			}
			field = 0;
			_tmp3_ = self->priv->_table;
			_tmp4_ = sql_heavy_table_get_field_count (_tmp3_);
			_tmp5_ = _tmp4_;
			field_count = _tmp5_;
			_tmp6_ = g_string_new ("");
			sql = _tmp6_;
			first_field = TRUE;
			_tmp7_ = self->priv->_id;
			if (_tmp7_ > ((gint64) 0)) {
				GString* _tmp8_;
				SQLHeavyTable* _tmp9_;
				const gchar* _tmp10_;
				const gchar* _tmp11_;
				GString* _tmp32_;
				_tmp8_ = sql;
				_tmp9_ = self->priv->_table;
				_tmp10_ = sql_heavy_table_get_name (_tmp9_);
				_tmp11_ = _tmp10_;
				g_string_printf (_tmp8_, "UPDATE `%s` SET ", _tmp11_);
				{
					gboolean _tmp12_;
					field = 0;
					_tmp12_ = TRUE;
					while (TRUE) {
						gboolean _tmp13_;
						gint _tmp15_;
						gint _tmp16_;
						GValue** _tmp17_;
						gint _tmp17__length1;
						gint _tmp18_;
						GValue* _tmp19_;
						_tmp13_ = _tmp12_;
						if (!_tmp13_) {
							gint _tmp14_;
							_tmp14_ = field;
							field = _tmp14_ + 1;
						}
						_tmp12_ = FALSE;
						_tmp15_ = field;
						_tmp16_ = field_count;
						if (!(_tmp15_ < _tmp16_)) {
							break;
						}
						_tmp17_ = self->priv->values;
						_tmp17__length1 = self->priv->values_length1;
						_tmp18_ = field;
						_tmp19_ = _tmp17_[_tmp18_];
						if (_tmp19_ != NULL) {
							gboolean _tmp20_;
							SQLHeavyTable* _tmp22_;
							gint _tmp23_;
							gchar* _tmp24_ = NULL;
							gchar* field_name;
							GString* _tmp25_;
							const gchar* _tmp26_;
							const gchar* _tmp27_ = NULL;
							const gchar* _tmp28_;
							const gchar* _tmp29_ = NULL;
							gchar* _tmp30_ = NULL;
							gchar* _tmp31_;
							_tmp20_ = first_field;
							if (!_tmp20_) {
								GString* _tmp21_;
								_tmp21_ = sql;
								g_string_append (_tmp21_, ", ");
							}
							_tmp22_ = self->priv->_table;
							_tmp23_ = field;
							_tmp24_ = sql_heavy_table_field_name (_tmp22_, _tmp23_, &_inner_error_);
							field_name = _tmp24_;
							if (_inner_error_ != NULL) {
								_g_string_free0 (sql);
								goto __finally28;
							}
							_tmp25_ = sql;
							_tmp26_ = field_name;
							_tmp27_ = string_to_string (_tmp26_);
							_tmp28_ = field_name;
							_tmp29_ = string_to_string (_tmp28_);
							_tmp30_ = g_strconcat ("`", _tmp27_, "` = :", _tmp29_, NULL);
							_tmp31_ = _tmp30_;
							g_string_append (_tmp25_, _tmp31_);
							_g_free0 (_tmp31_);
							first_field = FALSE;
							_g_free0 (field_name);
						}
					}
				}
				_tmp32_ = sql;
				g_string_append (_tmp32_, " WHERE `ROWID` = :ROWID;");
			} else {
				GString* _tmp33_;
				SQLHeavyTable* _tmp34_;
				const gchar* _tmp35_;
				const gchar* _tmp36_;
				GString* _tmp37_;
				GString* qvalues;
				GString* _tmp62_;
				GString* _tmp63_;
				GString* _tmp64_;
				const gchar* _tmp65_;
				GString* _tmp66_;
				_tmp33_ = sql;
				_tmp34_ = self->priv->_table;
				_tmp35_ = sql_heavy_table_get_name (_tmp34_);
				_tmp36_ = _tmp35_;
				g_string_printf (_tmp33_, "INSERT INTO `%s` (", _tmp36_);
				_tmp37_ = g_string_new ("");
				qvalues = _tmp37_;
				{
					gboolean _tmp38_;
					field = 0;
					_tmp38_ = TRUE;
					while (TRUE) {
						gboolean _tmp39_;
						gint _tmp41_;
						gint _tmp42_;
						GValue** _tmp43_;
						gint _tmp43__length1;
						gint _tmp44_;
						GValue* _tmp45_;
						_tmp39_ = _tmp38_;
						if (!_tmp39_) {
							gint _tmp40_;
							_tmp40_ = field;
							field = _tmp40_ + 1;
						}
						_tmp38_ = FALSE;
						_tmp41_ = field;
						_tmp42_ = field_count;
						if (!(_tmp41_ < _tmp42_)) {
							break;
						}
						_tmp43_ = self->priv->values;
						_tmp43__length1 = self->priv->values_length1;
						_tmp44_ = field;
						_tmp45_ = _tmp43_[_tmp44_];
						if (_tmp45_ != NULL) {
							gboolean _tmp46_;
							SQLHeavyTable* _tmp49_;
							gint _tmp50_;
							gchar* _tmp51_ = NULL;
							gchar* field_name;
							GString* _tmp52_;
							const gchar* _tmp53_;
							const gchar* _tmp54_ = NULL;
							gchar* _tmp55_ = NULL;
							gchar* _tmp56_;
							GString* _tmp57_;
							const gchar* _tmp58_;
							const gchar* _tmp59_ = NULL;
							gchar* _tmp60_ = NULL;
							gchar* _tmp61_;
							_tmp46_ = first_field;
							if (!_tmp46_) {
								GString* _tmp47_;
								GString* _tmp48_;
								_tmp47_ = sql;
								g_string_append (_tmp47_, ", ");
								_tmp48_ = qvalues;
								g_string_append (_tmp48_, ", ");
							}
							_tmp49_ = self->priv->_table;
							_tmp50_ = field;
							_tmp51_ = sql_heavy_table_field_name (_tmp49_, _tmp50_, &_inner_error_);
							field_name = _tmp51_;
							if (_inner_error_ != NULL) {
								_g_string_free0 (qvalues);
								_g_string_free0 (sql);
								goto __finally28;
							}
							_tmp52_ = sql;
							_tmp53_ = field_name;
							_tmp54_ = string_to_string (_tmp53_);
							_tmp55_ = g_strconcat ("`", _tmp54_, "`", NULL);
							_tmp56_ = _tmp55_;
							g_string_append (_tmp52_, _tmp56_);
							_g_free0 (_tmp56_);
							_tmp57_ = qvalues;
							_tmp58_ = field_name;
							_tmp59_ = string_to_string (_tmp58_);
							_tmp60_ = g_strconcat (":", _tmp59_, NULL);
							_tmp61_ = _tmp60_;
							g_string_append (_tmp57_, _tmp61_);
							_g_free0 (_tmp61_);
							first_field = FALSE;
							_g_free0 (field_name);
						}
					}
				}
				_tmp62_ = sql;
				g_string_append (_tmp62_, ") VALUES (");
				_tmp63_ = sql;
				_tmp64_ = qvalues;
				_tmp65_ = _tmp64_->str;
				g_string_append (_tmp63_, _tmp65_);
				_tmp66_ = sql;
				g_string_append (_tmp66_, ");");
				_g_string_free0 (qvalues);
			}
			_tmp67_ = self->priv->_table;
			_tmp68_ = sql_heavy_table_get_queryable (_tmp67_);
			_tmp69_ = _tmp68_;
			_tmp70_ = sql;
			_tmp71_ = _tmp70_->str;
			_tmp72_ = sql_heavy_query_new (_tmp69_, _tmp71_, &_inner_error_);
			query = _tmp72_;
			if (_inner_error_ != NULL) {
				_g_string_free0 (sql);
				goto __finally28;
			}
			{
				gboolean _tmp73_;
				field = 0;
				_tmp73_ = TRUE;
				while (TRUE) {
					gboolean _tmp74_;
					gint _tmp76_;
					gint _tmp77_;
					GValue** _tmp78_;
					gint _tmp78__length1;
					gint _tmp79_;
					GValue* _tmp80_;
					_tmp74_ = _tmp73_;
					if (!_tmp74_) {
						gint _tmp75_;
						_tmp75_ = field;
						field = _tmp75_ + 1;
					}
					_tmp73_ = FALSE;
					_tmp76_ = field;
					_tmp77_ = field_count;
					if (!(_tmp76_ < _tmp77_)) {
						break;
					}
					_tmp78_ = self->priv->values;
					_tmp78__length1 = self->priv->values_length1;
					_tmp79_ = field;
					_tmp80_ = _tmp78_[_tmp79_];
					if (_tmp80_ != NULL) {
						SQLHeavyTable* _tmp81_;
						gint _tmp82_;
						gchar* _tmp83_ = NULL;
						gchar* field_name;
						SQLHeavyQuery* _tmp84_;
						const gchar* _tmp85_;
						const gchar* _tmp86_ = NULL;
						gchar* _tmp87_ = NULL;
						gchar* _tmp88_;
						GValue** _tmp89_;
						gint _tmp89__length1;
						gint _tmp90_;
						GValue* _tmp91_;
						_tmp81_ = self->priv->_table;
						_tmp82_ = field;
						_tmp83_ = sql_heavy_table_field_name (_tmp81_, _tmp82_, &_inner_error_);
						field_name = _tmp83_;
						if (_inner_error_ != NULL) {
							_g_object_unref0 (query);
							_g_string_free0 (sql);
							goto __finally28;
						}
						_tmp84_ = query;
						_tmp85_ = field_name;
						_tmp86_ = string_to_string (_tmp85_);
						_tmp87_ = g_strconcat (":", _tmp86_, NULL);
						_tmp88_ = _tmp87_;
						_tmp89_ = self->priv->values;
						_tmp89__length1 = self->priv->values_length1;
						_tmp90_ = field;
						_tmp91_ = _tmp89_[_tmp90_];
						sql_heavy_query_set (_tmp84_, _tmp88_, _tmp91_, &_inner_error_);
						_g_free0 (_tmp88_);
						if (_inner_error_ != NULL) {
							_g_free0 (field_name);
							_g_object_unref0 (query);
							_g_string_free0 (sql);
							goto __finally28;
						}
						_g_free0 (field_name);
					}
				}
			}
			_tmp92_ = self->priv->_id;
			if (_tmp92_ > ((gint64) 0)) {
				SQLHeavyQuery* _tmp93_;
				gint64 _tmp94_;
				SQLHeavyQuery* _tmp95_;
				SQLHeavyQueryResult* _tmp96_ = NULL;
				SQLHeavyQueryResult* _tmp97_;
				_tmp93_ = query;
				_tmp94_ = self->priv->_id;
				sql_heavy_query_set_int64 (_tmp93_, ":ROWID", _tmp94_, &_inner_error_);
				if (_inner_error_ != NULL) {
					_g_object_unref0 (query);
					_g_string_free0 (sql);
					goto __finally28;
				}
				_tmp95_ = query;
				_tmp96_ = sql_heavy_query_execute (_tmp95_, NULL, &_inner_error_, NULL);
				_tmp97_ = _tmp96_;
				_g_object_unref0 (_tmp97_);
				if (_inner_error_ != NULL) {
					_g_object_unref0 (query);
					_g_string_free0 (sql);
					goto __finally28;
				}
			} else {
				SQLHeavyQuery* _tmp98_;
				gint64 _tmp99_ = 0LL;
				gint64 _tmp100_;
				SQLHeavyTable* _tmp101_;
				_tmp98_ = query;
				_tmp99_ = sql_heavy_query_execute_insert (_tmp98_, NULL, &_inner_error_, NULL);
				_tmp100_ = _tmp99_;
				if (_inner_error_ != NULL) {
					_g_object_unref0 (query);
					_g_string_free0 (sql);
					goto __finally28;
				}
				self->priv->_id = _tmp100_;
				_tmp101_ = self->priv->_table;
				sql_heavy_table_register_row (_tmp101_, self);
				sql_heavy_row_update_cache (self, &_inner_error_);
				if (_inner_error_ != NULL) {
					_g_object_unref0 (query);
					_g_string_free0 (sql);
					goto __finally28;
				}
			}
			self->priv->values = (_vala_array_free (self->priv->values, self->priv->values_length1, (GDestroyNotify) _vala_GValue_free), NULL);
			self->priv->values = NULL;
			self->priv->values_length1 = 0;
			self->priv->_values_size_ = self->priv->values_length1;
			_g_object_unref0 (query);
			_g_string_free0 (sql);
		}
		__finally28:
		{
			GValue** _tmp102_;
			gint _tmp102__length1;
			_tmp102_ = self->priv->values;
			_tmp102__length1 = self->priv->values_length1;
			g_static_rec_mutex_unlock (&self->priv->__lock_values);
		}
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				g_propagate_error (error, _inner_error_);
				return;
			} else {
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return;
			}
		}
	}
}


/**
     * {@inheritDoc}
     */
static gint sql_heavy_row_real_field_index (SQLHeavyRecord* base, const gchar* field, GError** error) {
	SQLHeavyRow * self;
	gint result = 0;
	SQLHeavyTable* _tmp0_;
	const gchar* _tmp1_;
	gint _tmp2_ = 0;
	gint _tmp3_;
	GError * _inner_error_ = NULL;
	self = (SQLHeavyRow*) base;
	g_return_val_if_fail (field != NULL, 0);
	_tmp0_ = self->priv->_table;
	_tmp1_ = field;
	_tmp2_ = sql_heavy_table_field_index (_tmp0_, _tmp1_, &_inner_error_);
	_tmp3_ = _tmp2_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			return 0;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
	}
	result = _tmp3_;
	return result;
}


/**
     * {@inheritDoc}
     */
static gchar* sql_heavy_row_real_field_name (SQLHeavyRecord* base, gint field, GError** error) {
	SQLHeavyRow * self;
	gchar* result = NULL;
	SQLHeavyTable* _tmp0_;
	gint _tmp1_;
	gchar* _tmp2_ = NULL;
	gchar* _tmp3_;
	GError * _inner_error_ = NULL;
	self = (SQLHeavyRow*) base;
	_tmp0_ = self->priv->_table;
	_tmp1_ = field;
	_tmp2_ = sql_heavy_table_field_name (_tmp0_, _tmp1_, &_inner_error_);
	_tmp3_ = _tmp2_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			return NULL;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	result = _tmp3_;
	return result;
}


/**
     * {@inheritDoc}
     */
static GType sql_heavy_row_real_field_type (SQLHeavyRecord* base, gint field, GError** error) {
	SQLHeavyRow * self;
	GType result = 0UL;
	gint _tmp0_;
	GValue _tmp1_ = {0};
	GValue _tmp2_;
	GType _tmp3_ = 0UL;
	GError * _inner_error_ = NULL;
	self = (SQLHeavyRow*) base;
	_tmp0_ = field;
	sql_heavy_record_fetch ((SQLHeavyRecord*) self, _tmp0_, &_tmp1_, &_inner_error_);
	_tmp2_ = _tmp1_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			return 0UL;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0UL;
		}
	}
	_tmp3_ = G_VALUE_TYPE (&_tmp2_);
	result = _tmp3_;
	return result;
}


/**
     * {@inheritDoc}
     */
static GValue* _g_value_dup (GValue* self) {
	return g_boxed_copy (G_TYPE_VALUE, self);
}


static gpointer __g_value_dup0 (gpointer self) {
	return self ? _g_value_dup (self) : NULL;
}


static void sql_heavy_row_real_put (SQLHeavyMutableRecord* base, gint field, GValue* value, GError** error) {
	SQLHeavyRow * self;
	SQLHeavyTable* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gint field_count;
	gboolean _tmp3_ = FALSE;
	gint _tmp4_;
	gboolean _tmp7_;
	GError * _inner_error_ = NULL;
	self = (SQLHeavyRow*) base;
	g_return_if_fail (value != NULL);
	_tmp0_ = self->priv->_table;
	_tmp1_ = sql_heavy_table_get_field_count (_tmp0_);
	_tmp2_ = _tmp1_;
	field_count = _tmp2_;
	_tmp4_ = field;
	if (_tmp4_ < 0) {
		_tmp3_ = TRUE;
	} else {
		gint _tmp5_;
		gint _tmp6_;
		_tmp5_ = field;
		_tmp6_ = field_count;
		_tmp3_ = _tmp5_ >= _tmp6_;
	}
	_tmp7_ = _tmp3_;
	if (_tmp7_) {
		gint _tmp8_;
		GError* _tmp9_;
		_tmp8_ = field;
		_tmp9_ = g_error_new (SQL_HEAVY_ERROR, SQL_HEAVY_ERROR_RANGE, "Invalid field index (%d)", _tmp8_);
		_inner_error_ = _tmp9_;
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			return;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	{
		GValue** _tmp10_;
		gint _tmp10__length1;
		_tmp10_ = self->priv->values;
		_tmp10__length1 = self->priv->values_length1;
		g_static_rec_mutex_lock (&self->priv->__lock_values);
		{
			GValue** _tmp11_;
			gint _tmp11__length1;
			GValue** _tmp14_;
			gint _tmp14__length1;
			gint _tmp15_;
			GValue _tmp16_;
			GValue _tmp17_;
			GValue* _tmp18_;
			GValue* _tmp19_;
			_tmp11_ = self->priv->values;
			_tmp11__length1 = self->priv->values_length1;
			if (_tmp11_ == NULL) {
				gint _tmp12_;
				GValue** _tmp13_ = NULL;
				_tmp12_ = field_count;
				_tmp13_ = g_new0 (GValue*, _tmp12_);
				self->priv->values = (_vala_array_free (self->priv->values, self->priv->values_length1, (GDestroyNotify) _vala_GValue_free), NULL);
				self->priv->values = _tmp13_;
				self->priv->values_length1 = _tmp12_;
				self->priv->_values_size_ = self->priv->values_length1;
			}
			_tmp14_ = self->priv->values;
			_tmp14__length1 = self->priv->values_length1;
			_tmp15_ = field;
			_tmp16_ = *value;
			_tmp17_ = _tmp16_;
			_tmp18_ = __g_value_dup0 (&_tmp17_);
			__vala_GValue_free0 (_tmp14_[_tmp15_]);
			_tmp14_[_tmp15_] = _tmp18_;
			_tmp19_ = _tmp14_[_tmp15_];
		}
		__finally29:
		{
			GValue** _tmp20_;
			gint _tmp20__length1;
			_tmp20_ = self->priv->values;
			_tmp20__length1 = self->priv->values_length1;
			g_static_rec_mutex_unlock (&self->priv->__lock_values);
		}
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				g_propagate_error (error, _inner_error_);
				return;
			} else {
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return;
			}
		}
	}
}


void sql_heavy_row_on_delete (SQLHeavyRow* self) {
	g_return_if_fail (self != NULL);
	self->priv->_id = (gint64) 0;
	g_signal_emit_by_name (self, "deleted");
}


/**
     * {@inheritDoc}
     *
     * @see deleted
     */
static void sql_heavy_row_real_delete (SQLHeavyMutableRecord* base, GError** error) {
	SQLHeavyRow * self;
	gint64 _tmp0_;
	GError * _inner_error_ = NULL;
	self = (SQLHeavyRow*) base;
	_tmp0_ = self->priv->_id;
	if (_tmp0_ > ((gint64) 0)) {
		SQLHeavyTable* _tmp1_;
		SQLHeavyQueryable* _tmp2_;
		SQLHeavyQueryable* _tmp3_;
		SQLHeavyTable* _tmp4_;
		const gchar* _tmp5_;
		const gchar* _tmp6_;
		const gchar* _tmp7_ = NULL;
		gchar* _tmp8_ = NULL;
		gchar* _tmp9_;
		SQLHeavyQuery* _tmp10_ = NULL;
		SQLHeavyQuery* _tmp11_;
		SQLHeavyQuery* query;
		SQLHeavyQuery* _tmp12_;
		gint64 _tmp13_;
		SQLHeavyQuery* _tmp14_;
		SQLHeavyQueryResult* _tmp15_ = NULL;
		SQLHeavyQueryResult* _tmp16_;
		_tmp1_ = self->priv->_table;
		_tmp2_ = sql_heavy_table_get_queryable (_tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = self->priv->_table;
		_tmp5_ = sql_heavy_table_get_name (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = string_to_string (_tmp6_);
		_tmp8_ = g_strconcat ("DELETE FROM `", _tmp7_, "` WHERE `ROWID` = :id;", NULL);
		_tmp9_ = _tmp8_;
		_tmp10_ = sql_heavy_queryable_prepare (_tmp3_, _tmp9_, &_inner_error_);
		_tmp11_ = _tmp10_;
		_g_free0 (_tmp9_);
		query = _tmp11_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				g_propagate_error (error, _inner_error_);
				return;
			} else {
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return;
			}
		}
		_tmp12_ = query;
		_tmp13_ = self->priv->_id;
		sql_heavy_query_set_int64 (_tmp12_, ":id", _tmp13_, &_inner_error_);
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				g_propagate_error (error, _inner_error_);
				_g_object_unref0 (query);
				return;
			} else {
				_g_object_unref0 (query);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return;
			}
		}
		_tmp14_ = query;
		_tmp15_ = sql_heavy_query_execute (_tmp14_, NULL, &_inner_error_, NULL);
		_tmp16_ = _tmp15_;
		_g_object_unref0 (_tmp16_);
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				g_propagate_error (error, _inner_error_);
				_g_object_unref0 (query);
				return;
			} else {
				_g_object_unref0 (query);
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return;
			}
		}
		_g_object_unref0 (query);
	}
}


/**
     * {@inheritDoc}
     */
static void sql_heavy_row_real_fetch (SQLHeavyRecord* base, gint field, GValue* result, GError** error) {
	SQLHeavyRow * self;
	gboolean _tmp0_ = FALSE;
	GValue** _tmp1_;
	gint _tmp1__length1;
	gboolean _tmp5_;
	gboolean _tmp10_ = FALSE;
	gboolean _tmp11_;
	gboolean _tmp15_;
	SQLHeavyTable* _tmp20_;
	gint _tmp21_;
	gchar* _tmp22_ = NULL;
	gchar* field_name;
	gint64 _tmp23_;
	SQLHeavyTable* _tmp26_;
	SQLHeavyQueryable* _tmp27_;
	SQLHeavyQueryable* _tmp28_;
	const gchar* _tmp29_;
	const gchar* _tmp30_ = NULL;
	SQLHeavyTable* _tmp31_;
	const gchar* _tmp32_;
	const gchar* _tmp33_;
	const gchar* _tmp34_ = NULL;
	gchar* _tmp35_ = NULL;
	gchar* _tmp36_;
	SQLHeavyQuery* _tmp37_;
	SQLHeavyQuery* _tmp38_;
	SQLHeavyQuery* query;
	SQLHeavyQuery* _tmp39_;
	gint64 _tmp40_;
	SQLHeavyQuery* _tmp41_;
	SQLHeavyQueryResult* _tmp42_ = NULL;
	SQLHeavyQueryResult* _tmp43_;
	SQLHeavyQueryResult* _tmp44_;
	GValue _tmp45_ = {0};
	GValue _tmp46_;
	GValue _tmp47_;
	GError * _inner_error_ = NULL;
	self = (SQLHeavyRow*) base;
	_tmp1_ = self->priv->values;
	_tmp1__length1 = self->priv->values_length1;
	if (_tmp1_ != NULL) {
		GValue** _tmp2_;
		gint _tmp2__length1;
		gint _tmp3_;
		GValue* _tmp4_;
		_tmp2_ = self->priv->values;
		_tmp2__length1 = self->priv->values_length1;
		_tmp3_ = field;
		_tmp4_ = _tmp2_[_tmp3_];
		_tmp0_ = _tmp4_ != NULL;
	} else {
		_tmp0_ = FALSE;
	}
	_tmp5_ = _tmp0_;
	if (_tmp5_) {
		GValue** _tmp6_;
		gint _tmp6__length1;
		gint _tmp7_;
		GValue* _tmp8_;
		GValue _tmp9_ = {0};
		_tmp6_ = self->priv->values;
		_tmp6__length1 = self->priv->values_length1;
		_tmp7_ = field;
		_tmp8_ = _tmp6_[_tmp7_];
		if (G_IS_VALUE (_tmp8_)) {
			g_value_init (&_tmp9_, G_VALUE_TYPE (_tmp8_));
			g_value_copy (_tmp8_, &_tmp9_);
		} else {
			_tmp9_ = *_tmp8_;
		}
		*result = _tmp9_;
		return;
	}
	_tmp11_ = self->priv->_enable_cache;
	if (_tmp11_) {
		GValue** _tmp12_;
		gint _tmp12__length1;
		gint _tmp13_;
		GValue* _tmp14_;
		_tmp12_ = self->priv->cache;
		_tmp12__length1 = self->priv->cache_length1;
		_tmp13_ = field;
		_tmp14_ = _tmp12_[_tmp13_];
		_tmp10_ = _tmp14_ != NULL;
	} else {
		_tmp10_ = FALSE;
	}
	_tmp15_ = _tmp10_;
	if (_tmp15_) {
		GValue** _tmp16_;
		gint _tmp16__length1;
		gint _tmp17_;
		GValue* _tmp18_;
		GValue _tmp19_ = {0};
		_tmp16_ = self->priv->cache;
		_tmp16__length1 = self->priv->cache_length1;
		_tmp17_ = field;
		_tmp18_ = _tmp16_[_tmp17_];
		if (G_IS_VALUE (_tmp18_)) {
			g_value_init (&_tmp19_, G_VALUE_TYPE (_tmp18_));
			g_value_copy (_tmp18_, &_tmp19_);
		} else {
			_tmp19_ = *_tmp18_;
		}
		*result = _tmp19_;
		return;
	}
	_tmp20_ = self->priv->_table;
	_tmp21_ = field;
	_tmp22_ = sql_heavy_table_field_name (_tmp20_, _tmp21_, &_inner_error_);
	field_name = _tmp22_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			return;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	_tmp23_ = self->priv->_id;
	if (_tmp23_ <= ((gint64) 0)) {
		const gchar* _tmp24_;
		GError* _tmp25_;
		_tmp24_ = field_name;
		_tmp25_ = g_error_new (SQL_HEAVY_ERROR, SQL_HEAVY_ERROR_MISUSE, "Cannot read field `%s` from row not persisted to database.", _tmp24_);
		_inner_error_ = _tmp25_;
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_free0 (field_name);
			return;
		} else {
			_g_free0 (field_name);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	_tmp26_ = self->priv->_table;
	_tmp27_ = sql_heavy_table_get_queryable (_tmp26_);
	_tmp28_ = _tmp27_;
	_tmp29_ = field_name;
	_tmp30_ = string_to_string (_tmp29_);
	_tmp31_ = self->priv->_table;
	_tmp32_ = sql_heavy_table_get_name (_tmp31_);
	_tmp33_ = _tmp32_;
	_tmp34_ = string_to_string (_tmp33_);
	_tmp35_ = g_strconcat ("SELECT `", _tmp30_, "` FROM `", _tmp34_, "` WHERE `ROWID` = :id;", NULL);
	_tmp36_ = _tmp35_;
	_tmp37_ = sql_heavy_query_new (_tmp28_, _tmp36_, &_inner_error_);
	_tmp38_ = _tmp37_;
	_g_free0 (_tmp36_);
	query = _tmp38_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_free0 (field_name);
			return;
		} else {
			_g_free0 (field_name);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	_tmp39_ = query;
	_tmp40_ = self->priv->_id;
	sql_heavy_query_set_int64 (_tmp39_, ":id", _tmp40_, &_inner_error_);
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (query);
			_g_free0 (field_name);
			return;
		} else {
			_g_object_unref0 (query);
			_g_free0 (field_name);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	_tmp41_ = query;
	_tmp42_ = sql_heavy_query_execute (_tmp41_, NULL, &_inner_error_, NULL);
	_tmp43_ = _tmp42_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (query);
			_g_free0 (field_name);
			return;
		} else {
			_g_object_unref0 (query);
			_g_free0 (field_name);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	_tmp44_ = _tmp43_;
	sql_heavy_record_fetch ((SQLHeavyRecord*) _tmp44_, 0, &_tmp45_, &_inner_error_);
	_tmp46_ = _tmp45_;
	_g_object_unref0 (_tmp44_);
	_tmp47_ = _tmp46_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (query);
			_g_free0 (field_name);
			return;
		} else {
			_g_object_unref0 (query);
			_g_free0 (field_name);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	*result = _tmp47_;
	_g_object_unref0 (query);
	_g_free0 (field_name);
	return;
}


/**
     * {@inheritDoc}
     */
static SQLHeavyRow* sql_heavy_row_real_fetch_foreign_row (SQLHeavyRecord* base, gint field, GError** error) {
	SQLHeavyRow * self;
	SQLHeavyRow* result = NULL;
	gint _tmp0_;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	SQLHeavyRow* _tmp4_ = NULL;
	SQLHeavyRow* _tmp5_;
	SQLHeavyRow* _tmp6_;
	GError * _inner_error_ = NULL;
	self = (SQLHeavyRow*) base;
	_tmp0_ = field;
	_tmp1_ = sql_heavy_record_field_name ((SQLHeavyRecord*) self, _tmp0_, &_inner_error_);
	_tmp2_ = _tmp1_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			return NULL;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	_tmp3_ = _tmp2_;
	_tmp4_ = sql_heavy_record_get_foreign_row ((SQLHeavyRecord*) self, _tmp3_, &_inner_error_);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	_tmp6_ = _tmp5_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			return NULL;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	result = _tmp6_;
	return result;
}


/**
     * {@inheritDoc}
     */
static SQLHeavyRow* sql_heavy_row_real_get_foreign_row (SQLHeavyRecord* base, const gchar* field, GError** error) {
	SQLHeavyRow * self;
	SQLHeavyRow* result = NULL;
	SQLHeavyTable* _tmp0_;
	const gchar* _tmp1_;
	gint _tmp2_ = 0;
	gint foreign_key_idx;
	SQLHeavyTable* _tmp3_;
	gint _tmp4_;
	SQLHeavyTable* _tmp5_ = NULL;
	SQLHeavyTable* foreign_table;
	const gchar* _tmp6_;
	gint64 _tmp7_ = 0LL;
	gint64 _tmp8_;
	SQLHeavyTable* _tmp9_;
	SQLHeavyRow* _tmp10_;
	GError * _inner_error_ = NULL;
	self = (SQLHeavyRow*) base;
	g_return_val_if_fail (field != NULL, NULL);
	_tmp0_ = self->priv->_table;
	_tmp1_ = field;
	_tmp2_ = sql_heavy_table_foreign_key_index (_tmp0_, _tmp1_, &_inner_error_);
	foreign_key_idx = _tmp2_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			return NULL;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	_tmp3_ = self->priv->_table;
	_tmp4_ = foreign_key_idx;
	_tmp5_ = sql_heavy_table_foreign_key_table (_tmp3_, _tmp4_, &_inner_error_);
	foreign_table = _tmp5_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			return NULL;
		} else {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	_tmp6_ = field;
	_tmp7_ = sql_heavy_record_get_int64 ((SQLHeavyRecord*) self, _tmp6_, &_inner_error_);
	_tmp8_ = _tmp7_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (foreign_table);
			return NULL;
		} else {
			_g_object_unref0 (foreign_table);
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return NULL;
		}
	}
	_tmp9_ = foreign_table;
	_tmp10_ = sql_heavy_row_new (_tmp9_, _tmp8_);
	result = _tmp10_;
	_g_object_unref0 (foreign_table);
	return result;
}


/**
     * Updates the cache of the row
     */
void sql_heavy_row_update_cache (SQLHeavyRow* self, GError** error) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	{
		GValue** _tmp0_;
		gint _tmp0__length1;
		_tmp0_ = self->priv->cache;
		_tmp0__length1 = self->priv->cache_length1;
		g_static_rec_mutex_lock (&self->priv->__lock_cache);
		{
			gint64 _tmp1_;
			gint fc = 0;
			gboolean _tmp3_;
			SQLHeavyTable* _tmp10_;
			SQLHeavyQueryable* _tmp11_;
			SQLHeavyQueryable* _tmp12_;
			SQLHeavyTable* _tmp13_;
			const gchar* _tmp14_;
			const gchar* _tmp15_;
			const gchar* _tmp16_ = NULL;
			gchar* _tmp17_ = NULL;
			gchar* _tmp18_;
			SQLHeavyQuery* _tmp19_;
			SQLHeavyQuery* _tmp20_;
			SQLHeavyQuery* query;
			SQLHeavyQuery* _tmp21_;
			gint64 _tmp22_;
			SQLHeavyQuery* _tmp23_;
			SQLHeavyQueryResult* _tmp24_;
			SQLHeavyQueryResult* _tmp25_;
			SQLHeavyQueryResult* _tmp26_;
			GValueArray* _tmp27_ = NULL;
			GValueArray* _tmp28_;
			GValueArray* res;
			gint _tmp29_;
			gboolean* _tmp30_ = NULL;
			gboolean* fields_changed;
			gint fields_changed_length1;
			gint _fields_changed_size_;
			gint f;
			_tmp1_ = self->priv->_id;
			if (_tmp1_ == ((gint64) 0)) {
				{
					GValue** _tmp2_;
					gint _tmp2__length1;
					_tmp2_ = self->priv->cache;
					_tmp2__length1 = self->priv->cache_length1;
					g_static_rec_mutex_unlock (&self->priv->__lock_cache);
				}
				return;
			}
			_tmp3_ = self->priv->_enable_cache;
			if (!_tmp3_) {
				self->priv->cache = (_vala_array_free (self->priv->cache, self->priv->cache_length1, (GDestroyNotify) _vala_GValue_free), NULL);
				self->priv->cache = NULL;
				self->priv->cache_length1 = 0;
				self->priv->_cache_size_ = self->priv->cache_length1;
				{
					GValue** _tmp4_;
					gint _tmp4__length1;
					_tmp4_ = self->priv->cache;
					_tmp4__length1 = self->priv->cache_length1;
					g_static_rec_mutex_unlock (&self->priv->__lock_cache);
				}
				return;
			} else {
				gint _tmp5_;
				gint _tmp6_;
				GValue** _tmp7_;
				gint _tmp7__length1;
				_tmp5_ = sql_heavy_record_get_field_count ((SQLHeavyRecord*) self);
				_tmp6_ = _tmp5_;
				fc = _tmp6_;
				_tmp7_ = self->priv->cache;
				_tmp7__length1 = self->priv->cache_length1;
				if (_tmp7_ == NULL) {
					gint _tmp8_;
					GValue** _tmp9_ = NULL;
					_tmp8_ = fc;
					_tmp9_ = g_new0 (GValue*, _tmp8_);
					self->priv->cache = (_vala_array_free (self->priv->cache, self->priv->cache_length1, (GDestroyNotify) _vala_GValue_free), NULL);
					self->priv->cache = _tmp9_;
					self->priv->cache_length1 = _tmp8_;
					self->priv->_cache_size_ = self->priv->cache_length1;
				}
			}
			_tmp10_ = self->priv->_table;
			_tmp11_ = sql_heavy_table_get_queryable (_tmp10_);
			_tmp12_ = _tmp11_;
			_tmp13_ = self->priv->_table;
			_tmp14_ = sql_heavy_table_get_name (_tmp13_);
			_tmp15_ = _tmp14_;
			_tmp16_ = string_to_string (_tmp15_);
			_tmp17_ = g_strconcat ("SELECT * FROM `", _tmp16_, "` WHERE `ROWID` = :id;", NULL);
			_tmp18_ = _tmp17_;
			_tmp19_ = sql_heavy_query_new (_tmp12_, _tmp18_, &_inner_error_);
			_tmp20_ = _tmp19_;
			_g_free0 (_tmp18_);
			query = _tmp20_;
			if (_inner_error_ != NULL) {
				goto __finally30;
			}
			_tmp21_ = query;
			_tmp22_ = self->priv->_id;
			sql_heavy_query_set_int64 (_tmp21_, ":id", _tmp22_, &_inner_error_);
			if (_inner_error_ != NULL) {
				_g_object_unref0 (query);
				goto __finally30;
			}
			_tmp23_ = query;
			_tmp24_ = sql_heavy_query_result_new_no_lock (_tmp23_, &_inner_error_);
			_tmp25_ = _tmp24_;
			if (_inner_error_ != NULL) {
				_g_object_unref0 (query);
				goto __finally30;
			}
			_tmp26_ = _tmp25_;
			_tmp27_ = sql_heavy_record_fetch_row ((SQLHeavyRecord*) _tmp26_, &_inner_error_);
			_tmp28_ = _tmp27_;
			_g_object_unref0 (_tmp26_);
			res = _tmp28_;
			if (_inner_error_ != NULL) {
				_g_object_unref0 (query);
				goto __finally30;
			}
			_tmp29_ = fc;
			_tmp30_ = g_new0 (gboolean, _tmp29_);
			fields_changed = _tmp30_;
			fields_changed_length1 = _tmp29_;
			_fields_changed_size_ = fields_changed_length1;
			f = 0;
			{
				gboolean _tmp31_;
				f = 0;
				_tmp31_ = TRUE;
				while (TRUE) {
					gboolean _tmp32_;
					gint _tmp34_;
					gint _tmp35_;
					gboolean _tmp36_ = FALSE;
					GValue** _tmp37_;
					gint _tmp37__length1;
					gint _tmp38_;
					GValue* _tmp39_;
					gboolean _tmp49_;
					_tmp32_ = _tmp31_;
					if (!_tmp32_) {
						gint _tmp33_;
						_tmp33_ = f;
						f = _tmp33_ + 1;
					}
					_tmp31_ = FALSE;
					_tmp34_ = f;
					_tmp35_ = fc;
					if (!(_tmp34_ < _tmp35_)) {
						break;
					}
					_tmp37_ = self->priv->cache;
					_tmp37__length1 = self->priv->cache_length1;
					_tmp38_ = f;
					_tmp39_ = _tmp37_[_tmp38_];
					if (_tmp39_ == NULL) {
						_tmp36_ = TRUE;
					} else {
						GValue** _tmp40_;
						gint _tmp40__length1;
						gint _tmp41_;
						GValue* _tmp42_;
						GValueArray* _tmp43_;
						GValue* _tmp44_;
						gint _tmp44__length1;
						gint _tmp45_;
						GValue _tmp46_;
						GValue _tmp47_;
						gboolean _tmp48_ = FALSE;
						_tmp40_ = self->priv->cache;
						_tmp40__length1 = self->priv->cache_length1;
						_tmp41_ = f;
						_tmp42_ = _tmp40_[_tmp41_];
						_tmp43_ = res;
						_tmp44_ = _tmp43_->values;
						_tmp44__length1 = (gint) _tmp43_->n_values;
						_tmp45_ = f;
						_tmp46_ = _tmp44_[_tmp45_];
						_tmp47_ = *_tmp42_;
						_tmp48_ = sql_heavy_value_equal (&_tmp47_, &_tmp46_);
						_tmp36_ = !_tmp48_;
					}
					_tmp49_ = _tmp36_;
					if (_tmp49_) {
						gboolean* _tmp50_;
						gint _tmp50__length1;
						gint _tmp51_;
						GValue** _tmp52_;
						gint _tmp52__length1;
						gint _tmp53_;
						GValue* _tmp54_;
						gboolean _tmp55_;
						GValue** _tmp56_;
						gint _tmp56__length1;
						gint _tmp57_;
						GValueArray* _tmp58_;
						GValue* _tmp59_;
						gint _tmp59__length1;
						gint _tmp60_;
						GValue _tmp61_;
						GValue _tmp62_;
						GValue* _tmp63_;
						GValue* _tmp64_;
						_tmp50_ = fields_changed;
						_tmp50__length1 = fields_changed_length1;
						_tmp51_ = f;
						_tmp52_ = self->priv->cache;
						_tmp52__length1 = self->priv->cache_length1;
						_tmp53_ = f;
						_tmp54_ = _tmp52_[_tmp53_];
						_tmp50_[_tmp51_] = _tmp54_ != NULL;
						_tmp55_ = _tmp50_[_tmp51_];
						_tmp56_ = self->priv->cache;
						_tmp56__length1 = self->priv->cache_length1;
						_tmp57_ = f;
						_tmp58_ = res;
						_tmp59_ = _tmp58_->values;
						_tmp59__length1 = (gint) _tmp58_->n_values;
						_tmp60_ = f;
						_tmp61_ = _tmp59_[_tmp60_];
						_tmp62_ = _tmp61_;
						_tmp63_ = __g_value_dup0 (&_tmp62_);
						__vala_GValue_free0 (_tmp56_[_tmp57_]);
						_tmp56_[_tmp57_] = _tmp63_;
						_tmp64_ = _tmp56_[_tmp57_];
					} else {
						gboolean* _tmp65_;
						gint _tmp65__length1;
						gint _tmp66_;
						gboolean _tmp67_;
						_tmp65_ = fields_changed;
						_tmp65__length1 = fields_changed_length1;
						_tmp66_ = f;
						_tmp65_[_tmp66_] = FALSE;
						_tmp67_ = _tmp65_[_tmp66_];
					}
				}
			}
			{
				gboolean _tmp68_;
				f = 0;
				_tmp68_ = TRUE;
				while (TRUE) {
					gboolean _tmp69_;
					gint _tmp71_;
					gint _tmp72_;
					gboolean* _tmp73_;
					gint _tmp73__length1;
					gint _tmp74_;
					gboolean _tmp75_;
					_tmp69_ = _tmp68_;
					if (!_tmp69_) {
						gint _tmp70_;
						_tmp70_ = f;
						f = _tmp70_ + 1;
					}
					_tmp68_ = FALSE;
					_tmp71_ = f;
					_tmp72_ = fc;
					if (!(_tmp71_ < _tmp72_)) {
						break;
					}
					_tmp73_ = fields_changed;
					_tmp73__length1 = fields_changed_length1;
					_tmp74_ = f;
					_tmp75_ = _tmp73_[_tmp74_];
					if (_tmp75_) {
						gint _tmp76_;
						_tmp76_ = f;
						g_signal_emit_by_name (self, "field-changed", _tmp76_);
					}
				}
			}
			fields_changed = (g_free (fields_changed), NULL);
			_g_value_array_free0 (res);
			_g_object_unref0 (query);
		}
		__finally30:
		{
			GValue** _tmp77_;
			gint _tmp77__length1;
			_tmp77_ = self->priv->cache;
			_tmp77__length1 = self->priv->cache_length1;
			g_static_rec_mutex_unlock (&self->priv->__lock_cache);
		}
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				g_propagate_error (error, _inner_error_);
				return;
			} else {
				g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
				return;
			}
		}
	}
}


/**
     * Compare two rows
     *
     * @param a the first row
     * @param b the second row
     * @return less than, equal to, or greater than 0 depending on a's relationship to b
     */
gint sql_heavy_row_compare (SQLHeavyRow* a, SQLHeavyRow* b) {
	gint result = 0;
	gint r;
	SQLHeavyRow* _tmp0_;
	SQLHeavyRow* _tmp1_;
	SQLHeavyRow* _tmp2_;
	SQLHeavyRow* _tmp3_;
	SQLHeavyRow* _tmp4_;
	SQLHeavyTable* _tmp5_;
	SQLHeavyRow* _tmp6_;
	SQLHeavyTable* _tmp7_;
	gint _tmp8_ = 0;
	gint _tmp9_;
	SQLHeavyRow* _tmp10_;
	gint64 _tmp11_;
	gint64 _tmp12_;
	SQLHeavyRow* _tmp13_;
	gint64 _tmp14_;
	gint64 _tmp15_;
	gint _tmp16_;
	gint _tmp17_;
	gint64 _tmp18_ = 0LL;
	gint _tmp19_;
	SQLHeavyRow* _tmp20_;
	SQLHeavyRow* _tmp21_;
	gint _tmp22_ = 0;
	r = 0;
	_tmp0_ = a;
	_tmp1_ = b;
	if (_tmp0_ == _tmp1_) {
		result = 0;
		return result;
	}
	_tmp2_ = a;
	if (_tmp2_ == NULL) {
		result = -1;
		return result;
	}
	_tmp3_ = b;
	if (_tmp3_ == NULL) {
		result = 1;
		return result;
	}
	_tmp4_ = a;
	_tmp5_ = _tmp4_->priv->_table;
	_tmp6_ = b;
	_tmp7_ = _tmp6_->priv->_table;
	_tmp8_ = sql_heavy_table_compare (_tmp5_, _tmp7_);
	r = _tmp8_;
	_tmp9_ = r;
	if (_tmp9_ != 0) {
		result = r;
		return result;
	}
	_tmp10_ = a;
	_tmp11_ = sql_heavy_row_get_id (_tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = b;
	_tmp14_ = sql_heavy_row_get_id (_tmp13_);
	_tmp15_ = _tmp14_;
	_tmp16_ = G_MININT;
	_tmp17_ = G_MAXINT;
	_tmp18_ = CLAMP (_tmp12_ - _tmp15_, (gint64) _tmp16_, (gint64) _tmp17_);
	r = (gint) _tmp18_;
	_tmp19_ = r;
	if (_tmp19_ != 0) {
		result = r;
		return result;
	}
	_tmp20_ = a;
	_tmp21_ = b;
	_tmp22_ = sql_heavy_row_direct_compare (_tmp20_, _tmp21_);
	result = _tmp22_;
	return result;
}


/**
     * Compare row pointers directly
     *
     * @param a the first row
     * @param b the second row
     * @return less than, equal to, or greater than 0 depending on a's relationship to b
     */
gint sql_heavy_row_direct_compare (SQLHeavyRow* a, SQLHeavyRow* b) {
	gint result = 0;
	SQLHeavyRow* _tmp0_;
	SQLHeavyRow* _tmp1_;
	_tmp0_ = a;
	_tmp1_ = b;
	result = (gint) (((gulong) _tmp0_) - ((gulong) _tmp1_));
	return result;
}


/**
     * Create or load a row from a table
     *
     * Note that you must call {@link save} in order for a new row
     * to be written to the queryable
     *
     * @param table the table to load the row from
     * @param id row ID, or 0 to create a new row
     */
SQLHeavyRow* sql_heavy_row_construct (GType object_type, SQLHeavyTable* table, gint64 id) {
	SQLHeavyRow * self = NULL;
	SQLHeavyTable* _tmp0_;
	gint64 _tmp1_;
	g_return_val_if_fail (table != NULL, NULL);
	_tmp0_ = table;
	_tmp1_ = id;
	self = (SQLHeavyRow*) g_object_new (object_type, "table", _tmp0_, "id", _tmp1_, NULL);
	return self;
}


SQLHeavyRow* sql_heavy_row_new (SQLHeavyTable* table, gint64 id) {
	return sql_heavy_row_construct (SQL_HEAVY_TYPE_ROW, table, id);
}


SQLHeavyTable* sql_heavy_row_get_table (SQLHeavyRow* self) {
	SQLHeavyTable* result;
	SQLHeavyTable* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_table;
	result = _tmp0_;
	return result;
}


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


static void sql_heavy_row_set_table (SQLHeavyRow* self, SQLHeavyTable* value) {
	SQLHeavyTable* _tmp0_;
	SQLHeavyTable* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->_table);
	self->priv->_table = _tmp1_;
	g_object_notify ((GObject *) self, "table");
}


gboolean sql_heavy_row_get_auto_save (SQLHeavyRow* self) {
	gboolean result;
	gboolean _tmp0_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_auto_save;
	result = _tmp0_;
	return result;
}


void sql_heavy_row_set_auto_save (SQLHeavyRow* self, gboolean value) {
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	self->priv->_auto_save = _tmp0_;
	g_object_notify ((GObject *) self, "auto-save");
}


gint64 sql_heavy_row_get_id (SQLHeavyRow* self) {
	gint64 result;
	gint64 _tmp0_;
	g_return_val_if_fail (self != NULL, 0LL);
	_tmp0_ = self->priv->_id;
	result = _tmp0_;
	return result;
}


static void sql_heavy_row_set_id (SQLHeavyRow* self, gint64 value) {
	gint64 _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	self->priv->_id = _tmp0_;
	g_object_notify ((GObject *) self, "id");
}


static gint sql_heavy_row_real_get_field_count (SQLHeavyRecord* base) {
	gint result;
	SQLHeavyRow* self;
	SQLHeavyTable* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	self = (SQLHeavyRow*) base;
	_tmp0_ = self->priv->_table;
	_tmp1_ = sql_heavy_table_get_field_count (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}


gboolean sql_heavy_row_get_enable_cache (SQLHeavyRow* self) {
	gboolean result;
	gboolean _tmp0_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_enable_cache;
	result = _tmp0_;
	return result;
}


void sql_heavy_row_set_enable_cache (SQLHeavyRow* self, gboolean value) {
	gboolean _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	self->priv->_enable_cache = _tmp0_;
	g_object_notify ((GObject *) self, "enable-cache");
}


static void _sql_heavy_row___lambda4_ (SQLHeavyRow* self) {
	SQLHeavyTable* _tmp0_;
	SQLHeavyQueryable* _tmp1_;
	SQLHeavyQueryable* _tmp2_;
	SQLHeavyDatabase* _tmp3_;
	SQLHeavyDatabase* _tmp4_;
	SQLHeavyDatabase* _tmp5_;
	_tmp0_ = self->priv->_table;
	_tmp1_ = sql_heavy_table_get_queryable (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = sql_heavy_queryable_get_database (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _tmp4_;
	sql_heavy_database_add_step_unlock_notify_row (_tmp5_, self);
	_g_object_unref0 (_tmp5_);
}


static void __sql_heavy_row___lambda4__sql_heavy_row_changed (SQLHeavyRow* _sender, gpointer self) {
	_sql_heavy_row___lambda4_ (self);
}


static void _sql_heavy_row___lambda5_ (SQLHeavyRow* self, GParamSpec* pspec) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (pspec != NULL);
	{
		sql_heavy_row_update_cache (self, &_inner_error_);
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch32_sql_heavy_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return;
		}
	}
	goto __finally32;
	__catch32_sql_heavy_error:
	{
		GError* e = NULL;
		const gchar* _tmp0_ = NULL;
		gboolean _tmp1_;
		const gchar* _tmp2_;
		GError* _tmp3_;
		const gchar* _tmp4_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp1_ = self->priv->_enable_cache;
		if (_tmp1_) {
			_tmp0_ = "enable";
		} else {
			_tmp0_ = "disable";
		}
		_tmp2_ = _tmp0_;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		g_warning ("sqlheavy-row.vala:336: Unable to %s cache: %s", _tmp2_, _tmp4_);
		_g_error_free0 (e);
	}
	__finally32:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
}


static void __sql_heavy_row___lambda5__g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self) {
	_sql_heavy_row___lambda5_ (self, pspec);
}


static GObject * sql_heavy_row_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	SQLHeavyRow * self;
	gint64 _tmp0_;
	gboolean _tmp2_;
	GError * _inner_error_ = NULL;
	parent_class = G_OBJECT_CLASS (sql_heavy_row_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = SQL_HEAVY_ROW (obj);
	_tmp0_ = self->priv->_id;
	if (_tmp0_ != ((gint64) 0)) {
		SQLHeavyTable* _tmp1_;
		_tmp1_ = self->priv->_table;
		sql_heavy_table_register_row (_tmp1_, self);
	}
	_tmp2_ = self->priv->_enable_cache;
	if (_tmp2_) {
		{
			sql_heavy_row_update_cache (self, &_inner_error_);
			if (_inner_error_ != NULL) {
				if (_inner_error_->domain == SQL_HEAVY_ERROR) {
					goto __catch31_sql_heavy_error;
				}
				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
				g_clear_error (&_inner_error_);
			}
		}
		goto __finally31;
		__catch31_sql_heavy_error:
		{
			GError* e = NULL;
			GError* _tmp3_;
			const gchar* _tmp4_;
			e = _inner_error_;
			_inner_error_ = NULL;
			_tmp3_ = e;
			_tmp4_ = _tmp3_->message;
			g_warning ("sqlheavy-row.vala:324: Unable to initialize cache: %s", _tmp4_);
			_g_error_free0 (e);
		}
		__finally31:
		if (_inner_error_ != NULL) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
		}
	}
	g_signal_connect_object (self, "changed", (GCallback) __sql_heavy_row___lambda4__sql_heavy_row_changed, self, 0);
	g_signal_connect_object ((GObject*) self, "notify::enable-cache", (GCallback) __sql_heavy_row___lambda5__g_object_notify, self, 0);
	return obj;
}


static void sql_heavy_row_class_init (SQLHeavyRowClass * klass) {
	sql_heavy_row_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (SQLHeavyRowPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_sql_heavy_row_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_sql_heavy_row_set_property;
	G_OBJECT_CLASS (klass)->constructor = sql_heavy_row_constructor;
	G_OBJECT_CLASS (klass)->finalize = sql_heavy_row_finalize;
	/**
	     * The table that this row is a record of
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), SQL_HEAVY_ROW_TABLE, g_param_spec_object ("table", "table", "table", SQL_HEAVY_TYPE_TABLE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	/**
	     * Whether the row should automatically save itself when destroyed
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), SQL_HEAVY_ROW_AUTO_SAVE, g_param_spec_boolean ("auto-save", "auto-save", "auto-save", TRUE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	/**
	     * The row ID of this row, or 0 if it has not yet been inserted
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), SQL_HEAVY_ROW_ID, g_param_spec_int64 ("id", "id", "id", G_MININT64, G_MAXINT64, 0, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	/**
	     * {@inheritDoc}
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), SQL_HEAVY_ROW_FIELD_COUNT, g_param_spec_int ("field-count", "field-count", "field-count", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	/**
	     * Whether or not to enable caching for this row
	     *
	     * Caching is required for field-level change notifications.
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), SQL_HEAVY_ROW_ENABLE_CACHE, g_param_spec_boolean ("enable-cache", "enable-cache", "enable-cache", TRUE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	/**
	     * One or more field in this row has changed in the database
	     *
	     * @see put
	     */
	g_signal_new ("changed", SQL_HEAVY_TYPE_ROW, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	/**
	     * The row was deleted from the database
	     *
	     * @see delete
	     */
	g_signal_new ("deleted", SQL_HEAVY_TYPE_ROW, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	/**
	     * The specified field changed in the database
	     *
	     * @param field the index of the field which was modified
	     */
	g_signal_new ("field_changed", SQL_HEAVY_TYPE_ROW, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
}


static void sql_heavy_row_sql_heavy_record_interface_init (SQLHeavyRecordIface * iface) {
	sql_heavy_row_sql_heavy_record_parent_iface = g_type_interface_peek_parent (iface);
	iface->field_index = (gint (*)(SQLHeavyRecord*, const gchar*, GError**)) sql_heavy_row_real_field_index;
	iface->field_name = (gchar* (*)(SQLHeavyRecord*, gint, GError**)) sql_heavy_row_real_field_name;
	iface->field_type = (GType (*)(SQLHeavyRecord*, gint, GError**)) sql_heavy_row_real_field_type;
	iface->fetch = (void (*)(SQLHeavyRecord*, gint, GValue*, GError**)) sql_heavy_row_real_fetch;
	iface->fetch_foreign_row = (SQLHeavyRow* (*)(SQLHeavyRecord*, gint, GError**)) sql_heavy_row_real_fetch_foreign_row;
	iface->get_foreign_row = (SQLHeavyRow* (*)(SQLHeavyRecord*, const gchar*, GError**)) sql_heavy_row_real_get_foreign_row;
	iface->get_field_count = sql_heavy_row_real_get_field_count;
}


static void sql_heavy_row_sql_heavy_mutable_record_interface_init (SQLHeavyMutableRecordIface * iface) {
	sql_heavy_row_sql_heavy_mutable_record_parent_iface = g_type_interface_peek_parent (iface);
	iface->save = (void (*)(SQLHeavyMutableRecord*, GError**)) sql_heavy_row_real_save;
	iface->put = (void (*)(SQLHeavyMutableRecord*, gint, GValue*, GError**)) sql_heavy_row_real_put;
	iface->delete = (void (*)(SQLHeavyMutableRecord*, GError**)) sql_heavy_row_real_delete;
}


static void sql_heavy_row_instance_init (SQLHeavyRow * self) {
	self->priv = SQL_HEAVY_ROW_GET_PRIVATE (self);
	self->priv->_auto_save = TRUE;
	self->priv->_id = (gint64) 0;
	g_static_rec_mutex_init (&self->priv->__lock_values);
	self->priv->values = NULL;
	g_static_rec_mutex_init (&self->priv->__lock_cache);
	self->priv->cache = NULL;
	self->priv->_enable_cache = TRUE;
}


static void sql_heavy_row_finalize (GObject* obj) {
	SQLHeavyRow * self;
	gboolean _tmp0_;
	SQLHeavyTable* _tmp1_;
	GError * _inner_error_ = NULL;
	self = SQL_HEAVY_ROW (obj);
	_tmp0_ = self->priv->_auto_save;
	if (_tmp0_) {
		sql_heavy_mutable_record_save ((SQLHeavyMutableRecord*) self, &_inner_error_);
		if (_inner_error_ != NULL) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
		}
	}
	_tmp1_ = self->priv->_table;
	sql_heavy_table_unregister_row (_tmp1_, self);
	_g_object_unref0 (self->priv->_table);
	g_static_rec_mutex_free (&self->priv->__lock_values);
	self->priv->values = (_vala_array_free (self->priv->values, self->priv->values_length1, (GDestroyNotify) _vala_GValue_free), NULL);
	g_static_rec_mutex_free (&self->priv->__lock_cache);
	self->priv->cache = (_vala_array_free (self->priv->cache, self->priv->cache_length1, (GDestroyNotify) _vala_GValue_free), NULL);
	G_OBJECT_CLASS (sql_heavy_row_parent_class)->finalize (obj);
}


/**
   * A table row
   */
GType sql_heavy_row_get_type (void) {
	static volatile gsize sql_heavy_row_type_id__volatile = 0;
	if (g_once_init_enter (&sql_heavy_row_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (SQLHeavyRowClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) sql_heavy_row_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SQLHeavyRow), 0, (GInstanceInitFunc) sql_heavy_row_instance_init, NULL };
		static const GInterfaceInfo sql_heavy_record_info = { (GInterfaceInitFunc) sql_heavy_row_sql_heavy_record_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		static const GInterfaceInfo sql_heavy_mutable_record_info = { (GInterfaceInitFunc) sql_heavy_row_sql_heavy_mutable_record_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType sql_heavy_row_type_id;
		sql_heavy_row_type_id = g_type_register_static (G_TYPE_OBJECT, "SQLHeavyRow", &g_define_type_info, 0);
		g_type_add_interface_static (sql_heavy_row_type_id, SQL_HEAVY_TYPE_RECORD, &sql_heavy_record_info);
		g_type_add_interface_static (sql_heavy_row_type_id, SQL_HEAVY_TYPE_MUTABLE_RECORD, &sql_heavy_mutable_record_info);
		g_once_init_leave (&sql_heavy_row_type_id__volatile, sql_heavy_row_type_id);
	}
	return sql_heavy_row_type_id__volatile;
}


static void _vala_sql_heavy_row_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	SQLHeavyRow * self;
	self = SQL_HEAVY_ROW (object);
	switch (property_id) {
		case SQL_HEAVY_ROW_TABLE:
		g_value_set_object (value, sql_heavy_row_get_table (self));
		break;
		case SQL_HEAVY_ROW_AUTO_SAVE:
		g_value_set_boolean (value, sql_heavy_row_get_auto_save (self));
		break;
		case SQL_HEAVY_ROW_ID:
		g_value_set_int64 (value, sql_heavy_row_get_id (self));
		break;
		case SQL_HEAVY_ROW_FIELD_COUNT:
		g_value_set_int (value, sql_heavy_record_get_field_count ((SQLHeavyRecord*) self));
		break;
		case SQL_HEAVY_ROW_ENABLE_CACHE:
		g_value_set_boolean (value, sql_heavy_row_get_enable_cache (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_sql_heavy_row_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	SQLHeavyRow * self;
	self = SQL_HEAVY_ROW (object);
	switch (property_id) {
		case SQL_HEAVY_ROW_TABLE:
		sql_heavy_row_set_table (self, g_value_get_object (value));
		break;
		case SQL_HEAVY_ROW_AUTO_SAVE:
		sql_heavy_row_set_auto_save (self, g_value_get_boolean (value));
		break;
		case SQL_HEAVY_ROW_ID:
		sql_heavy_row_set_id (self, g_value_get_int64 (value));
		break;
		case SQL_HEAVY_ROW_ENABLE_CACHE:
		sql_heavy_row_set_enable_cache (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



