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


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

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _SQLHeavyGtkModelPrivate {
	SQLHeavyTable* _table;
	SQLHeavyQueryable* queryable;
	gint get_value_calls;
	gint next_calls;
};


static gpointer sql_heavy_gtk_model_parent_class = NULL;
static GtkTreeModelIface* sql_heavy_gtk_model_gtk_tree_model_parent_iface = NULL;

#define SQL_HEAVY_GTK_MODEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SQL_HEAVY_GTK_TYPE_MODEL, SQLHeavyGtkModelPrivate))
enum  {
	SQL_HEAVY_GTK_MODEL_DUMMY_PROPERTY,
	SQL_HEAVY_GTK_MODEL_TABLE
};
static SQLHeavyRow* sql_heavy_gtk_model_get_row_from_iter (SQLHeavyGtkModel* self, GtkTreeIter* iter);
static GType sql_heavy_gtk_model_real_get_column_type (GtkTreeModel* base, gint index);
static GtkTreeModelFlags sql_heavy_gtk_model_real_get_flags (GtkTreeModel* base);
static gboolean sql_heavy_gtk_model_real_get_iter (GtkTreeModel* base, GtkTreeIter* iter, GtkTreePath* path);
static gint sql_heavy_gtk_model_real_get_n_columns (GtkTreeModel* base);
static GtkTreePath* sql_heavy_gtk_model_real_get_path (GtkTreeModel* base, GtkTreeIter* iter);
static void sql_heavy_gtk_model_real_get_value (GtkTreeModel* base, GtkTreeIter* iter, gint column, GValue* value);
static gboolean sql_heavy_gtk_model_real_iter_children (GtkTreeModel* base, GtkTreeIter* iter, GtkTreeIter* parent);
static gboolean sql_heavy_gtk_model_real_iter_has_child (GtkTreeModel* base, GtkTreeIter* iter);
static gint sql_heavy_gtk_model_real_iter_n_children (GtkTreeModel* base, GtkTreeIter* iter);
static gboolean sql_heavy_gtk_model_real_iter_next (GtkTreeModel* base, GtkTreeIter* iter);
static gboolean sql_heavy_gtk_model_real_iter_nth_child (GtkTreeModel* base, GtkTreeIter* iter, GtkTreeIter* parent, gint n);
static gboolean sql_heavy_gtk_model_real_iter_parent (GtkTreeModel* base, GtkTreeIter* iter, GtkTreeIter* child);
static void sql_heavy_gtk_model_real_ref_node (SQLHeavyGtkModel* self, GtkTreeIter* iter);
static void sql_heavy_gtk_model_real_unref_node (SQLHeavyGtkModel* self, GtkTreeIter* iter);
static void sql_heavy_gtk_model_finalize (GObject* obj);
static void _vala_sql_heavy_gtk_model_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_sql_heavy_gtk_model_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);


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


static SQLHeavyRow* sql_heavy_gtk_model_get_row_from_iter (SQLHeavyGtkModel* self, GtkTreeIter* iter) {
	SQLHeavyRow* result = NULL;
	GtkTreeIter _tmp0_;
	void* _tmp1_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (iter != NULL, NULL);
	_tmp0_ = *iter;
	_tmp1_ = _tmp0_.user_data;
	if (_tmp1_ != NULL) {
		GtkTreeIter _tmp2_;
		void* _tmp3_;
		SQLHeavyRow* _tmp4_;
		_tmp2_ = *iter;
		_tmp3_ = _tmp2_.user_data;
		_tmp4_ = _g_object_ref0 (SQL_HEAVY_ROW (_tmp3_));
		result = _tmp4_;
		return result;
	} else {
		{
			SQLHeavyTable* _tmp5_;
			SQLHeavyTable* _tmp6_;
			GtkTreeIter _tmp7_;
			gint _tmp8_;
			SQLHeavyRow* _tmp9_ = NULL;
			SQLHeavyRow* row;
			SQLHeavyRow* _tmp10_;
			SQLHeavyRow* _tmp11_;
			_tmp5_ = sql_heavy_gtk_model_get_table (self);
			_tmp6_ = _tmp5_;
			_tmp7_ = *iter;
			_tmp8_ = _tmp7_.stamp;
			_tmp9_ = sql_heavy_table_get (_tmp6_, (gint64) _tmp8_, &_inner_error_);
			row = _tmp9_;
			if (_inner_error_ != NULL) {
				if (_inner_error_->domain == SQL_HEAVY_ERROR) {
					goto __catch0_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 NULL;
			}
			_tmp10_ = row;
			(*iter).user_data = _tmp10_;
			_tmp11_ = row;
			g_object_ref ((GObject*) _tmp11_);
			result = row;
			return result;
		}
		goto __finally0;
		__catch0_sql_heavy_error:
		{
			GError* e = NULL;
			GError* _tmp12_;
			const gchar* _tmp13_;
			e = _inner_error_;
			_inner_error_ = NULL;
			_tmp12_ = e;
			_tmp13_ = _tmp12_->message;
			g_critical ("sqlheavy-gtk-model.vala:36: Unable to get row from iterator: %s", _tmp13_);
			result = NULL;
			_g_error_free0 (e);
			return result;
		}
		__finally0:
		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;
	}
}


static GType sql_heavy_gtk_model_real_get_column_type (GtkTreeModel* base, gint index) {
	SQLHeavyGtkModel * self;
	GType result = 0UL;
	GError * _inner_error_ = NULL;
	self = (SQLHeavyGtkModel*) base;
	{
		gint _tmp0_;
		_tmp0_ = index;
		if (_tmp0_ == 0) {
			result = G_TYPE_INT64;
			return result;
		} else {
			SQLHeavyTable* _tmp1_;
			SQLHeavyTable* _tmp2_;
			gint _tmp3_;
			GType _tmp4_ = 0UL;
			GType _tmp5_;
			_tmp1_ = sql_heavy_gtk_model_get_table (self);
			_tmp2_ = _tmp1_;
			_tmp3_ = index;
			_tmp4_ = sql_heavy_table_field_affinity_type (_tmp2_, _tmp3_ - 1, &_inner_error_);
			_tmp5_ = _tmp4_;
			if (_inner_error_ != NULL) {
				if (_inner_error_->domain == SQL_HEAVY_ERROR) {
					goto __catch1_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 0UL;
			}
			result = _tmp5_;
			return result;
		}
	}
	goto __finally1;
	__catch1_sql_heavy_error:
	{
		GError* e = NULL;
		gint _tmp6_;
		GError* _tmp7_;
		const gchar* _tmp8_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp6_ = index;
		_tmp7_ = e;
		_tmp8_ = _tmp7_->message;
		g_critical ("sqlheavy-gtk-model.vala:51: Unable to determine column affinity (colum" \
"n #%d): %s", _tmp6_, _tmp8_);
		result = G_TYPE_NONE;
		_g_error_free0 (e);
		return result;
	}
	__finally1:
	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;
}


static GtkTreeModelFlags sql_heavy_gtk_model_real_get_flags (GtkTreeModel* base) {
	SQLHeavyGtkModel * self;
	GtkTreeModelFlags result = 0;
	self = (SQLHeavyGtkModel*) base;
	result = GTK_TREE_MODEL_LIST_ONLY;
	return result;
}


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 gboolean sql_heavy_gtk_model_real_get_iter (GtkTreeModel* base, GtkTreeIter* iter, GtkTreePath* path) {
	SQLHeavyGtkModel * self;
	GtkTreeIter _vala_iter = {0};
	gboolean result = FALSE;
	gint64 offset;
	GtkTreePath* _tmp0_;
	gint _tmp1_ = 0;
	gint* _tmp2_ = NULL;
	gint* indices;
	gint indices_length1;
	gint _indices_size_;
	gint* _tmp3_;
	gint _tmp3__length1;
	GError * _inner_error_ = NULL;
	self = (SQLHeavyGtkModel*) base;
	g_return_val_if_fail (path != NULL, FALSE);
	offset = (gint64) 0;
	_tmp0_ = path;
	_tmp2_ = gtk_tree_path_get_indices_with_depth (_tmp0_, &_tmp1_);
	indices = _tmp2_;
	indices_length1 = _tmp1_;
	_indices_size_ = indices_length1;
	_tmp3_ = indices;
	_tmp3__length1 = indices_length1;
	if (_tmp3__length1 == (-1)) {
		offset = (gint64) 0;
	} else {
		gint* _tmp4_;
		gint _tmp4__length1;
		_tmp4_ = indices;
		_tmp4__length1 = indices_length1;
		if (_tmp4__length1 == 1) {
			gint* _tmp5_;
			gint _tmp5__length1;
			gint _tmp6_;
			_tmp5_ = indices;
			_tmp5__length1 = indices_length1;
			_tmp6_ = _tmp5_[0];
			offset = (gint64) _tmp6_;
		} else {
			result = FALSE;
			if (iter) {
				*iter = _vala_iter;
			}
			return result;
		}
	}
	{
		SQLHeavyQueryable* _tmp7_;
		SQLHeavyTable* _tmp8_;
		SQLHeavyTable* _tmp9_;
		const gchar* _tmp10_;
		const gchar* _tmp11_;
		gchar* _tmp12_ = NULL;
		gchar* _tmp13_;
		const gchar* _tmp14_ = NULL;
		gint* _tmp15_;
		gint _tmp15__length1;
		gint _tmp16_;
		gchar* _tmp17_ = NULL;
		gchar* _tmp18_;
		gchar* _tmp19_ = NULL;
		gchar* _tmp20_;
		SQLHeavyQuery* _tmp21_ = NULL;
		SQLHeavyQuery* _tmp22_;
		SQLHeavyQuery* _tmp23_;
		SQLHeavyQuery* _tmp24_;
		SQLHeavyQueryResult* _tmp25_ = NULL;
		SQLHeavyQueryResult* _tmp26_;
		SQLHeavyQueryResult* res;
		SQLHeavyQueryResult* _tmp27_;
		gboolean _tmp28_;
		gboolean _tmp29_;
		SQLHeavyQueryResult* _tmp30_;
		gint _tmp31_ = 0;
		gint _tmp32_;
		_tmp7_ = self->priv->queryable;
		_tmp8_ = sql_heavy_gtk_model_get_table (self);
		_tmp9_ = _tmp8_;
		_tmp10_ = sql_heavy_table_get_name (_tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = sql_heavy_escape_string (_tmp11_);
		_tmp13_ = _tmp12_;
		_tmp14_ = string_to_string (_tmp13_);
		_tmp15_ = indices;
		_tmp15__length1 = indices_length1;
		_tmp16_ = _tmp15_[0];
		_tmp17_ = g_strdup_printf ("%i", _tmp16_);
		_tmp18_ = _tmp17_;
		_tmp19_ = g_strconcat ("SELECT `ROWID` FROM `", _tmp14_, "` ORDER BY `ROWID` ASC LIMIT ", _tmp18_, ",1;", NULL);
		_tmp20_ = _tmp19_;
		_tmp21_ = sql_heavy_queryable_prepare (_tmp7_, _tmp20_, &_inner_error_);
		_tmp22_ = _tmp21_;
		_g_free0 (_tmp20_);
		_g_free0 (_tmp18_);
		_g_free0 (_tmp13_);
		_tmp23_ = _tmp22_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch2_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 FALSE;
		}
		_tmp24_ = _tmp23_;
		_tmp25_ = sql_heavy_query_execute (_tmp24_, NULL, &_inner_error_, NULL);
		_tmp26_ = _tmp25_;
		_g_object_unref0 (_tmp24_);
		res = _tmp26_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch2_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 FALSE;
		}
		_tmp27_ = res;
		_tmp28_ = sql_heavy_query_result_get_finished (_tmp27_);
		_tmp29_ = _tmp28_;
		if (_tmp29_) {
			result = FALSE;
			_g_object_unref0 (res);
			if (iter) {
				*iter = _vala_iter;
			}
			return result;
		}
		_tmp30_ = res;
		_tmp31_ = sql_heavy_record_fetch_int ((SQLHeavyRecord*) _tmp30_, 0, &_inner_error_);
		_tmp32_ = _tmp31_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (res);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch2_sql_heavy_error;
			}
			_g_object_unref0 (res);
			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 FALSE;
		}
		_vala_iter.stamp = _tmp32_;
		result = TRUE;
		_g_object_unref0 (res);
		if (iter) {
			*iter = _vala_iter;
		}
		return result;
	}
	goto __finally2;
	__catch2_sql_heavy_error:
	{
		GError* e = NULL;
		GError* _tmp33_;
		const gchar* _tmp34_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp33_ = e;
		_tmp34_ = _tmp33_->message;
		g_critical ("sqlheavy-gtk-model.vala:77: Unable to get row ID for iterator: %s", _tmp34_);
		result = FALSE;
		_g_error_free0 (e);
		if (iter) {
			*iter = _vala_iter;
		}
		return result;
	}
	__finally2:
	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 FALSE;
}


static gint sql_heavy_gtk_model_real_get_n_columns (GtkTreeModel* base) {
	SQLHeavyGtkModel * self;
	gint result = 0;
	SQLHeavyTable* _tmp0_;
	SQLHeavyTable* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	self = (SQLHeavyGtkModel*) base;
	_tmp0_ = sql_heavy_gtk_model_get_table (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = sql_heavy_table_get_field_count (_tmp1_);
	_tmp3_ = _tmp2_;
	result = _tmp3_ + 1;
	return result;
}


static GtkTreePath* sql_heavy_gtk_model_real_get_path (GtkTreeModel* base, GtkTreeIter* iter) {
	SQLHeavyGtkModel * self;
	GtkTreePath* result = NULL;
	GError * _inner_error_ = NULL;
	self = (SQLHeavyGtkModel*) base;
	g_return_val_if_fail (iter != NULL, NULL);
	{
		SQLHeavyQueryable* _tmp0_;
		SQLHeavyTable* _tmp1_;
		SQLHeavyTable* _tmp2_;
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		gchar* _tmp5_ = NULL;
		gchar* _tmp6_;
		const gchar* _tmp7_ = NULL;
		gchar* _tmp8_ = NULL;
		gchar* _tmp9_;
		SQLHeavyQuery* _tmp10_ = NULL;
		SQLHeavyQuery* _tmp11_;
		SQLHeavyQuery* _tmp12_;
		SQLHeavyQuery* _tmp13_;
		GtkTreeIter _tmp14_;
		gint _tmp15_;
		SQLHeavyQueryResult* _tmp16_ = NULL;
		SQLHeavyQueryResult* _tmp17_;
		SQLHeavyQueryResult* res;
		SQLHeavyQueryResult* _tmp18_;
		gint _tmp19_ = 0;
		gint _tmp20_;
		GtkTreePath* _tmp21_;
		_tmp0_ = self->priv->queryable;
		_tmp1_ = sql_heavy_gtk_model_get_table (self);
		_tmp2_ = _tmp1_;
		_tmp3_ = sql_heavy_table_get_name (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = sql_heavy_escape_string (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = string_to_string (_tmp6_);
		_tmp8_ = g_strconcat ("SELECT COUNT(*) FROM `", _tmp7_, "` WHERE `ROWID` < :rid ORDER BY `ROWID` ASC LIMIT 1", NULL);
		_tmp9_ = _tmp8_;
		_tmp10_ = sql_heavy_queryable_prepare (_tmp0_, _tmp9_, &_inner_error_);
		_tmp11_ = _tmp10_;
		_g_free0 (_tmp9_);
		_g_free0 (_tmp6_);
		_tmp12_ = _tmp11_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch3_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 NULL;
		}
		_tmp13_ = _tmp12_;
		_tmp14_ = *iter;
		_tmp15_ = _tmp14_.stamp;
		_tmp16_ = sql_heavy_query_execute (_tmp13_, ":rid", &_inner_error_, G_TYPE_INT, _tmp15_, NULL);
		_tmp17_ = _tmp16_;
		_g_object_unref0 (_tmp13_);
		res = _tmp17_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch3_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 NULL;
		}
		_tmp18_ = res;
		_tmp19_ = sql_heavy_record_fetch_int ((SQLHeavyRecord*) _tmp18_, 0, &_inner_error_);
		_tmp20_ = _tmp19_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (res);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch3_sql_heavy_error;
			}
			_g_object_unref0 (res);
			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 NULL;
		}
		_tmp21_ = gtk_tree_path_new_from_indices (_tmp20_, -1);
		result = _tmp21_;
		_g_object_unref0 (res);
		return result;
	}
	goto __finally3;
	__catch3_sql_heavy_error:
	{
		GError* e = NULL;
		GError* _tmp22_;
		const gchar* _tmp23_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp22_ = e;
		_tmp23_ = _tmp22_->message;
		g_critical ("sqlheavy-gtk-model.vala:91: Unable to get path from iterator: %s", _tmp23_);
		result = (gpointer) NULL;
		_g_error_free0 (e);
		return result;
	}
	__finally3:
	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;
}


static void sql_heavy_gtk_model_real_get_value (GtkTreeModel* base, GtkTreeIter* iter, gint column, GValue* value) {
	SQLHeavyGtkModel * self;
	GValue _vala_value = {0};
	GError * _inner_error_ = NULL;
	self = (SQLHeavyGtkModel*) base;
	g_return_if_fail (iter != NULL);
	{
		GtkTreeIter _tmp0_;
		SQLHeavyRow* _tmp1_ = NULL;
		SQLHeavyRow* row;
		gint _tmp2_;
		GValue _tmp3_ = {0};
		GValue _tmp4_;
		gboolean _tmp5_ = FALSE;
		_tmp0_ = *iter;
		_tmp1_ = sql_heavy_gtk_model_get_row_from_iter (self, &_tmp0_);
		row = _tmp1_;
		_tmp2_ = column;
		sql_heavy_record_fetch ((SQLHeavyRecord*) row, _tmp2_ - 1, &_tmp3_, &_inner_error_);
		_tmp4_ = _tmp3_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (row);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch4_sql_heavy_error;
			}
			_g_object_unref0 (row);
			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;
		}
		G_IS_VALUE (&_vala_value) ? (g_value_unset (&_vala_value), NULL) : NULL;
		_vala_value = _tmp4_;
		_tmp5_ = G_VALUE_HOLDS (&_vala_value, G_TYPE_POINTER);
		if (_tmp5_) {
			GValue _tmp6_ = {0};
			GValue _tmp7_;
			g_value_init (&_tmp6_, G_TYPE_STRING);
			G_IS_VALUE (&_vala_value) ? (g_value_unset (&_vala_value), NULL) : NULL;
			_vala_value = _tmp6_;
			_tmp7_ = _vala_value;
		}
		_g_object_unref0 (row);
	}
	goto __finally4;
	__catch4_sql_heavy_error:
	{
		GError* e = NULL;
		GError* _tmp8_;
		const gchar* _tmp9_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp8_ = e;
		_tmp9_ = _tmp8_->message;
		g_critical ("sqlheavy-gtk-model.vala:104: Unable to get value: %s", _tmp9_);
		_g_error_free0 (e);
	}
	__finally4:
	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;
	}
	if (value) {
		*value = _vala_value;
	} else {
		G_IS_VALUE (&_vala_value) ? (g_value_unset (&_vala_value), NULL) : NULL;
	}
}


static gboolean sql_heavy_gtk_model_real_iter_children (GtkTreeModel* base, GtkTreeIter* iter, GtkTreeIter* parent) {
	SQLHeavyGtkModel * self;
	GtkTreeIter _vala_iter = {0};
	gboolean result = FALSE;
	self = (SQLHeavyGtkModel*) base;
	result = FALSE;
	if (iter) {
		*iter = _vala_iter;
	}
	return result;
}


static gboolean sql_heavy_gtk_model_real_iter_has_child (GtkTreeModel* base, GtkTreeIter* iter) {
	SQLHeavyGtkModel * self;
	gboolean result = FALSE;
	self = (SQLHeavyGtkModel*) base;
	g_return_val_if_fail (iter != NULL, FALSE);
	result = FALSE;
	return result;
}


static gint sql_heavy_gtk_model_real_iter_n_children (GtkTreeModel* base, GtkTreeIter* iter) {
	SQLHeavyGtkModel * self;
	gint result = 0;
	self = (SQLHeavyGtkModel*) base;
	result = 0;
	return result;
}


static gboolean sql_heavy_gtk_model_real_iter_next (GtkTreeModel* base, GtkTreeIter* iter) {
	SQLHeavyGtkModel * self;
	gboolean result = FALSE;
	GError * _inner_error_ = NULL;
	self = (SQLHeavyGtkModel*) base;
	g_return_val_if_fail (iter != NULL, FALSE);
	{
		SQLHeavyQueryable* _tmp0_;
		SQLHeavyTable* _tmp1_;
		SQLHeavyTable* _tmp2_;
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		gchar* _tmp5_ = NULL;
		gchar* _tmp6_;
		const gchar* _tmp7_ = NULL;
		GtkTreeIter _tmp8_;
		gint _tmp9_;
		gchar* _tmp10_ = NULL;
		gchar* _tmp11_;
		gchar* _tmp12_ = NULL;
		gchar* _tmp13_;
		SQLHeavyQuery* _tmp14_ = NULL;
		SQLHeavyQuery* _tmp15_;
		SQLHeavyQuery* _tmp16_;
		SQLHeavyQuery* _tmp17_;
		SQLHeavyQueryResult* _tmp18_ = NULL;
		SQLHeavyQueryResult* _tmp19_;
		SQLHeavyQueryResult* res;
		SQLHeavyQueryResult* _tmp20_;
		gboolean _tmp21_;
		gboolean _tmp22_;
		_tmp0_ = self->priv->queryable;
		_tmp1_ = sql_heavy_gtk_model_get_table (self);
		_tmp2_ = _tmp1_;
		_tmp3_ = sql_heavy_table_get_name (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp5_ = sql_heavy_escape_string (_tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = string_to_string (_tmp6_);
		_tmp8_ = *iter;
		_tmp9_ = _tmp8_.stamp;
		_tmp10_ = g_strdup_printf ("%i", _tmp9_);
		_tmp11_ = _tmp10_;
		_tmp12_ = g_strconcat ("SELECT `ROWID` FROM `", _tmp7_, "` WHERE `ROWID` > ", _tmp11_, " ORDER BY `ROWID` ASC LIMIT 1", NULL);
		_tmp13_ = _tmp12_;
		_tmp14_ = sql_heavy_queryable_prepare (_tmp0_, _tmp13_, &_inner_error_);
		_tmp15_ = _tmp14_;
		_g_free0 (_tmp13_);
		_g_free0 (_tmp11_);
		_g_free0 (_tmp6_);
		_tmp16_ = _tmp15_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch5_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 FALSE;
		}
		_tmp17_ = _tmp16_;
		_tmp18_ = sql_heavy_query_execute (_tmp17_, NULL, &_inner_error_, NULL);
		_tmp19_ = _tmp18_;
		_g_object_unref0 (_tmp17_);
		res = _tmp19_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch5_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 FALSE;
		}
		_tmp20_ = res;
		_tmp21_ = sql_heavy_query_result_get_finished (_tmp20_);
		_tmp22_ = _tmp21_;
		if (_tmp22_) {
			result = FALSE;
			_g_object_unref0 (res);
			return result;
		} else {
			SQLHeavyQueryResult* _tmp23_;
			gint _tmp24_ = 0;
			gint _tmp25_;
			_tmp23_ = res;
			_tmp24_ = sql_heavy_record_fetch_int ((SQLHeavyRecord*) _tmp23_, 0, &_inner_error_);
			_tmp25_ = _tmp24_;
			if (_inner_error_ != NULL) {
				_g_object_unref0 (res);
				if (_inner_error_->domain == SQL_HEAVY_ERROR) {
					goto __catch5_sql_heavy_error;
				}
				_g_object_unref0 (res);
				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 FALSE;
			}
			(*iter).stamp = _tmp25_;
			(*iter).user_data = NULL;
			result = TRUE;
			_g_object_unref0 (res);
			return result;
		}
		_g_object_unref0 (res);
	}
	goto __finally5;
	__catch5_sql_heavy_error:
	{
		GError* e = NULL;
		GError* _tmp26_;
		const gchar* _tmp27_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp26_ = e;
		_tmp27_ = _tmp26_->message;
		g_critical ("sqlheavy-gtk-model.vala:133: Unable to determine next row id: %s", _tmp27_);
		result = FALSE;
		_g_error_free0 (e);
		return result;
	}
	__finally5:
	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 FALSE;
}


static gboolean sql_heavy_gtk_model_real_iter_nth_child (GtkTreeModel* base, GtkTreeIter* iter, GtkTreeIter* parent, gint n) {
	SQLHeavyGtkModel * self;
	GtkTreeIter _vala_iter = {0};
	gboolean result = FALSE;
	self = (SQLHeavyGtkModel*) base;
	result = FALSE;
	if (iter) {
		*iter = _vala_iter;
	}
	return result;
}


static gboolean sql_heavy_gtk_model_real_iter_parent (GtkTreeModel* base, GtkTreeIter* iter, GtkTreeIter* child) {
	SQLHeavyGtkModel * self;
	GtkTreeIter _vala_iter = {0};
	gboolean result = FALSE;
	self = (SQLHeavyGtkModel*) base;
	g_return_val_if_fail (child != NULL, FALSE);
	result = FALSE;
	if (iter) {
		*iter = _vala_iter;
	}
	return result;
}


static void sql_heavy_gtk_model_real_ref_node (SQLHeavyGtkModel* self, GtkTreeIter* iter) {
	GtkTreeIter _tmp0_;
	void* _tmp1_;
	g_return_if_fail (iter != NULL);
	_tmp0_ = *iter;
	_tmp1_ = _tmp0_.user_data;
	if (_tmp1_ != NULL) {
		GtkTreeIter _tmp2_;
		void* _tmp3_;
		_tmp2_ = *iter;
		_tmp3_ = _tmp2_.user_data;
		g_object_ref ((GObject*) SQL_HEAVY_ROW (_tmp3_));
	}
}


void sql_heavy_gtk_model_ref_node (SQLHeavyGtkModel* self, GtkTreeIter* iter) {
	g_return_if_fail (self != NULL);
	SQL_HEAVY_GTK_MODEL_GET_CLASS (self)->ref_node (self, iter);
}


static void sql_heavy_gtk_model_real_unref_node (SQLHeavyGtkModel* self, GtkTreeIter* iter) {
	GtkTreeIter _tmp0_;
	void* _tmp1_;
	g_return_if_fail (iter != NULL);
	_tmp0_ = *iter;
	_tmp1_ = _tmp0_.user_data;
	if (_tmp1_ != NULL) {
		GtkTreeIter _tmp2_;
		void* _tmp3_;
		_tmp2_ = *iter;
		_tmp3_ = _tmp2_.user_data;
		g_object_unref ((GObject*) SQL_HEAVY_ROW (_tmp3_));
	}
}


void sql_heavy_gtk_model_unref_node (SQLHeavyGtkModel* self, GtkTreeIter* iter) {
	g_return_if_fail (self != NULL);
	SQL_HEAVY_GTK_MODEL_GET_CLASS (self)->unref_node (self, iter);
}


/**
     * Create a new Model
     *
     * @param table the table this model is based on
     * @see table
     */
SQLHeavyGtkModel* sql_heavy_gtk_model_construct (GType object_type, SQLHeavyTable* table) {
	SQLHeavyGtkModel * self = NULL;
	SQLHeavyTable* _tmp0_;
	g_return_val_if_fail (table != NULL, NULL);
	_tmp0_ = table;
	self = (SQLHeavyGtkModel*) g_object_new (object_type, "table", _tmp0_, NULL);
	return self;
}


SQLHeavyGtkModel* sql_heavy_gtk_model_new (SQLHeavyTable* table) {
	return sql_heavy_gtk_model_construct (SQL_HEAVY_GTK_TYPE_MODEL, table);
}


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


static void sql_heavy_gtk_model_set_table (SQLHeavyGtkModel* self, SQLHeavyTable* value) {
	SQLHeavyTable* _tmp0_;
	SQLHeavyTable* _tmp1_;
	SQLHeavyTable* _tmp2_;
	SQLHeavyTable* _tmp3_;
	SQLHeavyQueryable* _tmp4_;
	SQLHeavyQueryable* _tmp5_;
	SQLHeavyQueryable* _tmp6_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->_table);
	self->priv->_table = _tmp1_;
	_tmp2_ = sql_heavy_gtk_model_get_table (self);
	_tmp3_ = _tmp2_;
	_tmp4_ = sql_heavy_table_get_queryable (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = _g_object_ref0 (_tmp5_);
	_g_object_unref0 (self->priv->queryable);
	self->priv->queryable = _tmp6_;
	g_object_notify ((GObject *) self, "table");
}


static void sql_heavy_gtk_model_class_init (SQLHeavyGtkModelClass * klass) {
	sql_heavy_gtk_model_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (SQLHeavyGtkModelPrivate));
	SQL_HEAVY_GTK_MODEL_CLASS (klass)->ref_node = sql_heavy_gtk_model_real_ref_node;
	SQL_HEAVY_GTK_MODEL_CLASS (klass)->unref_node = sql_heavy_gtk_model_real_unref_node;
	G_OBJECT_CLASS (klass)->get_property = _vala_sql_heavy_gtk_model_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_sql_heavy_gtk_model_set_property;
	G_OBJECT_CLASS (klass)->finalize = sql_heavy_gtk_model_finalize;
	/**
	     * The table that this model is based on
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), SQL_HEAVY_GTK_MODEL_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));
}


static void sql_heavy_gtk_model_gtk_tree_model_interface_init (GtkTreeModelIface * iface) {
	sql_heavy_gtk_model_gtk_tree_model_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_column_type = (GType (*)(GtkTreeModel*, gint)) sql_heavy_gtk_model_real_get_column_type;
	iface->get_flags = (GtkTreeModelFlags (*)(GtkTreeModel*)) sql_heavy_gtk_model_real_get_flags;
	iface->get_iter = (gboolean (*)(GtkTreeModel*, GtkTreeIter*, GtkTreePath*)) sql_heavy_gtk_model_real_get_iter;
	iface->get_n_columns = (gint (*)(GtkTreeModel*)) sql_heavy_gtk_model_real_get_n_columns;
	iface->get_path = (GtkTreePath* (*)(GtkTreeModel*, GtkTreeIter*)) sql_heavy_gtk_model_real_get_path;
	iface->get_value = (void (*)(GtkTreeModel*, GtkTreeIter*, gint, GValue*)) sql_heavy_gtk_model_real_get_value;
	iface->iter_children = (gboolean (*)(GtkTreeModel*, GtkTreeIter*, GtkTreeIter*)) sql_heavy_gtk_model_real_iter_children;
	iface->iter_has_child = (gboolean (*)(GtkTreeModel*, GtkTreeIter*)) sql_heavy_gtk_model_real_iter_has_child;
	iface->iter_n_children = (gint (*)(GtkTreeModel*, GtkTreeIter*)) sql_heavy_gtk_model_real_iter_n_children;
	iface->iter_next = (gboolean (*)(GtkTreeModel*, GtkTreeIter*)) sql_heavy_gtk_model_real_iter_next;
	iface->iter_nth_child = (gboolean (*)(GtkTreeModel*, GtkTreeIter*, GtkTreeIter*, gint)) sql_heavy_gtk_model_real_iter_nth_child;
	iface->iter_parent = (gboolean (*)(GtkTreeModel*, GtkTreeIter*, GtkTreeIter*)) sql_heavy_gtk_model_real_iter_parent;
	iface->ref_node = (void (*)(GtkTreeModel*, GtkTreeIter*)) sql_heavy_gtk_model_ref_node;
	iface->unref_node = (void (*)(GtkTreeModel*, GtkTreeIter*)) sql_heavy_gtk_model_unref_node;
}


static void sql_heavy_gtk_model_instance_init (SQLHeavyGtkModel * self) {
	self->priv = SQL_HEAVY_GTK_MODEL_GET_PRIVATE (self);
	self->priv->get_value_calls = 0;
	self->priv->next_calls = 0;
}


static void sql_heavy_gtk_model_finalize (GObject* obj) {
	SQLHeavyGtkModel * self;
	self = SQL_HEAVY_GTK_MODEL (obj);
	_g_object_unref0 (self->priv->_table);
	_g_object_unref0 (self->priv->queryable);
	G_OBJECT_CLASS (sql_heavy_gtk_model_parent_class)->finalize (obj);
}


/**
   * Gtk.TreeModel implementation
   */
GType sql_heavy_gtk_model_get_type (void) {
	static volatile gsize sql_heavy_gtk_model_type_id__volatile = 0;
	if (g_once_init_enter (&sql_heavy_gtk_model_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (SQLHeavyGtkModelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) sql_heavy_gtk_model_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SQLHeavyGtkModel), 0, (GInstanceInitFunc) sql_heavy_gtk_model_instance_init, NULL };
		static const GInterfaceInfo gtk_tree_model_info = { (GInterfaceInitFunc) sql_heavy_gtk_model_gtk_tree_model_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType sql_heavy_gtk_model_type_id;
		sql_heavy_gtk_model_type_id = g_type_register_static (G_TYPE_OBJECT, "SQLHeavyGtkModel", &g_define_type_info, 0);
		g_type_add_interface_static (sql_heavy_gtk_model_type_id, GTK_TYPE_TREE_MODEL, &gtk_tree_model_info);
		g_once_init_leave (&sql_heavy_gtk_model_type_id__volatile, sql_heavy_gtk_model_type_id);
	}
	return sql_heavy_gtk_model_type_id__volatile;
}


static void _vala_sql_heavy_gtk_model_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	SQLHeavyGtkModel * self;
	self = SQL_HEAVY_GTK_MODEL (object);
	switch (property_id) {
		case SQL_HEAVY_GTK_MODEL_TABLE:
		g_value_set_object (value, sql_heavy_gtk_model_get_table (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_sql_heavy_gtk_model_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	SQLHeavyGtkModel * self;
	self = SQL_HEAVY_GTK_MODEL (object);
	switch (property_id) {
		case SQL_HEAVY_GTK_MODEL_TABLE:
		sql_heavy_gtk_model_set_table (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



