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


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


#define SQL_HEAVY_TABLE_TYPE_FIELD_INFO (sql_heavy_table_field_info_get_type ())
#define SQL_HEAVY_TABLE_FIELD_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SQL_HEAVY_TABLE_TYPE_FIELD_INFO, SQLHeavyTableFieldInfo))
#define SQL_HEAVY_TABLE_FIELD_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SQL_HEAVY_TABLE_TYPE_FIELD_INFO, SQLHeavyTableFieldInfoClass))
#define SQL_HEAVY_TABLE_IS_FIELD_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SQL_HEAVY_TABLE_TYPE_FIELD_INFO))
#define SQL_HEAVY_TABLE_IS_FIELD_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SQL_HEAVY_TABLE_TYPE_FIELD_INFO))
#define SQL_HEAVY_TABLE_FIELD_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SQL_HEAVY_TABLE_TYPE_FIELD_INFO, SQLHeavyTableFieldInfoClass))

typedef struct _SQLHeavyTableFieldInfo SQLHeavyTableFieldInfo;
typedef struct _SQLHeavyTableFieldInfoClass SQLHeavyTableFieldInfoClass;

#define SQL_HEAVY_TABLE_TYPE_FOREIGN_KEY_INFO (sql_heavy_table_foreign_key_info_get_type ())
#define SQL_HEAVY_TABLE_FOREIGN_KEY_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SQL_HEAVY_TABLE_TYPE_FOREIGN_KEY_INFO, SQLHeavyTableForeignKeyInfo))
#define SQL_HEAVY_TABLE_FOREIGN_KEY_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SQL_HEAVY_TABLE_TYPE_FOREIGN_KEY_INFO, SQLHeavyTableForeignKeyInfoClass))
#define SQL_HEAVY_TABLE_IS_FOREIGN_KEY_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SQL_HEAVY_TABLE_TYPE_FOREIGN_KEY_INFO))
#define SQL_HEAVY_TABLE_IS_FOREIGN_KEY_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SQL_HEAVY_TABLE_TYPE_FOREIGN_KEY_INFO))
#define SQL_HEAVY_TABLE_FOREIGN_KEY_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SQL_HEAVY_TABLE_TYPE_FOREIGN_KEY_INFO, SQLHeavyTableForeignKeyInfoClass))

typedef struct _SQLHeavyTableForeignKeyInfo SQLHeavyTableForeignKeyInfo;
typedef struct _SQLHeavyTableForeignKeyInfoClass SQLHeavyTableForeignKeyInfoClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_sequence_free0(var) ((var == NULL) ? NULL : (var = (g_sequence_free (var), NULL)))
typedef struct _SQLHeavyTableFieldInfoPrivate SQLHeavyTableFieldInfoPrivate;
typedef struct _SQLHeavyTableForeignKeyInfoPrivate SQLHeavyTableForeignKeyInfoPrivate;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _SQLHeavyTablePrivate {
	gchar* _name;
	SQLHeavyQueryable* _queryable;
	GHashTable* child_rows;
	GStaticRecMutex __lock_child_rows;
	GSequence* _field_data;
	GStaticRecMutex __lock__field_data;
	GHashTable* _field_names;
	GSequence* _foreign_key_data;
	GStaticRecMutex __lock__foreign_key_data;
	GHashTable* _foreign_key_names;
};

struct _SQLHeavyTableFieldInfo {
	GObject parent_instance;
	SQLHeavyTableFieldInfoPrivate * priv;
	gint index;
	gchar* name;
	gchar* affinity;
	gboolean not_null;
};

struct _SQLHeavyTableFieldInfoClass {
	GObjectClass parent_class;
};

struct _SQLHeavyTableForeignKeyInfo {
	GObject parent_instance;
	SQLHeavyTableForeignKeyInfoPrivate * priv;
	gint id;
	gint seq;
	gchar* table;
	gchar* from;
	gchar* to;
};

struct _SQLHeavyTableForeignKeyInfoClass {
	GObjectClass parent_class;
};


static gpointer sql_heavy_table_parent_class = NULL;
static gpointer sql_heavy_table_field_info_parent_class = NULL;
static gpointer sql_heavy_table_foreign_key_info_parent_class = NULL;

static GType sql_heavy_table_field_info_get_type (void) G_GNUC_CONST G_GNUC_UNUSED;
static GType sql_heavy_table_foreign_key_info_get_type (void) G_GNUC_CONST G_GNUC_UNUSED;
#define SQL_HEAVY_TABLE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SQL_HEAVY_TYPE_TABLE, SQLHeavyTablePrivate))
enum  {
	SQL_HEAVY_TABLE_DUMMY_PROPERTY,
	SQL_HEAVY_TABLE_NAME,
	SQL_HEAVY_TABLE_QUERYABLE,
	SQL_HEAVY_TABLE_FIELD_COUNT,
	SQL_HEAVY_TABLE_FOREIGN_KEY_COUNT
};
void g_sequence_free (GSequence* seq);
static void sql_heavy_table_row_modified_handler (SQLHeavyTable* self, gint64 row_id);
static GSequence* sql_heavy_table_get_field_data (SQLHeavyTable* self, GError** error);
static void _g_object_unref0_ (gpointer var);
static SQLHeavyTableFieldInfo* sql_heavy_table_field_info_new_from_query_result (SQLHeavyQueryResult* query_result, GError** error);
static SQLHeavyTableFieldInfo* sql_heavy_table_field_info_construct_from_query_result (GType object_type, SQLHeavyQueryResult* query_result, GError** error);
static gint ______lambda2_ (SQLHeavyTable* self, SQLHeavyTableFieldInfo* a, SQLHeavyTableFieldInfo* b);
static gint _______lambda2__gcompare_data_func (gconstpointer a, gconstpointer b, gpointer self);
static gint* _int_dup (gint* self);
static GSequence* sql_heavy_table_get_foreign_key_data (SQLHeavyTable* self, GError** error);
static SQLHeavyTableForeignKeyInfo* sql_heavy_table_foreign_key_info_new_from_query_result (SQLHeavyQueryResult* query_result, GError** error);
static SQLHeavyTableForeignKeyInfo* sql_heavy_table_foreign_key_info_construct_from_query_result (GType object_type, SQLHeavyQueryResult* query_result, GError** error);
static gint ______lambda3_ (SQLHeavyTable* self, SQLHeavyTableForeignKeyInfo* a, SQLHeavyTableForeignKeyInfo* b);
static gint _______lambda3__gcompare_data_func (gconstpointer a, gconstpointer b, gpointer self);
static SQLHeavyTableFieldInfo* sql_heavy_table_field_info (SQLHeavyTable* self, gint field, GError** error);
GType sql_heavy_sqlite_type_string_to_g_type (const gchar* stype, GError** error);
static SQLHeavyTableForeignKeyInfo* sql_heavy_table_foreign_key_info (SQLHeavyTable* self, gint foreign_key, GError** error);
void sql_heavy_table_register_row (SQLHeavyTable* self, SQLHeavyRow* row);
static gint64* _int64_dup (gint64* self);
static gint _sql_heavy_row_compare_gcompare_data_func (gconstpointer a, gconstpointer b, gpointer self);
void sql_heavy_table_unregister_row (SQLHeavyTable* self, SQLHeavyRow* row);
gint sql_heavy_row_direct_compare (SQLHeavyRow* a, SQLHeavyRow* b);
static gint _sql_heavy_row_direct_compare_gcompare_data_func (gconstpointer a, gconstpointer b, gpointer self);
gint sql_heavy_table_direct_compare (SQLHeavyTable* a, SQLHeavyTable* b);
static void g_cclosure_user_marshal_VOID__INT64 (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data);
static void sql_heavy_table_real_row_modified (SQLHeavyTable* self, gint64 row_id);
static GObject * sql_heavy_table_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
void sql_heavy_database_register_orm_table (SQLHeavyDatabase* self, SQLHeavyTable* table);
enum  {
	SQL_HEAVY_TABLE_FIELD_INFO_DUMMY_PROPERTY
};
static SQLHeavyTableFieldInfo* sql_heavy_table_field_info_new (void);
static SQLHeavyTableFieldInfo* sql_heavy_table_field_info_construct (GType object_type);
static void sql_heavy_table_field_info_finalize (GObject* obj);
enum  {
	SQL_HEAVY_TABLE_FOREIGN_KEY_INFO_DUMMY_PROPERTY
};
static SQLHeavyTableForeignKeyInfo* sql_heavy_table_foreign_key_info_new (void);
static SQLHeavyTableForeignKeyInfo* sql_heavy_table_foreign_key_info_construct (GType object_type);
static void sql_heavy_table_foreign_key_info_finalize (GObject* obj);
static void sql_heavy_table_finalize (GObject* obj);
static void _vala_sql_heavy_table_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_sql_heavy_table_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);


static void sql_heavy_table_row_modified_handler (SQLHeavyTable* self, gint64 row_id) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	{
		GHashTable* _tmp0_;
		_tmp0_ = self->priv->child_rows;
		g_static_rec_mutex_lock (&self->priv->__lock_child_rows);
		{
			GHashTable* _tmp1_;
			gint64 _tmp2_;
			gconstpointer _tmp3_ = NULL;
			GSequence* l;
			GSequence* _tmp4_;
			_tmp1_ = self->priv->child_rows;
			_tmp2_ = row_id;
			_tmp3_ = g_hash_table_lookup (_tmp1_, &_tmp2_);
			l = (GSequence*) _tmp3_;
			_tmp4_ = l;
			if (_tmp4_ == NULL) {
				{
					GHashTable* _tmp5_;
					_tmp5_ = self->priv->child_rows;
					g_static_rec_mutex_unlock (&self->priv->__lock_child_rows);
				}
				return;
			}
			{
				GSequence* _tmp6_;
				GSequenceIter* _tmp7_ = NULL;
				GSequenceIter* iter;
				_tmp6_ = l;
				_tmp7_ = g_sequence_get_begin_iter (_tmp6_);
				iter = _tmp7_;
				{
					gboolean _tmp8_;
					_tmp8_ = TRUE;
					while (TRUE) {
						gboolean _tmp9_;
						GSequenceIter* _tmp12_;
						gboolean _tmp13_ = FALSE;
						GSequenceIter* _tmp14_;
						gconstpointer _tmp15_ = NULL;
						_tmp9_ = _tmp8_;
						if (!_tmp9_) {
							GSequenceIter* _tmp10_;
							GSequenceIter* _tmp11_ = NULL;
							_tmp10_ = iter;
							_tmp11_ = g_sequence_iter_next (_tmp10_);
							iter = _tmp11_;
						}
						_tmp8_ = FALSE;
						_tmp12_ = iter;
						_tmp13_ = g_sequence_iter_is_end (_tmp12_);
						if (!(!_tmp13_)) {
							break;
						}
						_tmp14_ = iter;
						_tmp15_ = g_sequence_get (_tmp14_);
						g_signal_emit_by_name ((SQLHeavyRow*) _tmp15_, "changed");
					}
				}
			}
		}
		__finally33:
		{
			GHashTable* _tmp16_;
			_tmp16_ = self->priv->child_rows;
			g_static_rec_mutex_unlock (&self->priv->__lock_child_rows);
		}
		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 _g_object_unref0_ (gpointer var) {
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}


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 gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


static gint ______lambda2_ (SQLHeavyTable* self, SQLHeavyTableFieldInfo* a, SQLHeavyTableFieldInfo* b) {
	gint result = 0;
	SQLHeavyTableFieldInfo* _tmp0_;
	gint _tmp1_;
	SQLHeavyTableFieldInfo* _tmp2_;
	gint _tmp3_;
	g_return_val_if_fail (a != NULL, 0);
	g_return_val_if_fail (b != NULL, 0);
	_tmp0_ = a;
	_tmp1_ = SQL_HEAVY_TABLE_FIELD_INFO (_tmp0_)->index;
	_tmp2_ = b;
	_tmp3_ = SQL_HEAVY_TABLE_FIELD_INFO (_tmp2_)->index;
	result = _tmp1_ - _tmp3_;
	return result;
}


static gint _______lambda2__gcompare_data_func (gconstpointer a, gconstpointer b, gpointer self) {
	gint result;
	result = ______lambda2_ (self, a, b);
	return result;
}


static gint* _int_dup (gint* self) {
	gint* dup;
	dup = g_new0 (gint, 1);
	memcpy (dup, self, sizeof (gint));
	return dup;
}


static gpointer __int_dup0 (gpointer self) {
	return self ? _int_dup (self) : NULL;
}


static GSequence* sql_heavy_table_get_field_data (SQLHeavyTable* self, GError** error) {
	GSequence* result = NULL;
	GSequence* _tmp39_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	{
		GSequence* _tmp0_;
		_tmp0_ = self->priv->_field_data;
		g_static_rec_mutex_lock (&self->priv->__lock__field_data);
		{
			GSequence* _tmp1_;
			_tmp1_ = self->priv->_field_data;
			if (_tmp1_ == NULL) {
				GSequence* _tmp2_;
				GHashFunc _tmp3_;
				GEqualFunc _tmp4_;
				GDestroyNotify _tmp5_;
				GDestroyNotify _tmp6_;
				GHashTable* _tmp7_;
				SQLHeavyQueryable* _tmp8_;
				const gchar* _tmp9_;
				gchar* _tmp10_ = NULL;
				gchar* _tmp11_;
				const gchar* _tmp12_ = NULL;
				gchar* _tmp13_ = NULL;
				gchar* _tmp14_;
				SQLHeavyQuery* _tmp15_;
				SQLHeavyQuery* _tmp16_;
				SQLHeavyQuery* _tmp17_;
				SQLHeavyQuery* _tmp18_;
				SQLHeavyQueryResult* _tmp19_ = NULL;
				SQLHeavyQueryResult* _tmp20_;
				SQLHeavyQueryResult* _result_;
				_tmp2_ = g_sequence_new (_g_object_unref0_);
				_g_sequence_free0 (self->priv->_field_data);
				self->priv->_field_data = _tmp2_;
				_tmp3_ = g_str_hash;
				_tmp4_ = g_str_equal;
				_tmp5_ = g_free;
				_tmp6_ = g_free;
				_tmp7_ = g_hash_table_new_full (_tmp3_, _tmp4_, _tmp5_, _tmp6_);
				_g_hash_table_unref0 (self->priv->_field_names);
				self->priv->_field_names = _tmp7_;
				_tmp8_ = self->priv->_queryable;
				_tmp9_ = self->priv->_name;
				_tmp10_ = sql_heavy_escape_string (_tmp9_);
				_tmp11_ = _tmp10_;
				_tmp12_ = string_to_string (_tmp11_);
				_tmp13_ = g_strconcat ("PRAGMA table_info (`", _tmp12_, "`);", NULL);
				_tmp14_ = _tmp13_;
				_tmp15_ = sql_heavy_query_new (_tmp8_, _tmp14_, &_inner_error_);
				_tmp16_ = _tmp15_;
				_g_free0 (_tmp14_);
				_g_free0 (_tmp11_);
				_tmp17_ = _tmp16_;
				if (_inner_error_ != NULL) {
					goto __finally34;
				}
				_tmp18_ = _tmp17_;
				_tmp19_ = sql_heavy_query_execute (_tmp18_, NULL, &_inner_error_, NULL);
				_tmp20_ = _tmp19_;
				_g_object_unref0 (_tmp18_);
				_result_ = _tmp20_;
				if (_inner_error_ != NULL) {
					goto __finally34;
				}
				while (TRUE) {
					SQLHeavyQueryResult* _tmp21_;
					gboolean _tmp22_;
					gboolean _tmp23_;
					SQLHeavyQueryResult* _tmp24_;
					SQLHeavyTableFieldInfo* _tmp25_;
					SQLHeavyTableFieldInfo* row;
					GSequence* _tmp26_;
					SQLHeavyTableFieldInfo* _tmp27_;
					SQLHeavyTableFieldInfo* _tmp28_;
					GSequenceIter* _tmp29_ = NULL;
					GHashTable* _tmp30_;
					SQLHeavyTableFieldInfo* _tmp31_;
					const gchar* _tmp32_;
					gchar* _tmp33_;
					SQLHeavyTableFieldInfo* _tmp34_;
					gint _tmp35_;
					gint* _tmp36_;
					SQLHeavyQueryResult* _tmp37_;
					_tmp21_ = _result_;
					_tmp22_ = sql_heavy_query_result_get_finished (_tmp21_);
					_tmp23_ = _tmp22_;
					if (!(!_tmp23_)) {
						break;
					}
					_tmp24_ = _result_;
					_tmp25_ = sql_heavy_table_field_info_new_from_query_result (_tmp24_, &_inner_error_);
					row = _tmp25_;
					if (_inner_error_ != NULL) {
						_g_object_unref0 (_result_);
						goto __finally34;
					}
					_tmp26_ = self->priv->_field_data;
					_tmp27_ = row;
					_tmp28_ = _g_object_ref0 (_tmp27_);
					_tmp29_ = g_sequence_insert_sorted (_tmp26_, _tmp28_, _______lambda2__gcompare_data_func, self);
					_tmp30_ = self->priv->_field_names;
					_tmp31_ = row;
					_tmp32_ = _tmp31_->name;
					_tmp33_ = g_strdup (_tmp32_);
					_tmp34_ = row;
					_tmp35_ = _tmp34_->index;
					_tmp36_ = __int_dup0 (&_tmp35_);
					g_hash_table_insert (_tmp30_, _tmp33_, _tmp36_);
					_tmp37_ = _result_;
					sql_heavy_record_set_next ((SQLHeavyRecordSet*) _tmp37_, &_inner_error_);
					if (_inner_error_ != NULL) {
						_g_object_unref0 (row);
						_g_object_unref0 (_result_);
						goto __finally34;
					}
					_g_object_unref0 (row);
				}
				_g_object_unref0 (_result_);
			}
		}
		__finally34:
		{
			GSequence* _tmp38_;
			_tmp38_ = self->priv->_field_data;
			g_static_rec_mutex_unlock (&self->priv->__lock__field_data);
		}
		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;
			}
		}
	}
	_tmp39_ = self->priv->_field_data;
	result = (GSequence*) _tmp39_;
	return result;
}


static gint ______lambda3_ (SQLHeavyTable* self, SQLHeavyTableForeignKeyInfo* a, SQLHeavyTableForeignKeyInfo* b) {
	gint result = 0;
	SQLHeavyTableForeignKeyInfo* _tmp0_;
	gint _tmp1_;
	SQLHeavyTableForeignKeyInfo* _tmp2_;
	gint _tmp3_;
	g_return_val_if_fail (a != NULL, 0);
	g_return_val_if_fail (b != NULL, 0);
	_tmp0_ = a;
	_tmp1_ = SQL_HEAVY_TABLE_FOREIGN_KEY_INFO (_tmp0_)->id;
	_tmp2_ = b;
	_tmp3_ = SQL_HEAVY_TABLE_FOREIGN_KEY_INFO (_tmp2_)->id;
	result = _tmp1_ - _tmp3_;
	return result;
}


static gint _______lambda3__gcompare_data_func (gconstpointer a, gconstpointer b, gpointer self) {
	gint result;
	result = ______lambda3_ (self, a, b);
	return result;
}


static GSequence* sql_heavy_table_get_foreign_key_data (SQLHeavyTable* self, GError** error) {
	GSequence* result = NULL;
	GSequence* _tmp39_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	{
		GSequence* _tmp0_;
		_tmp0_ = self->priv->_foreign_key_data;
		g_static_rec_mutex_lock (&self->priv->__lock__foreign_key_data);
		{
			GSequence* _tmp1_;
			_tmp1_ = self->priv->_foreign_key_data;
			if (_tmp1_ == NULL) {
				GSequence* _tmp2_;
				GHashFunc _tmp3_;
				GEqualFunc _tmp4_;
				GDestroyNotify _tmp5_;
				GDestroyNotify _tmp6_;
				GHashTable* _tmp7_;
				SQLHeavyQueryable* _tmp8_;
				const gchar* _tmp9_;
				gchar* _tmp10_ = NULL;
				gchar* _tmp11_;
				const gchar* _tmp12_ = NULL;
				gchar* _tmp13_ = NULL;
				gchar* _tmp14_;
				SQLHeavyQuery* _tmp15_;
				SQLHeavyQuery* _tmp16_;
				SQLHeavyQuery* _tmp17_;
				SQLHeavyQuery* _tmp18_;
				SQLHeavyQueryResult* _tmp19_ = NULL;
				SQLHeavyQueryResult* _tmp20_;
				SQLHeavyQueryResult* _result_;
				_tmp2_ = g_sequence_new (_g_object_unref0_);
				_g_sequence_free0 (self->priv->_foreign_key_data);
				self->priv->_foreign_key_data = _tmp2_;
				_tmp3_ = g_str_hash;
				_tmp4_ = g_str_equal;
				_tmp5_ = g_free;
				_tmp6_ = g_free;
				_tmp7_ = g_hash_table_new_full (_tmp3_, _tmp4_, _tmp5_, _tmp6_);
				_g_hash_table_unref0 (self->priv->_foreign_key_names);
				self->priv->_foreign_key_names = _tmp7_;
				_tmp8_ = self->priv->_queryable;
				_tmp9_ = self->priv->_name;
				_tmp10_ = sql_heavy_escape_string (_tmp9_);
				_tmp11_ = _tmp10_;
				_tmp12_ = string_to_string (_tmp11_);
				_tmp13_ = g_strconcat ("PRAGMA foreign_key_list (`", _tmp12_, "`);", NULL);
				_tmp14_ = _tmp13_;
				_tmp15_ = sql_heavy_query_new (_tmp8_, _tmp14_, &_inner_error_);
				_tmp16_ = _tmp15_;
				_g_free0 (_tmp14_);
				_g_free0 (_tmp11_);
				_tmp17_ = _tmp16_;
				if (_inner_error_ != NULL) {
					goto __finally35;
				}
				_tmp18_ = _tmp17_;
				_tmp19_ = sql_heavy_query_execute (_tmp18_, NULL, &_inner_error_, NULL);
				_tmp20_ = _tmp19_;
				_g_object_unref0 (_tmp18_);
				_result_ = _tmp20_;
				if (_inner_error_ != NULL) {
					goto __finally35;
				}
				while (TRUE) {
					SQLHeavyQueryResult* _tmp21_;
					gboolean _tmp22_;
					gboolean _tmp23_;
					SQLHeavyQueryResult* _tmp24_;
					SQLHeavyTableForeignKeyInfo* _tmp25_;
					SQLHeavyTableForeignKeyInfo* row;
					GSequence* _tmp26_;
					SQLHeavyTableForeignKeyInfo* _tmp27_;
					SQLHeavyTableForeignKeyInfo* _tmp28_;
					GSequenceIter* _tmp29_ = NULL;
					GHashTable* _tmp30_;
					SQLHeavyTableForeignKeyInfo* _tmp31_;
					const gchar* _tmp32_;
					gchar* _tmp33_;
					SQLHeavyTableForeignKeyInfo* _tmp34_;
					gint _tmp35_;
					gint* _tmp36_;
					SQLHeavyQueryResult* _tmp37_;
					_tmp21_ = _result_;
					_tmp22_ = sql_heavy_query_result_get_finished (_tmp21_);
					_tmp23_ = _tmp22_;
					if (!(!_tmp23_)) {
						break;
					}
					_tmp24_ = _result_;
					_tmp25_ = sql_heavy_table_foreign_key_info_new_from_query_result (_tmp24_, &_inner_error_);
					row = _tmp25_;
					if (_inner_error_ != NULL) {
						_g_object_unref0 (_result_);
						goto __finally35;
					}
					_tmp26_ = self->priv->_foreign_key_data;
					_tmp27_ = row;
					_tmp28_ = _g_object_ref0 (_tmp27_);
					_tmp29_ = g_sequence_insert_sorted (_tmp26_, _tmp28_, _______lambda3__gcompare_data_func, self);
					_tmp30_ = self->priv->_foreign_key_names;
					_tmp31_ = row;
					_tmp32_ = _tmp31_->from;
					_tmp33_ = g_strdup (_tmp32_);
					_tmp34_ = row;
					_tmp35_ = _tmp34_->id;
					_tmp36_ = __int_dup0 (&_tmp35_);
					g_hash_table_insert (_tmp30_, _tmp33_, _tmp36_);
					_tmp37_ = _result_;
					sql_heavy_record_set_next ((SQLHeavyRecordSet*) _tmp37_, &_inner_error_);
					if (_inner_error_ != NULL) {
						_g_object_unref0 (row);
						_g_object_unref0 (_result_);
						goto __finally35;
					}
					_g_object_unref0 (row);
				}
				_g_object_unref0 (_result_);
			}
		}
		__finally35:
		{
			GSequence* _tmp38_;
			_tmp38_ = self->priv->_foreign_key_data;
			g_static_rec_mutex_unlock (&self->priv->__lock__foreign_key_data);
		}
		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;
			}
		}
	}
	_tmp39_ = self->priv->_foreign_key_data;
	result = (GSequence*) _tmp39_;
	return result;
}


static SQLHeavyTableFieldInfo* sql_heavy_table_field_info (SQLHeavyTable* self, gint field, GError** error) {
	SQLHeavyTableFieldInfo* result = NULL;
	GSequence* _tmp0_ = NULL;
	GSequence* _tmp1_;
	gint _tmp2_;
	GSequenceIter* _tmp3_ = NULL;
	GSequenceIter* iter;
	GSequenceIter* _tmp4_;
	GSequenceIter* _tmp7_;
	gconstpointer _tmp8_ = NULL;
	SQLHeavyTableFieldInfo* _tmp9_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = sql_heavy_table_get_field_data (self, &_inner_error_);
	_tmp1_ = _tmp0_;
	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;
		}
	}
	_tmp2_ = field;
	_tmp3_ = g_sequence_get_iter_at_pos (_tmp1_, _tmp2_);
	iter = _tmp3_;
	_tmp4_ = iter;
	if (_tmp4_ == NULL) {
		gint _tmp5_;
		GError* _tmp6_;
		_tmp5_ = field;
		_tmp6_ = g_error_new (SQL_HEAVY_ERROR, SQL_HEAVY_ERROR_RANGE, "Invalid field index (%d)", _tmp5_);
		_inner_error_ = _tmp6_;
		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;
		}
	}
	_tmp7_ = iter;
	_tmp8_ = g_sequence_get (_tmp7_);
	_tmp9_ = _g_object_ref0 ((SQLHeavyTableFieldInfo*) _tmp8_);
	result = _tmp9_;
	return result;
}


/**
     * Get the name of a field
     *
     * @param field index of the field
     * @return name of the field by index
     */
gchar* sql_heavy_table_field_name (SQLHeavyTable* self, gint field, GError** error) {
	gchar* result = NULL;
	gint _tmp0_;
	SQLHeavyTableFieldInfo* _tmp1_ = NULL;
	SQLHeavyTableFieldInfo* _tmp2_;
	SQLHeavyTableFieldInfo* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = field;
	_tmp1_ = sql_heavy_table_field_info (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_ = _tmp3_->name;
	_tmp5_ = g_strdup (_tmp4_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp3_);
	result = _tmp6_;
	return result;
}


/**
     * The field affinity according to the schema
     *
     * @param field the field index
     * @return the field affinity
     */
gchar* sql_heavy_table_field_affinity (SQLHeavyTable* self, gint field, GError** error) {
	gchar* result = NULL;
	gint _tmp0_;
	SQLHeavyTableFieldInfo* _tmp1_ = NULL;
	SQLHeavyTableFieldInfo* _tmp2_;
	SQLHeavyTableFieldInfo* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = field;
	_tmp1_ = sql_heavy_table_field_info (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_ = _tmp3_->affinity;
	_tmp5_ = g_strdup (_tmp4_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp3_);
	result = _tmp6_;
	return result;
}


/**
     * The field affinity as a GType
     *
     * @param field the field index
     * @return the GType of the field affinity
     */
GType sql_heavy_table_field_affinity_type (SQLHeavyTable* self, gint field, GError** error) {
	GType result = 0UL;
	gint _tmp0_;
	SQLHeavyTableFieldInfo* _tmp1_ = NULL;
	SQLHeavyTableFieldInfo* _tmp2_;
	SQLHeavyTableFieldInfo* _tmp3_;
	const gchar* _tmp4_;
	GType _tmp5_ = 0UL;
	GType _tmp6_;
	GType _tmp7_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, 0UL);
	_tmp0_ = field;
	_tmp1_ = sql_heavy_table_field_info (self, _tmp0_, &_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_ = _tmp2_;
	_tmp4_ = _tmp3_->affinity;
	_tmp5_ = sql_heavy_sqlite_type_string_to_g_type (_tmp4_, &_inner_error_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp3_);
	_tmp7_ = _tmp6_;
	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;
		}
	}
	result = _tmp7_;
	return result;
}


/**
     * Get the index of a field by name
     *
     * @param name name of the field
     * @return index of the field
     */
gint sql_heavy_table_field_index (SQLHeavyTable* self, const gchar* name, GError** error) {
	gint result = 0;
	GHashTable* _tmp0_;
	GHashTable* _tmp1_;
	const gchar* _tmp2_;
	gconstpointer _tmp3_ = NULL;
	gint* _tmp4_;
	gint* index;
	gint* _tmp5_;
	gint* _tmp8_;
	gint _tmp9_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, 0);
	g_return_val_if_fail (name != NULL, 0);
	_tmp0_ = self->priv->_field_names;
	if (_tmp0_ == NULL) {
		sql_heavy_table_get_field_data (self, &_inner_error_);
		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;
			}
		}
	}
	_tmp1_ = self->priv->_field_names;
	_tmp2_ = name;
	_tmp3_ = g_hash_table_lookup (_tmp1_, _tmp2_);
	_tmp4_ = __int_dup0 ((gint*) _tmp3_);
	index = _tmp4_;
	_tmp5_ = index;
	if (_tmp5_ == NULL) {
		const gchar* _tmp6_;
		GError* _tmp7_;
		_tmp6_ = name;
		_tmp7_ = g_error_new (SQL_HEAVY_ERROR, SQL_HEAVY_ERROR_RANGE, "Invalid field name (`%s')", _tmp6_);
		_inner_error_ = _tmp7_;
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_free0 (index);
			return 0;
		} else {
			_g_free0 (index);
			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;
		}
	}
	_tmp8_ = index;
	_tmp9_ = *_tmp8_;
	_g_free0 (_tmp8_);
	result = _tmp9_;
	return result;
}


static SQLHeavyTableForeignKeyInfo* sql_heavy_table_foreign_key_info (SQLHeavyTable* self, gint foreign_key, GError** error) {
	SQLHeavyTableForeignKeyInfo* result = NULL;
	GSequence* _tmp0_ = NULL;
	GSequence* _tmp1_;
	gint _tmp2_;
	GSequenceIter* _tmp3_ = NULL;
	GSequenceIter* iter;
	GSequenceIter* _tmp4_;
	GSequenceIter* _tmp7_;
	gconstpointer _tmp8_ = NULL;
	SQLHeavyTableForeignKeyInfo* _tmp9_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = sql_heavy_table_get_foreign_key_data (self, &_inner_error_);
	_tmp1_ = _tmp0_;
	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;
		}
	}
	_tmp2_ = foreign_key;
	_tmp3_ = g_sequence_get_iter_at_pos (_tmp1_, _tmp2_);
	iter = _tmp3_;
	_tmp4_ = iter;
	if (_tmp4_ == NULL) {
		gint _tmp5_;
		GError* _tmp6_;
		_tmp5_ = foreign_key;
		_tmp6_ = g_error_new (SQL_HEAVY_ERROR, SQL_HEAVY_ERROR_RANGE, "Invalid foreign key index (%d)", _tmp5_);
		_inner_error_ = _tmp6_;
		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;
		}
	}
	_tmp7_ = iter;
	_tmp8_ = g_sequence_get (_tmp7_);
	_tmp9_ = _g_object_ref0 ((SQLHeavyTableForeignKeyInfo*) _tmp8_);
	result = _tmp9_;
	return result;
}


/**
     * Retrieve the table of the foreign key references
     *
     * @param foreign_key the id of the foreign key
     * @return the table name
     */
gchar* sql_heavy_table_foreign_key_table_name (SQLHeavyTable* self, gint foreign_key, GError** error) {
	gchar* result = NULL;
	gint _tmp0_;
	SQLHeavyTableForeignKeyInfo* _tmp1_ = NULL;
	SQLHeavyTableForeignKeyInfo* _tmp2_;
	SQLHeavyTableForeignKeyInfo* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = foreign_key;
	_tmp1_ = sql_heavy_table_foreign_key_info (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_ = _tmp3_->table;
	_tmp5_ = g_strdup (_tmp4_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp3_);
	result = _tmp6_;
	return result;
}


/**
     * Retrieve the table of the foreign key references
     *
     * @param foreign_key the id of the foreign key
     * @return the table name
     */
SQLHeavyTable* sql_heavy_table_foreign_key_table (SQLHeavyTable* self, gint foreign_key, GError** error) {
	SQLHeavyTable* result = NULL;
	gint _tmp0_;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_;
	SQLHeavyQueryable* _tmp3_;
	gchar* _tmp4_;
	SQLHeavyTable* _tmp5_;
	SQLHeavyTable* _tmp6_;
	SQLHeavyTable* _tmp7_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = foreign_key;
	_tmp1_ = sql_heavy_table_foreign_key_table_name (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_ = self->priv->_queryable;
	_tmp4_ = _tmp2_;
	_tmp5_ = sql_heavy_table_new (_tmp3_, _tmp4_, &_inner_error_);
	_tmp6_ = _tmp5_;
	_g_free0 (_tmp4_);
	_tmp7_ = _tmp6_;
	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 = _tmp7_;
	return result;
}


/**
     * Retrieve the column of the table of the foreign key
     *
     * @param foreign_key the id of the foreign key
     * @return the column name
     */
gchar* sql_heavy_table_foreign_key_from (SQLHeavyTable* self, gint foreign_key, GError** error) {
	gchar* result = NULL;
	gint _tmp0_;
	SQLHeavyTableForeignKeyInfo* _tmp1_ = NULL;
	SQLHeavyTableForeignKeyInfo* _tmp2_;
	SQLHeavyTableForeignKeyInfo* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = foreign_key;
	_tmp1_ = sql_heavy_table_foreign_key_info (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_ = _tmp3_->from;
	_tmp5_ = g_strdup (_tmp4_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp3_);
	result = _tmp6_;
	return result;
}


/**
     * Retrieve the column of which references the foreign key
     *
     * @param foreign_key the id of the foreign key
     * @return the column name
     */
gchar* sql_heavy_table_foreign_key_to (SQLHeavyTable* self, gint foreign_key, GError** error) {
	gchar* result = NULL;
	gint _tmp0_;
	SQLHeavyTableForeignKeyInfo* _tmp1_ = NULL;
	SQLHeavyTableForeignKeyInfo* _tmp2_;
	SQLHeavyTableForeignKeyInfo* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = foreign_key;
	_tmp1_ = sql_heavy_table_foreign_key_info (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_ = _tmp3_->to;
	_tmp5_ = g_strdup (_tmp4_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp3_);
	result = _tmp6_;
	return result;
}


/**
     * Retrieve the index of the foreign key
     *
     * @param foreign_key the name of the foreign key column
     * @return the column index
     */
gint sql_heavy_table_foreign_key_index (SQLHeavyTable* self, const gchar* foreign_key, GError** error) {
	gint result = 0;
	GHashTable* _tmp0_;
	GHashTable* _tmp1_;
	const gchar* _tmp2_;
	gconstpointer _tmp3_ = NULL;
	gint* _tmp4_;
	gint* index;
	gint* _tmp5_;
	gint* _tmp8_;
	gint _tmp9_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, 0);
	g_return_val_if_fail (foreign_key != NULL, 0);
	_tmp0_ = self->priv->_foreign_key_names;
	if (_tmp0_ == NULL) {
		sql_heavy_table_get_foreign_key_data (self, &_inner_error_);
		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;
			}
		}
	}
	_tmp1_ = self->priv->_foreign_key_names;
	_tmp2_ = foreign_key;
	_tmp3_ = g_hash_table_lookup (_tmp1_, _tmp2_);
	_tmp4_ = __int_dup0 ((gint*) _tmp3_);
	index = _tmp4_;
	_tmp5_ = index;
	if (_tmp5_ == NULL) {
		const gchar* _tmp6_;
		GError* _tmp7_;
		_tmp6_ = foreign_key;
		_tmp7_ = g_error_new (SQL_HEAVY_ERROR, SQL_HEAVY_ERROR_RANGE, "Invalid foreign key name (`%s')", _tmp6_);
		_inner_error_ = _tmp7_;
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_free0 (index);
			return 0;
		} else {
			_g_free0 (index);
			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;
		}
	}
	_tmp8_ = index;
	_tmp9_ = *_tmp8_;
	_g_free0 (_tmp8_);
	result = _tmp9_;
	return result;
}


/**
     * Return the row with the specified ID
     *
     * @param id the id (ROWID) of the requested row
     * @return the reqested row
     */
SQLHeavyRow* sql_heavy_table_get (SQLHeavyTable* self, gint64 id, GError** error) {
	SQLHeavyRow* result = NULL;
	gint64 _tmp0_;
	SQLHeavyRow* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = id;
	_tmp1_ = sql_heavy_row_new (self, _tmp0_);
	result = _tmp1_;
	return result;
}


/**
     * Register the triggers necessary for change notifications
     */
void sql_heavy_table_register_notify_triggers (SQLHeavyTable* self, GError** error) {
	SQLHeavyQueryable* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_ = NULL;
	const gchar* _tmp3_;
	const gchar* _tmp4_ = NULL;
	const gchar* _tmp5_;
	const gchar* _tmp6_ = NULL;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_;
	SQLHeavyQueryResult* _tmp9_ = NULL;
	SQLHeavyQueryResult* _tmp10_;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_queryable;
	_tmp1_ = self->priv->_name;
	_tmp2_ = string_to_string (_tmp1_);
	_tmp3_ = self->priv->_name;
	_tmp4_ = string_to_string (_tmp3_);
	_tmp5_ = self->priv->_name;
	_tmp6_ = string_to_string (_tmp5_);
	_tmp7_ = g_strconcat ("CREATE TEMPORARY TRIGGER IF NOT EXISTS `__SQLHeavy_", _tmp2_, "_update_notifier` AFTER UPDATE ON `", _tmp4_, "` FOR EACH ROW BEGIN SELECT __SQLHeavy_notify (1, '", _tmp6_, "', `OLD`.`ROWID`); END;", NULL);
	_tmp8_ = _tmp7_;
	_tmp9_ = sql_heavy_queryable_execute (_tmp0_, _tmp8_, &_inner_error_, NULL);
	_tmp10_ = _tmp9_;
	_g_object_unref0 (_tmp10_);
	_g_free0 (_tmp8_);
	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;
		}
	}
}


/**
     * Create a new cursor of this table
     */
SQLHeavyTableCursor* sql_heavy_table_iterator (SQLHeavyTable* self) {
	SQLHeavyTableCursor* result = NULL;
	SQLHeavyTableCursor* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = sql_heavy_table_cursor_new (self);
	result = _tmp0_;
	return result;
}


static gint64* _int64_dup (gint64* self) {
	gint64* dup;
	dup = g_new0 (gint64, 1);
	memcpy (dup, self, sizeof (gint64));
	return dup;
}


static gpointer __int64_dup0 (gpointer self) {
	return self ? _int64_dup (self) : NULL;
}


static gint _sql_heavy_row_compare_gcompare_data_func (gconstpointer a, gconstpointer b, gpointer self) {
	gint result;
	result = sql_heavy_row_compare (a, b);
	return result;
}


void sql_heavy_table_register_row (SQLHeavyTable* self, SQLHeavyRow* row) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	{
		GHashTable* _tmp0_;
		_tmp0_ = self->priv->child_rows;
		g_static_rec_mutex_lock (&self->priv->__lock_child_rows);
		{
			GHashTable* _tmp1_;
			SQLHeavyRow* _tmp2_;
			gint64 _tmp3_;
			gint64 _tmp4_;
			gconstpointer _tmp5_ = NULL;
			GSequence* list;
			GSequence* _tmp6_;
			GSequence* _tmp18_;
			SQLHeavyRow* _tmp19_;
			GSequenceIter* _tmp20_ = NULL;
			_tmp1_ = self->priv->child_rows;
			_tmp2_ = row;
			_tmp3_ = sql_heavy_row_get_id (_tmp2_);
			_tmp4_ = _tmp3_;
			_tmp5_ = g_hash_table_lookup (_tmp1_, &_tmp4_);
			list = (GSequence*) _tmp5_;
			_tmp6_ = list;
			if (_tmp6_ == NULL) {
				GHashTable* _tmp7_;
				SQLHeavyRow* _tmp8_;
				gint64 _tmp9_;
				gint64 _tmp10_;
				gint64* _tmp11_;
				GSequence* _tmp12_;
				GHashTable* _tmp13_;
				SQLHeavyRow* _tmp14_;
				gint64 _tmp15_;
				gint64 _tmp16_;
				gconstpointer _tmp17_ = NULL;
				_tmp7_ = self->priv->child_rows;
				_tmp8_ = row;
				_tmp9_ = sql_heavy_row_get_id (_tmp8_);
				_tmp10_ = _tmp9_;
				_tmp11_ = __int64_dup0 (&_tmp10_);
				_tmp12_ = g_sequence_new (NULL);
				g_hash_table_insert (_tmp7_, _tmp11_, _tmp12_);
				_tmp13_ = self->priv->child_rows;
				_tmp14_ = row;
				_tmp15_ = sql_heavy_row_get_id (_tmp14_);
				_tmp16_ = _tmp15_;
				_tmp17_ = g_hash_table_lookup (_tmp13_, &_tmp16_);
				list = (GSequence*) _tmp17_;
			}
			_tmp18_ = list;
			_tmp19_ = row;
			_tmp20_ = g_sequence_insert_sorted (_tmp18_, _tmp19_, _sql_heavy_row_compare_gcompare_data_func, NULL);
		}
		__finally36:
		{
			GHashTable* _tmp21_;
			_tmp21_ = self->priv->child_rows;
			g_static_rec_mutex_unlock (&self->priv->__lock_child_rows);
		}
		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 gint _sql_heavy_row_direct_compare_gcompare_data_func (gconstpointer a, gconstpointer b, gpointer self) {
	gint result;
	result = sql_heavy_row_direct_compare (a, b);
	return result;
}


void sql_heavy_table_unregister_row (SQLHeavyTable* self, SQLHeavyRow* row) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	g_return_if_fail (row != NULL);
	{
		GHashTable* _tmp0_;
		_tmp0_ = self->priv->child_rows;
		g_static_rec_mutex_lock (&self->priv->__lock_child_rows);
		{
			GHashTable* _tmp1_;
			SQLHeavyRow* _tmp2_;
			gint64 _tmp3_;
			gint64 _tmp4_;
			gconstpointer _tmp5_ = NULL;
			GSequence* list;
			GSequence* _tmp6_;
			_tmp1_ = self->priv->child_rows;
			_tmp2_ = row;
			_tmp3_ = sql_heavy_row_get_id (_tmp2_);
			_tmp4_ = _tmp3_;
			_tmp5_ = g_hash_table_lookup (_tmp1_, &_tmp4_);
			list = (GSequence*) _tmp5_;
			_tmp6_ = list;
			if (_tmp6_ != NULL) {
				GSequence* _tmp7_;
				SQLHeavyRow* _tmp8_;
				GSequenceIter* _tmp9_ = NULL;
				GSequenceIter* _tmp10_ = NULL;
				GSequenceIter* iter;
				GSequenceIter* _tmp11_;
				gconstpointer _tmp12_ = NULL;
				SQLHeavyRow* r2;
				SQLHeavyRow* _tmp13_;
				SQLHeavyRow* _tmp14_;
				_tmp7_ = list;
				_tmp8_ = row;
				_tmp9_ = g_sequence_search (_tmp7_, _tmp8_, _sql_heavy_row_direct_compare_gcompare_data_func, NULL);
				_tmp10_ = g_sequence_iter_prev (_tmp9_);
				iter = _tmp10_;
				_tmp11_ = iter;
				_tmp12_ = g_sequence_get (_tmp11_);
				r2 = (SQLHeavyRow*) _tmp12_;
				_tmp13_ = row;
				_tmp14_ = r2;
				if (((guint) _tmp13_) == ((guint) _tmp14_)) {
					GSequence* _tmp15_;
					GSequenceIter* _tmp16_;
					_tmp15_ = list;
					_tmp16_ = iter;
					g_sequence_remove (_tmp16_);
				}
			}
		}
		__finally37:
		{
			GHashTable* _tmp17_;
			_tmp17_ = self->priv->child_rows;
			g_static_rec_mutex_unlock (&self->priv->__lock_child_rows);
		}
		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;
		}
	}
}


/**
     * Compare two tables
     *
     * @param a the first table
     * @param b the second table
     * @return less than, equal to, or greater than 0 depending on a's relationship to b
     */
gint sql_heavy_table_compare (SQLHeavyTable* a, SQLHeavyTable* b) {
	gint result = 0;
	gint r;
	SQLHeavyTable* _tmp0_;
	SQLHeavyTable* _tmp1_;
	SQLHeavyTable* _tmp2_;
	SQLHeavyTable* _tmp3_;
	SQLHeavyTable* _tmp4_;
	SQLHeavyQueryable* _tmp5_;
	SQLHeavyDatabase* _tmp6_;
	SQLHeavyDatabase* _tmp7_;
	SQLHeavyDatabase* _tmp8_;
	SQLHeavyTable* _tmp9_;
	SQLHeavyQueryable* _tmp10_;
	SQLHeavyDatabase* _tmp11_;
	SQLHeavyDatabase* _tmp12_;
	SQLHeavyDatabase* _tmp13_;
	gint _tmp14_ = 0;
	gint _tmp15_;
	gboolean _tmp16_;
	SQLHeavyTable* _tmp17_;
	SQLHeavyTable* _tmp18_;
	gint _tmp19_ = 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->_queryable;
	_tmp6_ = sql_heavy_queryable_get_database (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = _tmp7_;
	_tmp9_ = b;
	_tmp10_ = _tmp9_->priv->_queryable;
	_tmp11_ = sql_heavy_queryable_get_database (_tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = _tmp12_;
	_tmp14_ = sql_heavy_database_compare (_tmp8_, _tmp13_);
	r = _tmp14_;
	_tmp15_ = r;
	_tmp16_ = _tmp15_ != 0;
	_g_object_unref0 (_tmp13_);
	_g_object_unref0 (_tmp8_);
	if (_tmp16_) {
		result = r;
		return result;
	}
	_tmp17_ = a;
	_tmp18_ = b;
	_tmp19_ = sql_heavy_table_direct_compare (_tmp17_, _tmp18_);
	result = _tmp19_;
	return result;
}


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


/**
     * Load a table
     *
     * @param queryable the queryable to load the table from
     * @param name the name of the table
     */
SQLHeavyTable* sql_heavy_table_construct (GType object_type, SQLHeavyQueryable* queryable, const gchar* name, GError** error) {
	SQLHeavyTable * self = NULL;
	SQLHeavyQueryable* _tmp0_;
	const gchar* _tmp1_;
	g_return_val_if_fail (queryable != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = queryable;
	_tmp1_ = name;
	self = (SQLHeavyTable*) g_object_new (object_type, "queryable", _tmp0_, "name", _tmp1_, NULL);
	return self;
}


SQLHeavyTable* sql_heavy_table_new (SQLHeavyQueryable* queryable, const gchar* name, GError** error) {
	return sql_heavy_table_construct (SQL_HEAVY_TYPE_TABLE, queryable, name, error);
}


const gchar* sql_heavy_table_get_name (SQLHeavyTable* self) {
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_name;
	result = _tmp0_;
	return result;
}


static void sql_heavy_table_set_name (SQLHeavyTable* self, const gchar* value) {
	const gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (self->priv->_name);
	self->priv->_name = _tmp1_;
	g_object_notify ((GObject *) self, "name");
}


SQLHeavyQueryable* sql_heavy_table_get_queryable (SQLHeavyTable* self) {
	SQLHeavyQueryable* result;
	SQLHeavyQueryable* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_queryable;
	result = _tmp0_;
	return result;
}


static void sql_heavy_table_set_queryable (SQLHeavyTable* self, SQLHeavyQueryable* value) {
	SQLHeavyQueryable* _tmp0_;
	SQLHeavyQueryable* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->_queryable);
	self->priv->_queryable = _tmp1_;
	g_object_notify ((GObject *) self, "queryable");
}


gint sql_heavy_table_get_field_count (SQLHeavyTable* self) {
	gint result;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, 0);
	{
		GSequence* _tmp0_ = NULL;
		GSequence* _tmp1_;
		gint _tmp2_ = 0;
		_tmp0_ = sql_heavy_table_get_field_data (self, &_inner_error_);
		_tmp1_ = _tmp0_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch38_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 0;
		}
		_tmp2_ = g_sequence_get_length (_tmp1_);
		result = _tmp2_;
		return result;
	}
	goto __finally38;
	__catch38_sql_heavy_error:
	{
		GError* e = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		GError* _tmp5_;
		gint _tmp6_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->code;
		g_critical ("sqlheavy-table.vala:152: Unable to get number of fields: %s (%d)", _tmp4_, _tmp6_);
		result = -1;
		_g_error_free0 (e);
		return result;
	}
	__finally38:
	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;
}


gint sql_heavy_table_get_foreign_key_count (SQLHeavyTable* self) {
	gint result;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, 0);
	{
		GSequence* _tmp0_ = NULL;
		GSequence* _tmp1_;
		gint _tmp2_ = 0;
		_tmp0_ = sql_heavy_table_get_foreign_key_data (self, &_inner_error_);
		_tmp1_ = _tmp0_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch39_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 0;
		}
		_tmp2_ = g_sequence_get_length (_tmp1_);
		result = _tmp2_;
		return result;
	}
	goto __finally39;
	__catch39_sql_heavy_error:
	{
		GError* e = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		GError* _tmp5_;
		gint _tmp6_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->code;
		g_critical ("sqlheavy-table.vala:221: Unable to get number of foreign keys: %s (%d)", _tmp4_, _tmp6_);
		result = -1;
		_g_error_free0 (e);
		return result;
	}
	__finally39:
	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;
}


static void g_cclosure_user_marshal_VOID__INT64 (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data) {
	typedef void (*GMarshalFunc_VOID__INT64) (gpointer data1, gint64 arg_1, gpointer data2);
	register GMarshalFunc_VOID__INT64 callback;
	register GCClosure * cc;
	register gpointer data1;
	register gpointer data2;
	cc = (GCClosure *) closure;
	g_return_if_fail (n_param_values == 2);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_VOID__INT64) (marshal_data ? marshal_data : cc->callback);
	callback (data1, g_value_get_int64 (param_values + 1), data2);
}


static void sql_heavy_table_real_row_modified (SQLHeavyTable* self, gint64 row_id) {
	gint64 _tmp0_;
	_tmp0_ = row_id;
	sql_heavy_table_row_modified_handler (self, _tmp0_);
}


static GObject * sql_heavy_table_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	SQLHeavyTable * self;
	SQLHeavyQueryable* _tmp0_;
	SQLHeavyDatabase* _tmp1_;
	SQLHeavyDatabase* _tmp2_;
	SQLHeavyDatabase* _tmp3_;
	parent_class = G_OBJECT_CLASS (sql_heavy_table_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = SQL_HEAVY_TABLE (obj);
	_tmp0_ = self->priv->_queryable;
	_tmp1_ = sql_heavy_queryable_get_database (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_;
	sql_heavy_database_register_orm_table (_tmp3_, self);
	_g_object_unref0 (_tmp3_);
	return obj;
}


static SQLHeavyTableFieldInfo* sql_heavy_table_field_info_construct_from_query_result (GType object_type, SQLHeavyQueryResult* query_result, GError** error) {
	SQLHeavyTableFieldInfo * self = NULL;
	SQLHeavyQueryResult* _tmp0_;
	gint _tmp1_ = 0;
	gint _tmp2_;
	SQLHeavyQueryResult* _tmp3_;
	gchar* _tmp4_ = NULL;
	gchar* _tmp5_;
	SQLHeavyQueryResult* _tmp6_;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_;
	SQLHeavyQueryResult* _tmp9_;
	gint _tmp10_ = 0;
	gint _tmp11_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (query_result != NULL, NULL);
	self = (SQLHeavyTableFieldInfo*) g_object_new (object_type, NULL);
	_tmp0_ = query_result;
	_tmp1_ = sql_heavy_record_fetch_int ((SQLHeavyRecord*) _tmp0_, 0, &_inner_error_);
	_tmp2_ = _tmp1_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (self);
			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;
		}
	}
	self->index = _tmp2_;
	_tmp3_ = query_result;
	_tmp4_ = sql_heavy_record_fetch_string ((SQLHeavyRecord*) _tmp3_, 1, &_inner_error_);
	_tmp5_ = _tmp4_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (self);
			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;
		}
	}
	_g_free0 (self->name);
	self->name = _tmp5_;
	_tmp6_ = query_result;
	_tmp7_ = sql_heavy_record_fetch_string ((SQLHeavyRecord*) _tmp6_, 2, &_inner_error_);
	_tmp8_ = _tmp7_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (self);
			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;
		}
	}
	_g_free0 (self->affinity);
	self->affinity = _tmp8_;
	_tmp9_ = query_result;
	_tmp10_ = sql_heavy_record_fetch_int ((SQLHeavyRecord*) _tmp9_, 3, &_inner_error_);
	_tmp11_ = _tmp10_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (self);
			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;
		}
	}
	self->not_null = _tmp11_ > 0;
	return self;
}


static SQLHeavyTableFieldInfo* sql_heavy_table_field_info_new_from_query_result (SQLHeavyQueryResult* query_result, GError** error) {
	return sql_heavy_table_field_info_construct_from_query_result (SQL_HEAVY_TABLE_TYPE_FIELD_INFO, query_result, error);
}


static SQLHeavyTableFieldInfo* sql_heavy_table_field_info_construct (GType object_type) {
	SQLHeavyTableFieldInfo * self = NULL;
	self = (SQLHeavyTableFieldInfo*) g_object_new (object_type, NULL);
	return self;
}


static SQLHeavyTableFieldInfo* sql_heavy_table_field_info_new (void) {
	return sql_heavy_table_field_info_construct (SQL_HEAVY_TABLE_TYPE_FIELD_INFO);
}


static void sql_heavy_table_field_info_class_init (SQLHeavyTableFieldInfoClass * klass) {
	sql_heavy_table_field_info_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = sql_heavy_table_field_info_finalize;
}


static void sql_heavy_table_field_info_instance_init (SQLHeavyTableFieldInfo * self) {
}


static void sql_heavy_table_field_info_finalize (GObject* obj) {
	SQLHeavyTableFieldInfo * self;
	self = SQL_HEAVY_TABLE_FIELD_INFO (obj);
	_g_free0 (self->name);
	_g_free0 (self->affinity);
	G_OBJECT_CLASS (sql_heavy_table_field_info_parent_class)->finalize (obj);
}


static GType sql_heavy_table_field_info_get_type (void) {
	static volatile gsize sql_heavy_table_field_info_type_id__volatile = 0;
	if (g_once_init_enter (&sql_heavy_table_field_info_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (SQLHeavyTableFieldInfoClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) sql_heavy_table_field_info_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SQLHeavyTableFieldInfo), 0, (GInstanceInitFunc) sql_heavy_table_field_info_instance_init, NULL };
		GType sql_heavy_table_field_info_type_id;
		sql_heavy_table_field_info_type_id = g_type_register_static (G_TYPE_OBJECT, "SQLHeavyTableFieldInfo", &g_define_type_info, 0);
		g_once_init_leave (&sql_heavy_table_field_info_type_id__volatile, sql_heavy_table_field_info_type_id);
	}
	return sql_heavy_table_field_info_type_id__volatile;
}


static SQLHeavyTableForeignKeyInfo* sql_heavy_table_foreign_key_info_construct_from_query_result (GType object_type, SQLHeavyQueryResult* query_result, GError** error) {
	SQLHeavyTableForeignKeyInfo * self = NULL;
	SQLHeavyQueryResult* _tmp0_;
	gint _tmp1_ = 0;
	gint _tmp2_;
	SQLHeavyQueryResult* _tmp3_;
	gint _tmp4_ = 0;
	gint _tmp5_;
	SQLHeavyQueryResult* _tmp6_;
	gchar* _tmp7_ = NULL;
	gchar* _tmp8_;
	SQLHeavyQueryResult* _tmp9_;
	gchar* _tmp10_ = NULL;
	gchar* _tmp11_;
	SQLHeavyQueryResult* _tmp12_;
	gchar* _tmp13_ = NULL;
	gchar* _tmp14_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (query_result != NULL, NULL);
	self = (SQLHeavyTableForeignKeyInfo*) g_object_new (object_type, NULL);
	_tmp0_ = query_result;
	_tmp1_ = sql_heavy_record_fetch_int ((SQLHeavyRecord*) _tmp0_, 0, &_inner_error_);
	_tmp2_ = _tmp1_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (self);
			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;
		}
	}
	self->id = _tmp2_;
	_tmp3_ = query_result;
	_tmp4_ = sql_heavy_record_fetch_int ((SQLHeavyRecord*) _tmp3_, 1, &_inner_error_);
	_tmp5_ = _tmp4_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (self);
			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;
		}
	}
	self->seq = _tmp5_;
	_tmp6_ = query_result;
	_tmp7_ = sql_heavy_record_fetch_string ((SQLHeavyRecord*) _tmp6_, 2, &_inner_error_);
	_tmp8_ = _tmp7_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (self);
			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;
		}
	}
	_g_free0 (self->table);
	self->table = _tmp8_;
	_tmp9_ = query_result;
	_tmp10_ = sql_heavy_record_fetch_string ((SQLHeavyRecord*) _tmp9_, 3, &_inner_error_);
	_tmp11_ = _tmp10_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (self);
			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;
		}
	}
	_g_free0 (self->from);
	self->from = _tmp11_;
	_tmp12_ = query_result;
	_tmp13_ = sql_heavy_record_fetch_string ((SQLHeavyRecord*) _tmp12_, 4, &_inner_error_);
	_tmp14_ = _tmp13_;
	if (_inner_error_ != NULL) {
		if (_inner_error_->domain == SQL_HEAVY_ERROR) {
			g_propagate_error (error, _inner_error_);
			_g_object_unref0 (self);
			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;
		}
	}
	_g_free0 (self->to);
	self->to = _tmp14_;
	return self;
}


static SQLHeavyTableForeignKeyInfo* sql_heavy_table_foreign_key_info_new_from_query_result (SQLHeavyQueryResult* query_result, GError** error) {
	return sql_heavy_table_foreign_key_info_construct_from_query_result (SQL_HEAVY_TABLE_TYPE_FOREIGN_KEY_INFO, query_result, error);
}


static SQLHeavyTableForeignKeyInfo* sql_heavy_table_foreign_key_info_construct (GType object_type) {
	SQLHeavyTableForeignKeyInfo * self = NULL;
	self = (SQLHeavyTableForeignKeyInfo*) g_object_new (object_type, NULL);
	return self;
}


static SQLHeavyTableForeignKeyInfo* sql_heavy_table_foreign_key_info_new (void) {
	return sql_heavy_table_foreign_key_info_construct (SQL_HEAVY_TABLE_TYPE_FOREIGN_KEY_INFO);
}


static void sql_heavy_table_foreign_key_info_class_init (SQLHeavyTableForeignKeyInfoClass * klass) {
	sql_heavy_table_foreign_key_info_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = sql_heavy_table_foreign_key_info_finalize;
}


static void sql_heavy_table_foreign_key_info_instance_init (SQLHeavyTableForeignKeyInfo * self) {
}


static void sql_heavy_table_foreign_key_info_finalize (GObject* obj) {
	SQLHeavyTableForeignKeyInfo * self;
	self = SQL_HEAVY_TABLE_FOREIGN_KEY_INFO (obj);
	_g_free0 (self->table);
	_g_free0 (self->from);
	_g_free0 (self->to);
	G_OBJECT_CLASS (sql_heavy_table_foreign_key_info_parent_class)->finalize (obj);
}


static GType sql_heavy_table_foreign_key_info_get_type (void) {
	static volatile gsize sql_heavy_table_foreign_key_info_type_id__volatile = 0;
	if (g_once_init_enter (&sql_heavy_table_foreign_key_info_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (SQLHeavyTableForeignKeyInfoClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) sql_heavy_table_foreign_key_info_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SQLHeavyTableForeignKeyInfo), 0, (GInstanceInitFunc) sql_heavy_table_foreign_key_info_instance_init, NULL };
		GType sql_heavy_table_foreign_key_info_type_id;
		sql_heavy_table_foreign_key_info_type_id = g_type_register_static (G_TYPE_OBJECT, "SQLHeavyTableForeignKeyInfo", &g_define_type_info, 0);
		g_once_init_leave (&sql_heavy_table_foreign_key_info_type_id__volatile, sql_heavy_table_foreign_key_info_type_id);
	}
	return sql_heavy_table_foreign_key_info_type_id__volatile;
}


static void sql_heavy_table_class_init (SQLHeavyTableClass * klass) {
	sql_heavy_table_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (SQLHeavyTablePrivate));
	SQL_HEAVY_TABLE_CLASS (klass)->row_modified = sql_heavy_table_real_row_modified;
	G_OBJECT_CLASS (klass)->get_property = _vala_sql_heavy_table_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_sql_heavy_table_set_property;
	G_OBJECT_CLASS (klass)->constructor = sql_heavy_table_constructor;
	G_OBJECT_CLASS (klass)->finalize = sql_heavy_table_finalize;
	/**
	     * Table name
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), SQL_HEAVY_TABLE_NAME, g_param_spec_string ("name", "name", "name", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	/**
	     * The queryable that this table is a member of
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), SQL_HEAVY_TABLE_QUERYABLE, g_param_spec_object ("queryable", "queryable", "queryable", SQL_HEAVY_TYPE_QUERYABLE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	/**
	     * Number of fields (columns) in the table
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), SQL_HEAVY_TABLE_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));
	/**
	     * Number of foreign keys which reference a column in the table
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), SQL_HEAVY_TABLE_FOREIGN_KEY_COUNT, g_param_spec_int ("foreign-key-count", "foreign-key-count", "foreign-key-count", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
	/**
	     * A new row was inserted into the table
	     *
	     * @param row_id the ROWID of the row that was inserted
	     */
	g_signal_new ("row_inserted", SQL_HEAVY_TYPE_TABLE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT64, G_TYPE_NONE, 1, G_TYPE_INT64);
	/**
	     * A row was deleted from the table
	     *
	     * @param row_id the ROWID of the row that was deleted
	     */
	g_signal_new ("row_deleted", SQL_HEAVY_TYPE_TABLE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__INT64, G_TYPE_NONE, 1, G_TYPE_INT64);
	/**
	     * A row in the table was modified
	     *
	     * @param row_id the ROWID of the row that was updated
	     */
	g_signal_new ("row_modified", SQL_HEAVY_TYPE_TABLE, G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (SQLHeavyTableClass, row_modified), NULL, NULL, g_cclosure_user_marshal_VOID__INT64, G_TYPE_NONE, 1, G_TYPE_INT64);
}


static void sql_heavy_table_instance_init (SQLHeavyTable * self) {
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GDestroyNotify _tmp2_;
	GHashTable* _tmp3_;
	self->priv = SQL_HEAVY_TABLE_GET_PRIVATE (self);
	g_static_rec_mutex_init (&self->priv->__lock_child_rows);
	_tmp0_ = g_int64_hash;
	_tmp1_ = g_int64_equal;
	_tmp2_ = g_free;
	_tmp3_ = g_hash_table_new_full (_tmp0_, _tmp1_, _tmp2_, (GDestroyNotify) g_sequence_free);
	self->priv->child_rows = _tmp3_;
	g_static_rec_mutex_init (&self->priv->__lock__field_data);
	self->priv->_field_data = NULL;
	self->priv->_field_names = NULL;
	g_static_rec_mutex_init (&self->priv->__lock__foreign_key_data);
	self->priv->_foreign_key_data = NULL;
	self->priv->_foreign_key_names = NULL;
}


static void sql_heavy_table_finalize (GObject* obj) {
	SQLHeavyTable * self;
	self = SQL_HEAVY_TABLE (obj);
	_g_free0 (self->priv->_name);
	_g_object_unref0 (self->priv->_queryable);
	g_static_rec_mutex_free (&self->priv->__lock_child_rows);
	_g_hash_table_unref0 (self->priv->child_rows);
	g_static_rec_mutex_free (&self->priv->__lock__field_data);
	_g_sequence_free0 (self->priv->_field_data);
	_g_hash_table_unref0 (self->priv->_field_names);
	g_static_rec_mutex_free (&self->priv->__lock__foreign_key_data);
	_g_sequence_free0 (self->priv->_foreign_key_data);
	_g_hash_table_unref0 (self->priv->_foreign_key_names);
	G_OBJECT_CLASS (sql_heavy_table_parent_class)->finalize (obj);
}


/**
   * A database table
   */
GType sql_heavy_table_get_type (void) {
	static volatile gsize sql_heavy_table_type_id__volatile = 0;
	if (g_once_init_enter (&sql_heavy_table_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (SQLHeavyTableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) sql_heavy_table_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SQLHeavyTable), 0, (GInstanceInitFunc) sql_heavy_table_instance_init, NULL };
		GType sql_heavy_table_type_id;
		sql_heavy_table_type_id = g_type_register_static (G_TYPE_OBJECT, "SQLHeavyTable", &g_define_type_info, 0);
		g_once_init_leave (&sql_heavy_table_type_id__volatile, sql_heavy_table_type_id);
	}
	return sql_heavy_table_type_id__volatile;
}


static void _vala_sql_heavy_table_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	SQLHeavyTable * self;
	self = SQL_HEAVY_TABLE (object);
	switch (property_id) {
		case SQL_HEAVY_TABLE_NAME:
		g_value_set_string (value, sql_heavy_table_get_name (self));
		break;
		case SQL_HEAVY_TABLE_QUERYABLE:
		g_value_set_object (value, sql_heavy_table_get_queryable (self));
		break;
		case SQL_HEAVY_TABLE_FIELD_COUNT:
		g_value_set_int (value, sql_heavy_table_get_field_count (self));
		break;
		case SQL_HEAVY_TABLE_FOREIGN_KEY_COUNT:
		g_value_set_int (value, sql_heavy_table_get_foreign_key_count (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_sql_heavy_table_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	SQLHeavyTable * self;
	self = SQL_HEAVY_TABLE (object);
	switch (property_id) {
		case SQL_HEAVY_TABLE_NAME:
		sql_heavy_table_set_name (self, g_value_get_string (value));
		break;
		case SQL_HEAVY_TABLE_QUERYABLE:
		sql_heavy_table_set_queryable (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



