/* query_builder.c generated by valac 0.56.19, the Vala compiler
 * generated from query_builder.vala, do not modify */

#include "qlite.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib-object.h>
#include <sqlite3.h>
#include <gobject/gvaluecollector.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define QLITE_QUERY_BUILDER_TYPE_ORDERING_TERM (qlite_query_builder_ordering_term_get_type ())
#define QLITE_QUERY_BUILDER_ORDERING_TERM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), QLITE_QUERY_BUILDER_TYPE_ORDERING_TERM, QliteQueryBuilderOrderingTerm))
#define QLITE_QUERY_BUILDER_ORDERING_TERM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), QLITE_QUERY_BUILDER_TYPE_ORDERING_TERM, QliteQueryBuilderOrderingTermClass))
#define QLITE_QUERY_BUILDER_IS_ORDERING_TERM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), QLITE_QUERY_BUILDER_TYPE_ORDERING_TERM))
#define QLITE_QUERY_BUILDER_IS_ORDERING_TERM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), QLITE_QUERY_BUILDER_TYPE_ORDERING_TERM))
#define QLITE_QUERY_BUILDER_ORDERING_TERM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), QLITE_QUERY_BUILDER_TYPE_ORDERING_TERM, QliteQueryBuilderOrderingTermClass))

typedef struct _QliteQueryBuilderOrderingTerm QliteQueryBuilderOrderingTerm;
typedef struct _QliteQueryBuilderOrderingTermClass QliteQueryBuilderOrderingTermClass;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _qlite_table_unref0(var) ((var == NULL) ? NULL : (var = (qlite_table_unref (var), NULL)))

#define QLITE_STATEMENT_BUILDER_TYPE_ABSTRACT_FIELD (qlite_statement_builder_abstract_field_get_type ())
#define QLITE_STATEMENT_BUILDER_ABSTRACT_FIELD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), QLITE_STATEMENT_BUILDER_TYPE_ABSTRACT_FIELD, QliteStatementBuilderAbstractField))
#define QLITE_STATEMENT_BUILDER_ABSTRACT_FIELD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), QLITE_STATEMENT_BUILDER_TYPE_ABSTRACT_FIELD, QliteStatementBuilderAbstractFieldClass))
#define QLITE_STATEMENT_BUILDER_IS_ABSTRACT_FIELD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), QLITE_STATEMENT_BUILDER_TYPE_ABSTRACT_FIELD))
#define QLITE_STATEMENT_BUILDER_IS_ABSTRACT_FIELD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), QLITE_STATEMENT_BUILDER_TYPE_ABSTRACT_FIELD))
#define QLITE_STATEMENT_BUILDER_ABSTRACT_FIELD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), QLITE_STATEMENT_BUILDER_TYPE_ABSTRACT_FIELD, QliteStatementBuilderAbstractFieldClass))

typedef struct _QliteStatementBuilderAbstractField QliteStatementBuilderAbstractField;
typedef struct _QliteStatementBuilderAbstractFieldClass QliteStatementBuilderAbstractFieldClass;

#define QLITE_STATEMENT_BUILDER_TYPE_STRING_FIELD (qlite_statement_builder_string_field_get_type ())
#define QLITE_STATEMENT_BUILDER_STRING_FIELD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), QLITE_STATEMENT_BUILDER_TYPE_STRING_FIELD, QliteStatementBuilderStringField))
#define QLITE_STATEMENT_BUILDER_STRING_FIELD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), QLITE_STATEMENT_BUILDER_TYPE_STRING_FIELD, QliteStatementBuilderStringFieldClass))
#define QLITE_STATEMENT_BUILDER_IS_STRING_FIELD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), QLITE_STATEMENT_BUILDER_TYPE_STRING_FIELD))
#define QLITE_STATEMENT_BUILDER_IS_STRING_FIELD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), QLITE_STATEMENT_BUILDER_TYPE_STRING_FIELD))
#define QLITE_STATEMENT_BUILDER_STRING_FIELD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), QLITE_STATEMENT_BUILDER_TYPE_STRING_FIELD, QliteStatementBuilderStringFieldClass))

typedef struct _QliteStatementBuilderStringField QliteStatementBuilderStringField;
typedef struct _QliteStatementBuilderStringFieldClass QliteStatementBuilderStringFieldClass;

#define QLITE_STATEMENT_BUILDER_TYPE_FIELD (qlite_statement_builder_field_get_type ())
#define QLITE_STATEMENT_BUILDER_FIELD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), QLITE_STATEMENT_BUILDER_TYPE_FIELD, QliteStatementBuilderField))
#define QLITE_STATEMENT_BUILDER_FIELD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), QLITE_STATEMENT_BUILDER_TYPE_FIELD, QliteStatementBuilderFieldClass))
#define QLITE_STATEMENT_BUILDER_IS_FIELD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), QLITE_STATEMENT_BUILDER_TYPE_FIELD))
#define QLITE_STATEMENT_BUILDER_IS_FIELD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), QLITE_STATEMENT_BUILDER_TYPE_FIELD))
#define QLITE_STATEMENT_BUILDER_FIELD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), QLITE_STATEMENT_BUILDER_TYPE_FIELD, QliteStatementBuilderFieldClass))

typedef struct _QliteStatementBuilderField QliteStatementBuilderField;
typedef struct _QliteStatementBuilderFieldClass QliteStatementBuilderFieldClass;
#define _qlite_column_unref0(var) ((var == NULL) ? NULL : (var = (qlite_column_unref (var), NULL)))
#define _qlite_row_option_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_option_unref (var), NULL)))
#define _qlite_row_iterator_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_iterator_unref (var), NULL)))
#define _qlite_row_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_unref (var), NULL)))
typedef struct _QliteQueryBuilderOrderingTermPrivate QliteQueryBuilderOrderingTermPrivate;
typedef struct _QliteQueryBuilderParamSpecOrderingTerm QliteQueryBuilderParamSpecOrderingTerm;
#define _qlite_statement_builder_unref0(var) ((var == NULL) ? NULL : (var = (qlite_statement_builder_unref (var), NULL)))

struct _QliteQueryBuilderPrivate {
	gboolean single_result;
	gchar* column_selector;
	QliteColumn** columns;
	gint columns_length1;
	gint _columns_size_;
	gchar* joins;
	QliteQueryBuilderOrderingTerm** order_by_terms;
	gint order_by_terms_length1;
	gint _order_by_terms_size_;
	gchar* group_by_term;
	gint limit_val;
	gint offset_val;
};

struct _QliteQueryBuilderOrderingTerm {
	GTypeInstance parent_instance;
	volatile int ref_count;
	QliteQueryBuilderOrderingTermPrivate * priv;
};

struct _QliteQueryBuilderOrderingTermClass {
	GTypeClass parent_class;
	void (*finalize) (QliteQueryBuilderOrderingTerm *self);
};

struct _QliteQueryBuilderOrderingTermPrivate {
	QliteColumn* column;
	gchar* column_name;
	gchar* dir;
};

struct _QliteQueryBuilderParamSpecOrderingTerm {
	GParamSpec parent_instance;
};

static gint QliteQueryBuilder_private_offset;
static gpointer qlite_query_builder_parent_class = NULL;
static gint QliteQueryBuilderOrderingTerm_private_offset;
static gpointer qlite_query_builder_ordering_term_parent_class = NULL;
static gpointer qlite_match_query_builder_parent_class = NULL;

static gpointer qlite_query_builder_ordering_term_ref (gpointer instance);
static void qlite_query_builder_ordering_term_unref (gpointer instance);
static GParamSpec* qlite_query_builder_param_spec_ordering_term (const gchar* name,
                                                          const gchar* nick,
                                                          const gchar* blurb,
                                                          GType object_type,
                                                          GParamFlags flags) G_GNUC_UNUSED ;
static void qlite_query_builder_value_set_ordering_term (GValue* value,
                                                  gpointer v_object) G_GNUC_UNUSED ;
static void qlite_query_builder_value_take_ordering_term (GValue* value,
                                                   gpointer v_object) G_GNUC_UNUSED ;
static gpointer qlite_query_builder_value_get_ordering_term (const GValue* value) G_GNUC_UNUSED ;
static GType qlite_query_builder_ordering_term_get_type (void) G_GNUC_CONST  G_GNUC_UNUSED ;
VALA_EXTERN sqlite3_stmt* qlite_statement_builder_prepare (QliteStatementBuilder* self);
VALA_EXTERN gpointer qlite_statement_builder_abstract_field_ref (gpointer instance);
VALA_EXTERN void qlite_statement_builder_abstract_field_unref (gpointer instance);
VALA_EXTERN GParamSpec* qlite_statement_builder_param_spec_abstract_field (const gchar* name,
                                                               const gchar* nick,
                                                               const gchar* blurb,
                                                               GType object_type,
                                                               GParamFlags flags);
VALA_EXTERN void qlite_statement_builder_value_set_abstract_field (GValue* value,
                                                       gpointer v_object);
VALA_EXTERN void qlite_statement_builder_value_take_abstract_field (GValue* value,
                                                        gpointer v_object);
VALA_EXTERN gpointer qlite_statement_builder_value_get_abstract_field (const GValue* value);
VALA_EXTERN GType qlite_statement_builder_abstract_field_get_type (void) G_GNUC_CONST ;
VALA_EXTERN QliteQueryBuilder* qlite_query_builder_new (QliteDatabase* db);
VALA_EXTERN QliteQueryBuilder* qlite_query_builder_construct (GType object_type,
                                                  QliteDatabase* db);
VALA_EXTERN QliteStatementBuilder* qlite_statement_builder_construct (GType object_type,
                                                          QliteDatabase* db);
static QliteColumn** _vala_array_dup2 (QliteColumn** self,
                                gssize length);
static QliteQueryBuilder* qlite_query_builder_real_from (QliteQueryBuilder* self,
                                                  QliteTable* table);
static QliteQueryBuilder* qlite_query_builder_real_from_name (QliteQueryBuilder* self,
                                                       const gchar* table);
VALA_EXTERN QliteQueryBuilder* qlite_query_builder_join_name (QliteQueryBuilder* self,
                                                  const gchar* table_name,
                                                  const gchar* on);
VALA_EXTERN QliteStatementBuilderStringField* qlite_statement_builder_string_field_new (const gchar* value);
VALA_EXTERN QliteStatementBuilderStringField* qlite_statement_builder_string_field_construct (GType object_type,
                                                                                  const gchar* value);
VALA_EXTERN GType qlite_statement_builder_string_field_get_type (void) G_GNUC_CONST ;
static void _vala_array_add5 (QliteStatementBuilderAbstractField** * array,
                       gint* length,
                       gint* size,
                       QliteStatementBuilderAbstractField* value);
VALA_EXTERN QliteStatementBuilderField* qlite_statement_builder_field_new (GType t_type,
                                                               GBoxedCopyFunc t_dup_func,
                                                               GDestroyNotify t_destroy_func,
                                                               QliteColumn* column,
                                                               gconstpointer value);
VALA_EXTERN QliteStatementBuilderField* qlite_statement_builder_field_construct (GType object_type,
                                                                     GType t_type,
                                                                     GBoxedCopyFunc t_dup_func,
                                                                     GDestroyNotify t_destroy_func,
                                                                     QliteColumn* column,
                                                                     gconstpointer value);
VALA_EXTERN GType qlite_statement_builder_field_get_type (void) G_GNUC_CONST ;
static void _vala_array_add6 (QliteStatementBuilderAbstractField** * array,
                       gint* length,
                       gint* size,
                       QliteStatementBuilderAbstractField* value);
static QliteQueryBuilderOrderingTerm* qlite_query_builder_ordering_term_new (QliteColumn* column,
                                                                      const gchar* dir);
static QliteQueryBuilderOrderingTerm* qlite_query_builder_ordering_term_construct (GType object_type,
                                                                            QliteColumn* column,
                                                                            const gchar* dir);
static void _vala_array_add7 (QliteQueryBuilderOrderingTerm** * array,
                       gint* length,
                       gint* size,
                       QliteQueryBuilderOrderingTerm* value);
static QliteQueryBuilderOrderingTerm* qlite_query_builder_ordering_term_new_by_name (const gchar* column_name,
                                                                              const gchar* dir);
static QliteQueryBuilderOrderingTerm* qlite_query_builder_ordering_term_construct_by_name (GType object_type,
                                                                                    const gchar* column_name,
                                                                                    const gchar* dir);
static void _vala_array_add8 (QliteQueryBuilderOrderingTerm** * array,
                       gint* length,
                       gint* size,
                       QliteQueryBuilderOrderingTerm* value);
VALA_EXTERN glong qlite_row_option_get_integer (QliteRowOption* self,
                                    const gchar* field,
                                    glong def);
static QliteRow* qlite_query_builder_row_ (QliteQueryBuilder* self);
static sqlite3_stmt* qlite_query_builder_real_prepare (QliteStatementBuilder* base);
VALA_EXTERN sqlite3_stmt* qlite_database_prepare (QliteDatabase* self,
                                      const gchar* sql);
static gchar* qlite_query_builder_ordering_term_all_to_string (QliteQueryBuilderOrderingTerm** terms,
                                                        gint terms_length1);
VALA_EXTERN void qlite_statement_builder_abstract_field_bind (QliteStatementBuilderAbstractField* self,
                                                  sqlite3_stmt* stmt,
                                                  gint index);
static gchar* qlite_query_builder_ordering_term_to_string (QliteQueryBuilderOrderingTerm* self);
static void qlite_query_builder_ordering_term_finalize (QliteQueryBuilderOrderingTerm * obj);
static GType qlite_query_builder_ordering_term_get_type_once (void);
static void qlite_query_builder_finalize (QliteStatementBuilder * obj);
static GType qlite_query_builder_get_type_once (void);
VALA_EXTERN QliteMatchQueryBuilder* qlite_match_query_builder_new (QliteDatabase* db,
                                                       QliteTable* table);
VALA_EXTERN QliteMatchQueryBuilder* qlite_match_query_builder_construct (GType object_type,
                                                             QliteDatabase* db,
                                                             QliteTable* table);
static gboolean _vala_qlite_column_array_contains (QliteColumn* * stack,
                                            gssize stack_length,
                                            const QliteColumn* needle);
static void _vala_array_add9 (QliteStatementBuilderAbstractField** * array,
                       gint* length,
                       gint* size,
                       QliteStatementBuilderAbstractField* value);
static GType qlite_match_query_builder_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);

static inline gpointer
qlite_query_builder_get_instance_private (QliteQueryBuilder* self)
{
	return G_STRUCT_MEMBER_P (self, QliteQueryBuilder_private_offset);
}

QliteQueryBuilder*
qlite_query_builder_construct (GType object_type,
                               QliteDatabase* db)
{
	QliteQueryBuilder* self = NULL;
	g_return_val_if_fail (db != NULL, NULL);
	self = (QliteQueryBuilder*) qlite_statement_builder_construct (object_type, db);
	return self;
}

QliteQueryBuilder*
qlite_query_builder_new (QliteDatabase* db)
{
	return qlite_query_builder_construct (QLITE_TYPE_QUERY_BUILDER, db);
}

static gpointer
_qlite_column_ref0 (gpointer self)
{
	return self ? qlite_column_ref (self) : NULL;
}

static QliteColumn**
_vala_array_dup2 (QliteColumn** self,
                  gssize length)
{
	if (length >= 0) {
		QliteColumn** result;
		gssize i;
		result = g_new0 (QliteColumn*, length + 1);
		for (i = 0; i < length; i++) {
			QliteColumn* _tmp0_;
			_tmp0_ = _qlite_column_ref0 (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

static gpointer
_qlite_statement_builder_ref0 (gpointer self)
{
	return self ? qlite_statement_builder_ref (self) : NULL;
}

QliteQueryBuilder*
qlite_query_builder_select (QliteQueryBuilder* self,
                            QliteColumn** columns,
                            gint columns_length1)
{
	QliteColumn** _tmp0_;
	gint _tmp0__length1;
	QliteQueryBuilder* _tmp14_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = (columns != NULL) ? _vala_array_dup2 (columns, columns_length1) : columns;
	_tmp0__length1 = columns_length1;
	self->priv->columns = (_vala_array_free (self->priv->columns, self->priv->columns_length1, (GDestroyNotify) qlite_column_unref), NULL);
	self->priv->columns = _tmp0_;
	self->priv->columns_length1 = _tmp0__length1;
	self->priv->_columns_size_ = self->priv->columns_length1;
	if (columns_length1 != 0) {
		{
			gint i = 0;
			i = 0;
			{
				gboolean _tmp1_ = FALSE;
				_tmp1_ = TRUE;
				while (TRUE) {
					const gchar* _tmp3_;
					if (!_tmp1_) {
						gint _tmp2_;
						_tmp2_ = i;
						i = _tmp2_ + 1;
					}
					_tmp1_ = FALSE;
					if (!(i < columns_length1)) {
						break;
					}
					_tmp3_ = self->priv->column_selector;
					if (g_strcmp0 (_tmp3_, "*") == 0) {
						QliteColumn* _tmp4_;
						gchar* _tmp5_;
						_tmp4_ = columns[i];
						_tmp5_ = qlite_column_to_string (_tmp4_);
						_g_free0 (self->priv->column_selector);
						self->priv->column_selector = _tmp5_;
					} else {
						const gchar* _tmp6_;
						QliteColumn* _tmp7_;
						gchar* _tmp8_;
						gchar* _tmp9_;
						gchar* _tmp10_;
						gchar* _tmp11_;
						gchar* _tmp12_;
						_tmp6_ = self->priv->column_selector;
						_tmp7_ = columns[i];
						_tmp8_ = qlite_column_to_string (_tmp7_);
						_tmp9_ = _tmp8_;
						_tmp10_ = g_strconcat (", ", _tmp9_, NULL);
						_tmp11_ = _tmp10_;
						_tmp12_ = g_strconcat (_tmp6_, _tmp11_, NULL);
						_g_free0 (self->priv->column_selector);
						self->priv->column_selector = _tmp12_;
						_g_free0 (_tmp11_);
						_g_free0 (_tmp9_);
					}
				}
			}
		}
	} else {
		gchar* _tmp13_;
		_tmp13_ = g_strdup ("*");
		_g_free0 (self->priv->column_selector);
		self->priv->column_selector = _tmp13_;
	}
	_tmp14_ = _qlite_statement_builder_ref0 (self);
	result = _tmp14_;
	return result;
}

QliteQueryBuilder*
qlite_query_builder_select_string (QliteQueryBuilder* self,
                                   const gchar* column_selector)
{
	QliteColumn** _tmp0_;
	gchar* _tmp1_;
	QliteQueryBuilder* _tmp2_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (column_selector != NULL, NULL);
	_tmp0_ = g_new0 (QliteColumn*, 0 + 1);
	self->priv->columns = (_vala_array_free (self->priv->columns, self->priv->columns_length1, (GDestroyNotify) qlite_column_unref), NULL);
	self->priv->columns = _tmp0_;
	self->priv->columns_length1 = 0;
	self->priv->_columns_size_ = self->priv->columns_length1;
	_tmp1_ = g_strdup (column_selector);
	_g_free0 (self->priv->column_selector);
	self->priv->column_selector = _tmp1_;
	_tmp2_ = _qlite_statement_builder_ref0 (self);
	result = _tmp2_;
	return result;
}

static gpointer
_qlite_table_ref0 (gpointer self)
{
	return self ? qlite_table_ref (self) : NULL;
}

static QliteQueryBuilder*
qlite_query_builder_real_from (QliteQueryBuilder* self,
                               QliteTable* table)
{
	const gchar* _tmp0_;
	QliteTable* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	QliteQueryBuilder* _tmp5_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (table != NULL, NULL);
	_tmp0_ = self->table_name;
	if (_tmp0_ != NULL) {
		g_error ("query_builder.vala:60: cannot use from() multiple times.");
	}
	_tmp1_ = _qlite_table_ref0 (table);
	_qlite_table_unref0 (self->table);
	self->table = _tmp1_;
	_tmp2_ = qlite_table_get_name (table);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strdup (_tmp3_);
	_g_free0 (self->table_name);
	self->table_name = _tmp4_;
	_tmp5_ = _qlite_statement_builder_ref0 (self);
	result = _tmp5_;
	return result;
}

QliteQueryBuilder*
qlite_query_builder_from (QliteQueryBuilder* self,
                          QliteTable* table)
{
	QliteQueryBuilderClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = QLITE_QUERY_BUILDER_GET_CLASS (self);
	if (_klass_->from) {
		return _klass_->from (self, table);
	}
	return NULL;
}

static QliteQueryBuilder*
qlite_query_builder_real_from_name (QliteQueryBuilder* self,
                                    const gchar* table)
{
	gchar* _tmp0_;
	QliteQueryBuilder* _tmp1_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (table != NULL, NULL);
	_tmp0_ = g_strdup (table);
	_g_free0 (self->table_name);
	self->table_name = _tmp0_;
	_tmp1_ = _qlite_statement_builder_ref0 (self);
	result = _tmp1_;
	return result;
}

QliteQueryBuilder*
qlite_query_builder_from_name (QliteQueryBuilder* self,
                               const gchar* table)
{
	QliteQueryBuilderClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = QLITE_QUERY_BUILDER_GET_CLASS (self);
	if (_klass_->from_name) {
		return _klass_->from_name (self, table);
	}
	return NULL;
}

QliteQueryBuilder*
qlite_query_builder_outer_join_with (QliteQueryBuilder* self,
                                     GType t_type,
                                     GBoxedCopyFunc t_dup_func,
                                     GDestroyNotify t_destroy_func,
                                     QliteTable* table,
                                     QliteColumn* lhs,
                                     QliteColumn* rhs,
                                     const gchar* as)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	QliteQueryBuilder* _tmp7_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (table != NULL, NULL);
	g_return_val_if_fail (lhs != NULL, NULL);
	g_return_val_if_fail (rhs != NULL, NULL);
	_tmp0_ = qlite_column_to_string (lhs);
	_tmp1_ = _tmp0_;
	_tmp2_ = qlite_column_to_string (rhs);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat (_tmp1_, " = ", _tmp3_, NULL);
	_tmp5_ = _tmp4_;
	_tmp6_ = qlite_query_builder_outer_join_on (self, table, _tmp5_, as);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	result = _tmp7_;
	return result;
}

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

QliteQueryBuilder*
qlite_query_builder_outer_join_on (QliteQueryBuilder* self,
                                   QliteTable* table,
                                   const gchar* on,
                                   const gchar* as)
{
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	QliteQueryBuilder* _tmp11_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (table != NULL, NULL);
	g_return_val_if_fail (on != NULL, NULL);
	if (as == NULL) {
		const gchar* _tmp0_;
		const gchar* _tmp1_;
		_tmp0_ = qlite_table_get_name (table);
		_tmp1_ = _tmp0_;
		as = _tmp1_;
	}
	_tmp2_ = self->priv->joins;
	_tmp3_ = qlite_table_get_name (table);
	_tmp4_ = _tmp3_;
	_tmp5_ = string_to_string (_tmp4_);
	_tmp6_ = string_to_string (as);
	_tmp7_ = string_to_string (on);
	_tmp8_ = g_strconcat (" LEFT OUTER JOIN ", _tmp5_, " AS ", _tmp6_, " ON ", _tmp7_, NULL);
	_tmp9_ = _tmp8_;
	_tmp10_ = g_strconcat (_tmp2_, _tmp9_, NULL);
	_g_free0 (self->priv->joins);
	self->priv->joins = _tmp10_;
	_g_free0 (_tmp9_);
	_tmp11_ = _qlite_statement_builder_ref0 (self);
	result = _tmp11_;
	return result;
}

QliteQueryBuilder*
qlite_query_builder_join_with (QliteQueryBuilder* self,
                               GType t_type,
                               GBoxedCopyFunc t_dup_func,
                               GDestroyNotify t_destroy_func,
                               QliteTable* table,
                               QliteColumn* lhs,
                               QliteColumn* rhs,
                               const gchar* as)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	QliteQueryBuilder* _tmp7_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (table != NULL, NULL);
	g_return_val_if_fail (lhs != NULL, NULL);
	g_return_val_if_fail (rhs != NULL, NULL);
	_tmp0_ = qlite_column_to_string (lhs);
	_tmp1_ = _tmp0_;
	_tmp2_ = qlite_column_to_string (rhs);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat (_tmp1_, " = ", _tmp3_, NULL);
	_tmp5_ = _tmp4_;
	_tmp6_ = qlite_query_builder_join_on (self, table, _tmp5_, as);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	_g_free0 (_tmp3_);
	_g_free0 (_tmp1_);
	result = _tmp7_;
	return result;
}

QliteQueryBuilder*
qlite_query_builder_join_on (QliteQueryBuilder* self,
                             QliteTable* table,
                             const gchar* on,
                             const gchar* as)
{
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	QliteQueryBuilder* _tmp11_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (table != NULL, NULL);
	g_return_val_if_fail (on != NULL, NULL);
	if (as == NULL) {
		const gchar* _tmp0_;
		const gchar* _tmp1_;
		_tmp0_ = qlite_table_get_name (table);
		_tmp1_ = _tmp0_;
		as = _tmp1_;
	}
	_tmp2_ = self->priv->joins;
	_tmp3_ = qlite_table_get_name (table);
	_tmp4_ = _tmp3_;
	_tmp5_ = string_to_string (_tmp4_);
	_tmp6_ = string_to_string (as);
	_tmp7_ = string_to_string (on);
	_tmp8_ = g_strconcat (" JOIN ", _tmp5_, " AS ", _tmp6_, " ON ", _tmp7_, NULL);
	_tmp9_ = _tmp8_;
	_tmp10_ = g_strconcat (_tmp2_, _tmp9_, NULL);
	_g_free0 (self->priv->joins);
	self->priv->joins = _tmp10_;
	_g_free0 (_tmp9_);
	_tmp11_ = _qlite_statement_builder_ref0 (self);
	result = _tmp11_;
	return result;
}

QliteQueryBuilder*
qlite_query_builder_join_name (QliteQueryBuilder* self,
                               const gchar* table_name,
                               const gchar* on)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (table_name != NULL, NULL);
	g_return_val_if_fail (on != NULL, NULL);
	_tmp0_ = self->priv->joins;
	_tmp1_ = string_to_string (table_name);
	_tmp2_ = string_to_string (on);
	_tmp3_ = g_strconcat (" JOIN ", _tmp1_, " ON ", _tmp2_, NULL);
	_tmp4_ = _tmp3_;
	_tmp5_ = g_strconcat (_tmp0_, _tmp4_, NULL);
	_g_free0 (self->priv->joins);
	self->priv->joins = _tmp5_;
	_g_free0 (_tmp4_);
	_tmp6_ = _qlite_statement_builder_ref0 (self);
	result = _tmp6_;
	return result;
}

static void
_vala_array_add5 (QliteStatementBuilderAbstractField** * array,
                  gint* length,
                  gint* size,
                  QliteStatementBuilderAbstractField* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (QliteStatementBuilderAbstractField*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

QliteQueryBuilder*
qlite_query_builder_where (QliteQueryBuilder* self,
                           const gchar* selection,
                           gchar** selection_args,
                           gint selection_args_length1)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	QliteQueryBuilder* _tmp7_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (selection != NULL, NULL);
	_tmp0_ = self->selection;
	_tmp1_ = string_to_string (_tmp0_);
	_tmp2_ = string_to_string (selection);
	_tmp3_ = g_strconcat ("(", _tmp1_, ") AND (", _tmp2_, ")", NULL);
	_g_free0 (self->selection);
	self->selection = _tmp3_;
	{
		gchar** arg_collection = NULL;
		gint arg_collection_length1 = 0;
		gint _arg_collection_size_ = 0;
		gint arg_it = 0;
		arg_collection = selection_args;
		arg_collection_length1 = selection_args_length1;
		for (arg_it = 0; arg_it < arg_collection_length1; arg_it = arg_it + 1) {
			gchar* _tmp4_;
			gchar* arg = NULL;
			_tmp4_ = g_strdup (arg_collection[arg_it]);
			arg = _tmp4_;
			{
				const gchar* _tmp5_;
				QliteStatementBuilderStringField* _tmp6_;
				_tmp5_ = arg;
				_tmp6_ = qlite_statement_builder_string_field_new (_tmp5_);
				_vala_array_add5 (&self->selection_args, &self->selection_args_length1, &self->_selection_args_size_, (QliteStatementBuilderAbstractField*) _tmp6_);
				_g_free0 (arg);
			}
		}
	}
	_tmp7_ = _qlite_statement_builder_ref0 (self);
	result = _tmp7_;
	return result;
}

static void
_vala_array_add6 (QliteStatementBuilderAbstractField** * array,
                  gint* length,
                  gint* size,
                  QliteStatementBuilderAbstractField* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (QliteStatementBuilderAbstractField*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

QliteQueryBuilder*
qlite_query_builder_with (QliteQueryBuilder* self,
                          GType t_type,
                          GBoxedCopyFunc t_dup_func,
                          GDestroyNotify t_destroy_func,
                          QliteColumn* column,
                          const gchar* comp,
                          gconstpointer value)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_;
	gboolean _tmp3_;
	QliteStatementBuilderField* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	QliteQueryBuilder* _tmp13_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (column != NULL, NULL);
	g_return_val_if_fail (comp != NULL, NULL);
	_tmp2_ = qlite_column_get_unique (column);
	_tmp3_ = _tmp2_;
	if (_tmp3_) {
		_tmp1_ = TRUE;
	} else {
		gboolean _tmp4_;
		gboolean _tmp5_;
		_tmp4_ = qlite_column_get_primary_key (column);
		_tmp5_ = _tmp4_;
		_tmp1_ = _tmp5_;
	}
	if (_tmp1_) {
		_tmp0_ = g_strcmp0 (comp, "=") == 0;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		self->priv->single_result = TRUE;
	}
	_tmp6_ = qlite_statement_builder_field_new (t_type, (GBoxedCopyFunc) t_dup_func, (GDestroyNotify) t_destroy_func, column, value);
	_vala_array_add6 (&self->selection_args, &self->selection_args_length1, &self->_selection_args_size_, (QliteStatementBuilderAbstractField*) _tmp6_);
	_tmp7_ = self->selection;
	_tmp8_ = string_to_string (_tmp7_);
	_tmp9_ = qlite_column_to_string (column);
	_tmp10_ = _tmp9_;
	_tmp11_ = string_to_string (comp);
	_tmp12_ = g_strconcat ("(", _tmp8_, ") AND ", _tmp10_, " ", _tmp11_, " ?", NULL);
	_g_free0 (self->selection);
	self->selection = _tmp12_;
	_g_free0 (_tmp10_);
	_tmp13_ = _qlite_statement_builder_ref0 (self);
	result = _tmp13_;
	return result;
}

QliteQueryBuilder*
qlite_query_builder_with_null (QliteQueryBuilder* self,
                               GType t_type,
                               GBoxedCopyFunc t_dup_func,
                               GDestroyNotify t_destroy_func,
                               QliteColumn* column)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	QliteQueryBuilder* _tmp5_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (column != NULL, NULL);
	_tmp0_ = self->selection;
	_tmp1_ = string_to_string (_tmp0_);
	_tmp2_ = qlite_column_to_string (column);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat ("(", _tmp1_, ") AND ", _tmp3_, " ISNULL", NULL);
	_g_free0 (self->selection);
	self->selection = _tmp4_;
	_g_free0 (_tmp3_);
	_tmp5_ = _qlite_statement_builder_ref0 (self);
	result = _tmp5_;
	return result;
}

QliteQueryBuilder*
qlite_query_builder_without_null (QliteQueryBuilder* self,
                                  GType t_type,
                                  GBoxedCopyFunc t_dup_func,
                                  GDestroyNotify t_destroy_func,
                                  QliteColumn* column)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	QliteQueryBuilder* _tmp5_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (column != NULL, NULL);
	_tmp0_ = self->selection;
	_tmp1_ = string_to_string (_tmp0_);
	_tmp2_ = qlite_column_to_string (column);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat ("(", _tmp1_, ") AND ", _tmp3_, " NOT NULL", NULL);
	_g_free0 (self->selection);
	self->selection = _tmp4_;
	_g_free0 (_tmp3_);
	_tmp5_ = _qlite_statement_builder_ref0 (self);
	result = _tmp5_;
	return result;
}

static void
_vala_array_add7 (QliteQueryBuilderOrderingTerm** * array,
                  gint* length,
                  gint* size,
                  QliteQueryBuilderOrderingTerm* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (QliteQueryBuilderOrderingTerm*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

QliteQueryBuilder*
qlite_query_builder_order_by (QliteQueryBuilder* self,
                              QliteColumn* column,
                              const gchar* dir)
{
	QliteQueryBuilderOrderingTerm* _tmp0_;
	QliteQueryBuilder* _tmp1_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (column != NULL, NULL);
	g_return_val_if_fail (dir != NULL, NULL);
	_tmp0_ = qlite_query_builder_ordering_term_new (column, dir);
	_vala_array_add7 (&self->priv->order_by_terms, &self->priv->order_by_terms_length1, &self->priv->_order_by_terms_size_, _tmp0_);
	_tmp1_ = _qlite_statement_builder_ref0 (self);
	result = _tmp1_;
	return result;
}

static void
_vala_array_add8 (QliteQueryBuilderOrderingTerm** * array,
                  gint* length,
                  gint* size,
                  QliteQueryBuilderOrderingTerm* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (QliteQueryBuilderOrderingTerm*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

QliteQueryBuilder*
qlite_query_builder_order_by_name (QliteQueryBuilder* self,
                                   const gchar* name,
                                   const gchar* dir)
{
	QliteQueryBuilderOrderingTerm* _tmp0_;
	QliteQueryBuilder* _tmp1_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	g_return_val_if_fail (dir != NULL, NULL);
	_tmp0_ = qlite_query_builder_ordering_term_new_by_name (name, dir);
	_vala_array_add8 (&self->priv->order_by_terms, &self->priv->order_by_terms_length1, &self->priv->_order_by_terms_size_, _tmp0_);
	_tmp1_ = _qlite_statement_builder_ref0 (self);
	result = _tmp1_;
	return result;
}

QliteQueryBuilder*
qlite_query_builder_group_by (QliteQueryBuilder* self,
                              QliteColumn** columns,
                              gint columns_length1)
{
	QliteQueryBuilder* _tmp11_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	{
		QliteColumn** col_collection = NULL;
		gint col_collection_length1 = 0;
		gint _col_collection_size_ = 0;
		gint col_it = 0;
		col_collection = columns;
		col_collection_length1 = columns_length1;
		for (col_it = 0; col_it < col_collection_length1; col_it = col_it + 1) {
			QliteColumn* _tmp0_;
			QliteColumn* col = NULL;
			_tmp0_ = _qlite_column_ref0 (col_collection[col_it]);
			col = _tmp0_;
			{
				const gchar* _tmp1_;
				_tmp1_ = self->priv->group_by_term;
				if (_tmp1_ == NULL) {
					QliteColumn* _tmp2_;
					gchar* _tmp3_;
					_tmp2_ = col;
					_tmp3_ = qlite_column_to_string (_tmp2_);
					_g_free0 (self->priv->group_by_term);
					self->priv->group_by_term = _tmp3_;
				} else {
					const gchar* _tmp4_;
					QliteColumn* _tmp5_;
					gchar* _tmp6_;
					gchar* _tmp7_;
					gchar* _tmp8_;
					gchar* _tmp9_;
					gchar* _tmp10_;
					_tmp4_ = self->priv->group_by_term;
					_tmp5_ = col;
					_tmp6_ = qlite_column_to_string (_tmp5_);
					_tmp7_ = _tmp6_;
					_tmp8_ = g_strconcat (", ", _tmp7_, NULL);
					_tmp9_ = _tmp8_;
					_tmp10_ = g_strconcat (_tmp4_, _tmp9_, NULL);
					_g_free0 (self->priv->group_by_term);
					self->priv->group_by_term = _tmp10_;
					_g_free0 (_tmp9_);
					_g_free0 (_tmp7_);
				}
				_qlite_column_unref0 (col);
			}
		}
	}
	_tmp11_ = _qlite_statement_builder_ref0 (self);
	result = _tmp11_;
	return result;
}

QliteQueryBuilder*
qlite_query_builder_limit (QliteQueryBuilder* self,
                           gint limit)
{
	gboolean _tmp0_ = FALSE;
	QliteQueryBuilder* _tmp1_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (self->priv->limit_val != 0) {
		_tmp0_ = limit > self->priv->limit_val;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		g_error ("query_builder.vala:143: tried to increase an existing limit");
	}
	self->priv->limit_val = limit;
	_tmp1_ = _qlite_statement_builder_ref0 (self);
	result = _tmp1_;
	return result;
}

QliteQueryBuilder*
qlite_query_builder_offset (QliteQueryBuilder* self,
                            gint offset)
{
	QliteQueryBuilder* _tmp0_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (self->priv->limit_val == 0) {
		g_error ("query_builder.vala:149: limit required before offset");
	}
	self->priv->offset_val = offset;
	_tmp0_ = _qlite_statement_builder_ref0 (self);
	result = _tmp0_;
	return result;
}

QliteQueryBuilder*
qlite_query_builder_single (QliteQueryBuilder* self)
{
	QliteQueryBuilder* _tmp0_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	self->priv->single_result = TRUE;
	_tmp0_ = qlite_query_builder_limit (self, 1);
	result = _tmp0_;
	return result;
}

gint64
qlite_query_builder_count (QliteQueryBuilder* self)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	QliteRowOption* _tmp3_;
	QliteRowOption* _tmp4_;
	gint64 _tmp5_;
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	_tmp0_ = self->priv->column_selector;
	_tmp1_ = string_to_string (_tmp0_);
	_tmp2_ = g_strconcat ("COUNT(", _tmp1_, ") AS count", NULL);
	_g_free0 (self->priv->column_selector);
	self->priv->column_selector = _tmp2_;
	self->priv->single_result = TRUE;
	_tmp3_ = qlite_query_builder_row (self);
	_tmp4_ = _tmp3_;
	_tmp5_ = (gint64) qlite_row_option_get_integer (_tmp4_, "count", (glong) 0);
	_qlite_row_option_unref0 (_tmp4_);
	result = _tmp5_;
	return result;
}

static QliteRow*
qlite_query_builder_row_ (QliteQueryBuilder* self)
{
	QliteRowIterator* _tmp0_;
	QliteRowIterator* _tmp1_;
	QliteRow* _tmp2_;
	QliteRow* _tmp3_;
	QliteRow* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (!self->priv->single_result) {
		g_error ("query_builder.vala:166: query is not suited to return a single row, bu" \
"t row() was called.");
	}
	_tmp0_ = qlite_query_builder_iterator (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = qlite_row_iterator_get_next (_tmp1_);
	_tmp3_ = _tmp2_;
	_qlite_row_iterator_unref0 (_tmp1_);
	result = _tmp3_;
	return result;
}

QliteRowOption*
qlite_query_builder_row (QliteQueryBuilder* self)
{
	QliteRow* _tmp0_;
	QliteRow* _tmp1_;
	QliteRowOption* _tmp2_;
	QliteRowOption* _tmp3_;
	QliteRowOption* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = qlite_query_builder_row_ (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = qlite_row_option_new (_tmp1_);
	_tmp3_ = _tmp2_;
	_qlite_row_unref0 (_tmp1_);
	result = _tmp3_;
	return result;
}

gpointer
qlite_query_builder_get (QliteQueryBuilder* self,
                         GType t_type,
                         GBoxedCopyFunc t_dup_func,
                         GDestroyNotify t_destroy_func,
                         QliteColumn* field,
                         gconstpointer def)
{
	QliteRowOption* _tmp0_;
	QliteRowOption* _tmp1_;
	gpointer _tmp2_;
	gpointer _tmp3_;
	gpointer result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (field != NULL, NULL);
	_tmp0_ = qlite_query_builder_row (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = qlite_row_option_get (_tmp1_, t_type, (GBoxedCopyFunc) t_dup_func, (GDestroyNotify) t_destroy_func, field, def);
	_tmp3_ = _tmp2_;
	_qlite_row_option_unref0 (_tmp1_);
	result = _tmp3_;
	return result;
}

static sqlite3_stmt*
qlite_query_builder_real_prepare (QliteStatementBuilder* base)
{
	QliteQueryBuilder * self;
	gchar* _tmp0_ = NULL;
	const gchar* _tmp1_;
	gchar* _tmp6_ = NULL;
	const gchar* _tmp7_;
	gchar* _tmp12_ = NULL;
	sqlite3_stmt* stmt = NULL;
	QliteDatabase* _tmp19_;
	const gchar* _tmp20_;
	const gchar* _tmp21_;
	const gchar* _tmp22_;
	const gchar* _tmp23_;
	const gchar* _tmp24_;
	const gchar* _tmp25_;
	const gchar* _tmp26_;
	const gchar* _tmp27_;
	QliteQueryBuilderOrderingTerm** _tmp28_;
	gint _tmp28__length1;
	gchar* _tmp29_;
	gchar* _tmp30_;
	const gchar* _tmp31_;
	const gchar* _tmp32_;
	gchar* _tmp33_;
	gchar* _tmp34_;
	sqlite3_stmt* _tmp35_;
	sqlite3_stmt* _tmp36_;
	sqlite3_stmt* result;
	self = (QliteQueryBuilder*) base;
	_tmp1_ = self->table_name;
	if (_tmp1_ == NULL) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup ("");
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp2_;
	} else {
		const gchar* _tmp3_;
		const gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp3_ = self->table_name;
		_tmp4_ = string_to_string ((const gchar*) _tmp3_);
		_tmp5_ = g_strconcat ("FROM ", _tmp4_, NULL);
		_g_free0 (_tmp0_);
		_tmp0_ = _tmp5_;
	}
	_tmp7_ = self->priv->group_by_term;
	if (_tmp7_ == NULL) {
		gchar* _tmp8_;
		_tmp8_ = g_strdup ("");
		_g_free0 (_tmp6_);
		_tmp6_ = _tmp8_;
	} else {
		const gchar* _tmp9_;
		const gchar* _tmp10_;
		gchar* _tmp11_;
		_tmp9_ = self->priv->group_by_term;
		_tmp10_ = string_to_string (_tmp9_);
		_tmp11_ = g_strconcat ("GROUP BY ", _tmp10_, NULL);
		_g_free0 (_tmp6_);
		_tmp6_ = _tmp11_;
	}
	if (self->priv->limit_val > 0) {
		gchar* _tmp13_;
		gchar* _tmp14_;
		gchar* _tmp15_;
		gchar* _tmp16_;
		gchar* _tmp17_;
		_tmp13_ = g_strdup_printf ("%i", self->priv->limit_val);
		_tmp14_ = _tmp13_;
		_tmp15_ = g_strdup_printf ("%i", self->priv->offset_val);
		_tmp16_ = _tmp15_;
		_tmp17_ = g_strconcat (" LIMIT ", _tmp14_, " OFFSET ", _tmp16_, NULL);
		_g_free0 (_tmp12_);
		_tmp12_ = _tmp17_;
		_g_free0 (_tmp16_);
		_g_free0 (_tmp14_);
	} else {
		gchar* _tmp18_;
		_tmp18_ = g_strdup ("");
		_g_free0 (_tmp12_);
		_tmp12_ = _tmp18_;
	}
	_tmp19_ = ((QliteStatementBuilder*) self)->db;
	_tmp20_ = self->priv->column_selector;
	_tmp21_ = string_to_string (_tmp20_);
	_tmp22_ = string_to_string (_tmp0_);
	_tmp23_ = self->priv->joins;
	_tmp24_ = string_to_string (_tmp23_);
	_tmp25_ = self->selection;
	_tmp26_ = string_to_string (_tmp25_);
	_tmp27_ = string_to_string (_tmp6_);
	_tmp28_ = self->priv->order_by_terms;
	_tmp28__length1 = self->priv->order_by_terms_length1;
	_tmp29_ = qlite_query_builder_ordering_term_all_to_string (_tmp28_, (gint) _tmp28__length1);
	_tmp30_ = _tmp29_;
	_tmp31_ = string_to_string (_tmp30_);
	_tmp32_ = string_to_string (_tmp12_);
	_tmp33_ = g_strconcat ("SELECT ", _tmp21_, " ", _tmp22_, " ", _tmp24_, " WHERE ", _tmp26_, " ", _tmp27_, " ", _tmp31_, " ", _tmp32_, NULL);
	_tmp34_ = _tmp33_;
	_tmp35_ = qlite_database_prepare (_tmp19_, _tmp34_);
	_tmp36_ = _tmp35_;
	_g_free0 (_tmp34_);
	_g_free0 (_tmp30_);
	stmt = _tmp36_;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp37_ = FALSE;
			_tmp37_ = TRUE;
			while (TRUE) {
				QliteStatementBuilderAbstractField** _tmp39_;
				gint _tmp39__length1;
				QliteStatementBuilderAbstractField** _tmp40_;
				gint _tmp40__length1;
				QliteStatementBuilderAbstractField* _tmp41_;
				sqlite3_stmt* _tmp42_;
				if (!_tmp37_) {
					gint _tmp38_;
					_tmp38_ = i;
					i = _tmp38_ + 1;
				}
				_tmp37_ = FALSE;
				_tmp39_ = self->selection_args;
				_tmp39__length1 = self->selection_args_length1;
				if (!(i < _tmp39__length1)) {
					break;
				}
				_tmp40_ = self->selection_args;
				_tmp40__length1 = self->selection_args_length1;
				_tmp41_ = _tmp40_[i];
				_tmp42_ = stmt;
				qlite_statement_builder_abstract_field_bind (_tmp41_, _tmp42_, i + 1);
			}
		}
	}
	result = stmt;
	_g_free0 (_tmp12_);
	_g_free0 (_tmp6_);
	_g_free0 (_tmp0_);
	return result;
}

QliteRowIterator*
qlite_query_builder_iterator (QliteQueryBuilder* self)
{
	QliteDatabase* _tmp0_;
	QliteRowIterator* _tmp1_;
	QliteRowIterator* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = ((QliteStatementBuilder*) self)->db;
	_tmp1_ = qlite_row_iterator_new_from_query_builder (_tmp0_, self);
	result = _tmp1_;
	return result;
}

static inline gpointer
qlite_query_builder_ordering_term_get_instance_private (QliteQueryBuilderOrderingTerm* self)
{
	return G_STRUCT_MEMBER_P (self, QliteQueryBuilderOrderingTerm_private_offset);
}

static QliteQueryBuilderOrderingTerm*
qlite_query_builder_ordering_term_construct (GType object_type,
                                             QliteColumn* column,
                                             const gchar* dir)
{
	QliteQueryBuilderOrderingTerm* self = NULL;
	QliteColumn* _tmp0_;
	gchar* _tmp1_;
	gchar* _tmp2_;
	g_return_val_if_fail (column != NULL, NULL);
	g_return_val_if_fail (dir != NULL, NULL);
	self = (QliteQueryBuilderOrderingTerm*) g_type_create_instance (object_type);
	_tmp0_ = _qlite_column_ref0 (column);
	_qlite_column_unref0 (self->priv->column);
	self->priv->column = _tmp0_;
	_tmp1_ = qlite_column_to_string (column);
	_g_free0 (self->priv->column_name);
	self->priv->column_name = _tmp1_;
	_tmp2_ = g_strdup (dir);
	_g_free0 (self->priv->dir);
	self->priv->dir = _tmp2_;
	return self;
}

static QliteQueryBuilderOrderingTerm*
qlite_query_builder_ordering_term_new (QliteColumn* column,
                                       const gchar* dir)
{
	return qlite_query_builder_ordering_term_construct (QLITE_QUERY_BUILDER_TYPE_ORDERING_TERM, column, dir);
}

static QliteQueryBuilderOrderingTerm*
qlite_query_builder_ordering_term_construct_by_name (GType object_type,
                                                     const gchar* column_name,
                                                     const gchar* dir)
{
	QliteQueryBuilderOrderingTerm* self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_val_if_fail (column_name != NULL, NULL);
	g_return_val_if_fail (dir != NULL, NULL);
	self = (QliteQueryBuilderOrderingTerm*) g_type_create_instance (object_type);
	_tmp0_ = g_strdup (column_name);
	_g_free0 (self->priv->column_name);
	self->priv->column_name = _tmp0_;
	_tmp1_ = g_strdup (dir);
	_g_free0 (self->priv->dir);
	self->priv->dir = _tmp1_;
	return self;
}

static QliteQueryBuilderOrderingTerm*
qlite_query_builder_ordering_term_new_by_name (const gchar* column_name,
                                               const gchar* dir)
{
	return qlite_query_builder_ordering_term_construct_by_name (QLITE_QUERY_BUILDER_TYPE_ORDERING_TERM, column_name, dir);
}

static gchar*
qlite_query_builder_ordering_term_to_string (QliteQueryBuilderOrderingTerm* self)
{
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->column_name;
	_tmp1_ = string_to_string (_tmp0_);
	_tmp2_ = self->priv->dir;
	_tmp3_ = string_to_string (_tmp2_);
	_tmp4_ = g_strconcat (_tmp1_, " ", _tmp3_, NULL);
	result = _tmp4_;
	return result;
}

static gchar*
qlite_query_builder_ordering_term_all_to_string (QliteQueryBuilderOrderingTerm** terms,
                                                 gint terms_length1)
{
	gboolean _tmp0_ = FALSE;
	gchar* res = NULL;
	QliteQueryBuilderOrderingTerm* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* result;
	if (terms == NULL) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = terms_length1 == 0;
	}
	if (_tmp0_) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("");
		result = _tmp1_;
		return result;
	}
	_tmp2_ = terms[0];
	_tmp3_ = qlite_query_builder_ordering_term_to_string (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = g_strconcat ("ORDER BY ", _tmp4_, NULL);
	_tmp6_ = _tmp5_;
	_g_free0 (_tmp4_);
	res = _tmp6_;
	{
		gint i = 0;
		i = 1;
		{
			gboolean _tmp7_ = FALSE;
			_tmp7_ = TRUE;
			while (TRUE) {
				const gchar* _tmp9_;
				QliteQueryBuilderOrderingTerm* _tmp10_;
				gchar* _tmp11_;
				gchar* _tmp12_;
				gchar* _tmp13_;
				gchar* _tmp14_;
				gchar* _tmp15_;
				if (!_tmp7_) {
					gint _tmp8_;
					_tmp8_ = i;
					i = _tmp8_ + 1;
				}
				_tmp7_ = FALSE;
				if (!(i < terms_length1)) {
					break;
				}
				_tmp9_ = res;
				_tmp10_ = terms[i];
				_tmp11_ = qlite_query_builder_ordering_term_to_string (_tmp10_);
				_tmp12_ = _tmp11_;
				_tmp13_ = g_strconcat (", ", _tmp12_, NULL);
				_tmp14_ = _tmp13_;
				_tmp15_ = g_strconcat (_tmp9_, _tmp14_, NULL);
				_g_free0 (res);
				res = _tmp15_;
				_g_free0 (_tmp14_);
				_g_free0 (_tmp12_);
			}
		}
	}
	result = res;
	return result;
}

static void
qlite_query_builder_value_ordering_term_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
qlite_query_builder_value_ordering_term_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		qlite_query_builder_ordering_term_unref (value->data[0].v_pointer);
	}
}

static void
qlite_query_builder_value_ordering_term_copy_value (const GValue* src_value,
                                                    GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = qlite_query_builder_ordering_term_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
qlite_query_builder_value_ordering_term_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
qlite_query_builder_value_ordering_term_collect_value (GValue* value,
                                                       guint n_collect_values,
                                                       GTypeCValue* collect_values,
                                                       guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		QliteQueryBuilderOrderingTerm * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = qlite_query_builder_ordering_term_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
qlite_query_builder_value_ordering_term_lcopy_value (const GValue* value,
                                                     guint n_collect_values,
                                                     GTypeCValue* collect_values,
                                                     guint collect_flags)
{
	QliteQueryBuilderOrderingTerm ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = qlite_query_builder_ordering_term_ref (value->data[0].v_pointer);
	}
	return NULL;
}

static GParamSpec*
qlite_query_builder_param_spec_ordering_term (const gchar* name,
                                              const gchar* nick,
                                              const gchar* blurb,
                                              GType object_type,
                                              GParamFlags flags)
{
	QliteQueryBuilderParamSpecOrderingTerm* spec;
	g_return_val_if_fail (g_type_is_a (object_type, QLITE_QUERY_BUILDER_TYPE_ORDERING_TERM), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

static gpointer
qlite_query_builder_value_get_ordering_term (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, QLITE_QUERY_BUILDER_TYPE_ORDERING_TERM), NULL);
	return value->data[0].v_pointer;
}

static void
qlite_query_builder_value_set_ordering_term (GValue* value,
                                             gpointer v_object)
{
	QliteQueryBuilderOrderingTerm * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, QLITE_QUERY_BUILDER_TYPE_ORDERING_TERM));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, QLITE_QUERY_BUILDER_TYPE_ORDERING_TERM));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		qlite_query_builder_ordering_term_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		qlite_query_builder_ordering_term_unref (old);
	}
}

static void
qlite_query_builder_value_take_ordering_term (GValue* value,
                                              gpointer v_object)
{
	QliteQueryBuilderOrderingTerm * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, QLITE_QUERY_BUILDER_TYPE_ORDERING_TERM));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, QLITE_QUERY_BUILDER_TYPE_ORDERING_TERM));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		qlite_query_builder_ordering_term_unref (old);
	}
}

static void
qlite_query_builder_ordering_term_class_init (QliteQueryBuilderOrderingTermClass * klass,
                                              gpointer klass_data)
{
	qlite_query_builder_ordering_term_parent_class = g_type_class_peek_parent (klass);
	((QliteQueryBuilderOrderingTermClass *) klass)->finalize = qlite_query_builder_ordering_term_finalize;
	g_type_class_adjust_private_offset (klass, &QliteQueryBuilderOrderingTerm_private_offset);
}

static void
qlite_query_builder_ordering_term_instance_init (QliteQueryBuilderOrderingTerm * self,
                                                 gpointer klass)
{
	self->priv = qlite_query_builder_ordering_term_get_instance_private (self);
	self->ref_count = 1;
}

static void
qlite_query_builder_ordering_term_finalize (QliteQueryBuilderOrderingTerm * obj)
{
	QliteQueryBuilderOrderingTerm * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, QLITE_QUERY_BUILDER_TYPE_ORDERING_TERM, QliteQueryBuilderOrderingTerm);
	g_signal_handlers_destroy (self);
	_qlite_column_unref0 (self->priv->column);
	_g_free0 (self->priv->column_name);
	_g_free0 (self->priv->dir);
}

static GType
qlite_query_builder_ordering_term_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { qlite_query_builder_value_ordering_term_init, qlite_query_builder_value_ordering_term_free_value, qlite_query_builder_value_ordering_term_copy_value, qlite_query_builder_value_ordering_term_peek_pointer, "p", qlite_query_builder_value_ordering_term_collect_value, "p", qlite_query_builder_value_ordering_term_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (QliteQueryBuilderOrderingTermClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) qlite_query_builder_ordering_term_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (QliteQueryBuilderOrderingTerm), 0, (GInstanceInitFunc) qlite_query_builder_ordering_term_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType qlite_query_builder_ordering_term_type_id;
	qlite_query_builder_ordering_term_type_id = g_type_register_fundamental (g_type_fundamental_next (), "QliteQueryBuilderOrderingTerm", &g_define_type_info, &g_define_type_fundamental_info, 0);
	QliteQueryBuilderOrderingTerm_private_offset = g_type_add_instance_private (qlite_query_builder_ordering_term_type_id, sizeof (QliteQueryBuilderOrderingTermPrivate));
	return qlite_query_builder_ordering_term_type_id;
}

static GType
qlite_query_builder_ordering_term_get_type (void)
{
	static volatile gsize qlite_query_builder_ordering_term_type_id__once = 0;
	if (g_once_init_enter (&qlite_query_builder_ordering_term_type_id__once)) {
		GType qlite_query_builder_ordering_term_type_id;
		qlite_query_builder_ordering_term_type_id = qlite_query_builder_ordering_term_get_type_once ();
		g_once_init_leave (&qlite_query_builder_ordering_term_type_id__once, qlite_query_builder_ordering_term_type_id);
	}
	return qlite_query_builder_ordering_term_type_id__once;
}

static gpointer
qlite_query_builder_ordering_term_ref (gpointer instance)
{
	QliteQueryBuilderOrderingTerm * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

static void
qlite_query_builder_ordering_term_unref (gpointer instance)
{
	QliteQueryBuilderOrderingTerm * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		QLITE_QUERY_BUILDER_ORDERING_TERM_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
qlite_query_builder_class_init (QliteQueryBuilderClass * klass,
                                gpointer klass_data)
{
	qlite_query_builder_parent_class = g_type_class_peek_parent (klass);
	((QliteStatementBuilderClass *) klass)->finalize = qlite_query_builder_finalize;
	g_type_class_adjust_private_offset (klass, &QliteQueryBuilder_private_offset);
	((QliteQueryBuilderClass *) klass)->from = (QliteQueryBuilder* (*) (QliteQueryBuilder*, QliteTable*)) qlite_query_builder_real_from;
	((QliteQueryBuilderClass *) klass)->from_name = (QliteQueryBuilder* (*) (QliteQueryBuilder*, const gchar*)) qlite_query_builder_real_from_name;
	((QliteStatementBuilderClass *) klass)->prepare = (sqlite3_stmt* (*) (QliteStatementBuilder*)) qlite_query_builder_real_prepare;
}

static void
qlite_query_builder_instance_init (QliteQueryBuilder * self,
                                   gpointer klass)
{
	gchar* _tmp0_;
	QliteColumn** _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	QliteStatementBuilderAbstractField** _tmp4_;
	QliteQueryBuilderOrderingTerm** _tmp5_;
	self->priv = qlite_query_builder_get_instance_private (self);
	_tmp0_ = g_strdup ("*");
	self->priv->column_selector = _tmp0_;
	_tmp1_ = g_new0 (QliteColumn*, 0 + 1);
	self->priv->columns = _tmp1_;
	self->priv->columns_length1 = 0;
	self->priv->_columns_size_ = self->priv->columns_length1;
	_tmp2_ = g_strdup ("");
	self->priv->joins = _tmp2_;
	_tmp3_ = g_strdup ("1");
	self->selection = _tmp3_;
	_tmp4_ = g_new0 (QliteStatementBuilderAbstractField*, 0 + 1);
	self->selection_args = _tmp4_;
	self->selection_args_length1 = 0;
	self->_selection_args_size_ = self->selection_args_length1;
	_tmp5_ = g_new0 (QliteQueryBuilderOrderingTerm*, 0 + 1);
	self->priv->order_by_terms = _tmp5_;
	self->priv->order_by_terms_length1 = 0;
	self->priv->_order_by_terms_size_ = self->priv->order_by_terms_length1;
}

static void
qlite_query_builder_finalize (QliteStatementBuilder * obj)
{
	QliteQueryBuilder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, QLITE_TYPE_QUERY_BUILDER, QliteQueryBuilder);
	_g_free0 (self->priv->column_selector);
	self->priv->columns = (_vala_array_free (self->priv->columns, self->priv->columns_length1, (GDestroyNotify) qlite_column_unref), NULL);
	_qlite_table_unref0 (self->table);
	_g_free0 (self->table_name);
	_g_free0 (self->priv->joins);
	_g_free0 (self->selection);
	self->selection_args = (_vala_array_free (self->selection_args, self->selection_args_length1, (GDestroyNotify) qlite_statement_builder_abstract_field_unref), NULL);
	self->priv->order_by_terms = (_vala_array_free (self->priv->order_by_terms, self->priv->order_by_terms_length1, (GDestroyNotify) qlite_query_builder_ordering_term_unref), NULL);
	_g_free0 (self->priv->group_by_term);
	QLITE_STATEMENT_BUILDER_CLASS (qlite_query_builder_parent_class)->finalize (obj);
}

static GType
qlite_query_builder_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (QliteQueryBuilderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) qlite_query_builder_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (QliteQueryBuilder), 0, (GInstanceInitFunc) qlite_query_builder_instance_init, NULL };
	GType qlite_query_builder_type_id;
	qlite_query_builder_type_id = g_type_register_static (QLITE_TYPE_STATEMENT_BUILDER, "QliteQueryBuilder", &g_define_type_info, 0);
	QliteQueryBuilder_private_offset = g_type_add_instance_private (qlite_query_builder_type_id, sizeof (QliteQueryBuilderPrivate));
	return qlite_query_builder_type_id;
}

GType
qlite_query_builder_get_type (void)
{
	static volatile gsize qlite_query_builder_type_id__once = 0;
	if (g_once_init_enter (&qlite_query_builder_type_id__once)) {
		GType qlite_query_builder_type_id;
		qlite_query_builder_type_id = qlite_query_builder_get_type_once ();
		g_once_init_leave (&qlite_query_builder_type_id__once, qlite_query_builder_type_id);
	}
	return qlite_query_builder_type_id__once;
}

QliteMatchQueryBuilder*
qlite_match_query_builder_construct (GType object_type,
                                     QliteDatabase* db,
                                     QliteTable* table)
{
	QliteMatchQueryBuilder* self = NULL;
	QliteColumn** _tmp0_;
	gint _tmp0__length1;
	QliteQueryBuilder* _tmp1_;
	QliteQueryBuilder* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	QliteQueryBuilder* _tmp13_;
	QliteQueryBuilder* _tmp14_;
	g_return_val_if_fail (db != NULL, NULL);
	g_return_val_if_fail (table != NULL, NULL);
	self = (QliteMatchQueryBuilder*) qlite_query_builder_construct (object_type, db);
	_tmp0_ = table->fts_columns;
	_tmp0__length1 = table->fts_columns_length1;
	if (_tmp0_ == NULL) {
		g_error ("query_builder.vala:224: MATCH query on non FTS table");
	}
	_tmp1_ = qlite_query_builder_from ((QliteQueryBuilder*) self, table);
	_tmp2_ = _tmp1_;
	_qlite_statement_builder_unref0 (_tmp2_);
	_tmp3_ = ((QliteQueryBuilder*) self)->table_name;
	_tmp4_ = string_to_string (_tmp3_);
	_tmp5_ = g_strconcat ("_fts_", _tmp4_, NULL);
	_tmp6_ = _tmp5_;
	_tmp7_ = ((QliteQueryBuilder*) self)->table_name;
	_tmp8_ = string_to_string (_tmp7_);
	_tmp9_ = ((QliteQueryBuilder*) self)->table_name;
	_tmp10_ = string_to_string (_tmp9_);
	_tmp11_ = g_strconcat ("_fts_", _tmp8_, ".docid = ", _tmp10_, ".rowid", NULL);
	_tmp12_ = _tmp11_;
	_tmp13_ = qlite_query_builder_join_name ((QliteQueryBuilder*) self, _tmp6_, _tmp12_);
	_tmp14_ = _tmp13_;
	_qlite_statement_builder_unref0 (_tmp14_);
	_g_free0 (_tmp12_);
	_g_free0 (_tmp6_);
	return self;
}

QliteMatchQueryBuilder*
qlite_match_query_builder_new (QliteDatabase* db,
                               QliteTable* table)
{
	return qlite_match_query_builder_construct (QLITE_TYPE_MATCH_QUERY_BUILDER, db, table);
}

static gboolean
_vala_qlite_column_array_contains (QliteColumn* * stack,
                                   gssize stack_length,
                                   const QliteColumn* needle)
{
	gssize i;
	for (i = 0; i < stack_length; i++) {
		if (needle == stack[i]) {
			return TRUE;
		}
	}
	return FALSE;
}

static void
_vala_array_add9 (QliteStatementBuilderAbstractField** * array,
                  gint* length,
                  gint* size,
                  QliteStatementBuilderAbstractField* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (QliteStatementBuilderAbstractField*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

QliteMatchQueryBuilder*
qlite_match_query_builder_match (QliteMatchQueryBuilder* self,
                                 QliteColumn* column,
                                 const gchar* match)
{
	QliteTable* _tmp0_;
	QliteTable* _tmp1_;
	QliteColumn** _tmp2_;
	gint _tmp2__length1;
	QliteStatementBuilderStringField* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	const gchar* _tmp8_;
	const gchar* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	QliteMatchQueryBuilder* _tmp12_;
	QliteMatchQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (column != NULL, NULL);
	g_return_val_if_fail (match != NULL, NULL);
	_tmp0_ = ((QliteQueryBuilder*) self)->table;
	if (_tmp0_ == NULL) {
		g_error ("query_builder.vala:230: MATCH must occur after FROM statement");
	}
	_tmp1_ = ((QliteQueryBuilder*) self)->table;
	_tmp2_ = _tmp1_->fts_columns;
	_tmp2__length1 = _tmp1_->fts_columns_length1;
	if (!_vala_qlite_column_array_contains (_tmp2_, _tmp2__length1, column)) {
		g_error ("query_builder.vala:231: MATCH selection on non FTS column");
	}
	_tmp3_ = qlite_statement_builder_string_field_new (match);
	_vala_array_add9 (&((QliteQueryBuilder*) self)->selection_args, &((QliteQueryBuilder*) self)->selection_args_length1, &((QliteQueryBuilder*) self)->_selection_args_size_, (QliteStatementBuilderAbstractField*) _tmp3_);
	_tmp4_ = ((QliteQueryBuilder*) self)->selection;
	_tmp5_ = string_to_string (_tmp4_);
	_tmp6_ = ((QliteQueryBuilder*) self)->table_name;
	_tmp7_ = string_to_string (_tmp6_);
	_tmp8_ = qlite_column_get_name (column);
	_tmp9_ = _tmp8_;
	_tmp10_ = string_to_string (_tmp9_);
	_tmp11_ = g_strconcat ("(", _tmp5_, ") AND _fts_", _tmp7_, ".", _tmp10_, " MATCH ?", NULL);
	_g_free0 (((QliteQueryBuilder*) self)->selection);
	((QliteQueryBuilder*) self)->selection = _tmp11_;
	_tmp12_ = _qlite_statement_builder_ref0 (self);
	result = _tmp12_;
	return result;
}

static void
qlite_match_query_builder_class_init (QliteMatchQueryBuilderClass * klass,
                                      gpointer klass_data)
{
	qlite_match_query_builder_parent_class = g_type_class_peek_parent (klass);
}

static void
qlite_match_query_builder_instance_init (QliteMatchQueryBuilder * self,
                                         gpointer klass)
{
}

static GType
qlite_match_query_builder_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (QliteMatchQueryBuilderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) qlite_match_query_builder_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (QliteMatchQueryBuilder), 0, (GInstanceInitFunc) qlite_match_query_builder_instance_init, NULL };
	GType qlite_match_query_builder_type_id;
	qlite_match_query_builder_type_id = g_type_register_static (QLITE_TYPE_QUERY_BUILDER, "QliteMatchQueryBuilder", &g_define_type_info, 0);
	return qlite_match_query_builder_type_id;
}

GType
qlite_match_query_builder_get_type (void)
{
	static volatile gsize qlite_match_query_builder_type_id__once = 0;
	if (g_once_init_enter (&qlite_match_query_builder_type_id__once)) {
		GType qlite_match_query_builder_type_id;
		qlite_match_query_builder_type_id = qlite_match_query_builder_get_type_once ();
		g_once_init_leave (&qlite_match_query_builder_type_id__once, qlite_match_query_builder_type_id);
	}
	return qlite_match_query_builder_type_id__once;
}

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

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

