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

#include "qlite.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <sqlite3.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_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_table_unref0(var) ((var == NULL) ? NULL : (var = (qlite_table_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

#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 _sqlite3_finalize0(var) ((var == NULL) ? NULL : (var = (sqlite3_finalize (var), NULL)))

struct _QliteDeleteBuilderPrivate {
	QliteTable* table;
	gchar* table_name;
	gchar* selection;
	QliteStatementBuilderAbstractField** selection_args;
	gint selection_args_length1;
	gint _selection_args_size_;
};

static gint QliteDeleteBuilder_private_offset;
static gpointer qlite_delete_builder_parent_class = NULL;

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 sqlite3_stmt* qlite_statement_builder_prepare (QliteStatementBuilder* self);
VALA_EXTERN QliteDeleteBuilder* qlite_delete_builder_new (QliteDatabase* db);
VALA_EXTERN QliteDeleteBuilder* qlite_delete_builder_construct (GType object_type,
                                                    QliteDatabase* db);
VALA_EXTERN QliteStatementBuilder* qlite_statement_builder_construct (GType object_type,
                                                          QliteDatabase* db);
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_add1 (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_add2 (QliteStatementBuilderAbstractField** * array,
                       gint* length,
                       gint* size,
                       QliteStatementBuilderAbstractField* value);
static sqlite3_stmt* qlite_delete_builder_real_prepare (QliteStatementBuilder* base);
VALA_EXTERN sqlite3_stmt* qlite_database_prepare (QliteDatabase* self,
                                      const gchar* sql);
VALA_EXTERN void qlite_statement_builder_abstract_field_bind (QliteStatementBuilderAbstractField* self,
                                                  sqlite3_stmt* stmt,
                                                  gint index);
VALA_EXTERN gint qlite_database_errcode (QliteDatabase* self);
VALA_EXTERN gchar* qlite_database_errmsg (QliteDatabase* self);
static void qlite_delete_builder_finalize (QliteStatementBuilder * obj);
static GType qlite_delete_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_delete_builder_get_instance_private (QliteDeleteBuilder* self)
{
	return G_STRUCT_MEMBER_P (self, QliteDeleteBuilder_private_offset);
}

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

QliteDeleteBuilder*
qlite_delete_builder_new (QliteDatabase* db)
{
	return qlite_delete_builder_construct (QLITE_TYPE_DELETE_BUILDER, db);
}

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

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

QliteDeleteBuilder*
qlite_delete_builder_from (QliteDeleteBuilder* self,
                           QliteTable* table)
{
	QliteTable* _tmp0_;
	QliteTable* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	gchar* _tmp4_;
	QliteDeleteBuilder* _tmp5_;
	QliteDeleteBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (table != NULL, NULL);
	_tmp0_ = self->priv->table;
	if (_tmp0_ != NULL) {
		g_error ("delete_builder.vala:20: Qlite Error: ILLEGAL QUERY: cannot use from() " \
"multiple times.");
	}
	_tmp1_ = _qlite_table_ref0 (table);
	_qlite_table_unref0 (self->priv->table);
	self->priv->table = _tmp1_;
	_tmp2_ = qlite_table_get_name (table);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strdup (_tmp3_);
	_g_free0 (self->priv->table_name);
	self->priv->table_name = _tmp4_;
	_tmp5_ = _qlite_statement_builder_ref0 (self);
	result = _tmp5_;
	return result;
}

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

static void
_vala_array_add1 (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;
}

QliteDeleteBuilder*
qlite_delete_builder_where (QliteDeleteBuilder* self,
                            const gchar* selection,
                            gchar** selection_args,
                            gint selection_args_length1)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	QliteDeleteBuilder* _tmp5_;
	QliteDeleteBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (selection != NULL, NULL);
	_tmp0_ = self->priv->selection;
	if (g_strcmp0 (_tmp0_, "1") != 0) {
		g_error ("delete_builder.vala:32: selection was already done, but where() was ca" \
"lled.");
	}
	_tmp1_ = g_strdup (selection);
	_g_free0 (self->priv->selection);
	self->priv->selection = _tmp1_;
	{
		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* _tmp2_;
			gchar* arg = NULL;
			_tmp2_ = g_strdup (arg_collection[arg_it]);
			arg = _tmp2_;
			{
				const gchar* _tmp3_;
				QliteStatementBuilderStringField* _tmp4_;
				_tmp3_ = arg;
				_tmp4_ = qlite_statement_builder_string_field_new (_tmp3_);
				_vala_array_add1 (&self->priv->selection_args, &self->priv->selection_args_length1, &self->priv->_selection_args_size_, (QliteStatementBuilderAbstractField*) _tmp4_);
				_g_free0 (arg);
			}
		}
	}
	_tmp5_ = _qlite_statement_builder_ref0 (self);
	result = _tmp5_;
	return result;
}

static void
_vala_array_add2 (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;
}

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

QliteDeleteBuilder*
qlite_delete_builder_with (QliteDeleteBuilder* self,
                           GType t_type,
                           GBoxedCopyFunc t_dup_func,
                           GDestroyNotify t_destroy_func,
                           QliteColumn* column,
                           const gchar* comp,
                           gconstpointer value)
{
	QliteStatementBuilderField* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	QliteDeleteBuilder* _tmp8_;
	QliteDeleteBuilder* 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);
	_tmp0_ = qlite_statement_builder_field_new (t_type, (GBoxedCopyFunc) t_dup_func, (GDestroyNotify) t_destroy_func, column, value);
	_vala_array_add2 (&self->priv->selection_args, &self->priv->selection_args_length1, &self->priv->_selection_args_size_, (QliteStatementBuilderAbstractField*) _tmp0_);
	_tmp1_ = self->priv->selection;
	_tmp2_ = string_to_string (_tmp1_);
	_tmp3_ = qlite_column_get_name (column);
	_tmp4_ = _tmp3_;
	_tmp5_ = string_to_string (_tmp4_);
	_tmp6_ = string_to_string (comp);
	_tmp7_ = g_strconcat ("(", _tmp2_, ") AND ", _tmp5_, " ", _tmp6_, " ?", NULL);
	_g_free0 (self->priv->selection);
	self->priv->selection = _tmp7_;
	_tmp8_ = _qlite_statement_builder_ref0 (self);
	result = _tmp8_;
	return result;
}

static sqlite3_stmt*
qlite_delete_builder_real_prepare (QliteStatementBuilder* base)
{
	QliteDeleteBuilder * self;
	sqlite3_stmt* stmt = NULL;
	QliteDatabase* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	sqlite3_stmt* _tmp7_;
	sqlite3_stmt* _tmp8_;
	sqlite3_stmt* result;
	self = (QliteDeleteBuilder*) base;
	_tmp0_ = ((QliteStatementBuilder*) self)->db;
	_tmp1_ = self->priv->table_name;
	_tmp2_ = string_to_string (_tmp1_);
	_tmp3_ = self->priv->selection;
	_tmp4_ = string_to_string (_tmp3_);
	_tmp5_ = g_strconcat ("DELETE FROM ", _tmp2_, " WHERE ", _tmp4_, NULL);
	_tmp6_ = _tmp5_;
	_tmp7_ = qlite_database_prepare (_tmp0_, _tmp6_);
	_tmp8_ = _tmp7_;
	_g_free0 (_tmp6_);
	stmt = _tmp8_;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp9_ = FALSE;
			_tmp9_ = TRUE;
			while (TRUE) {
				QliteStatementBuilderAbstractField** _tmp11_;
				gint _tmp11__length1;
				QliteStatementBuilderAbstractField** _tmp12_;
				gint _tmp12__length1;
				QliteStatementBuilderAbstractField* _tmp13_;
				sqlite3_stmt* _tmp14_;
				if (!_tmp9_) {
					gint _tmp10_;
					_tmp10_ = i;
					i = _tmp10_ + 1;
				}
				_tmp9_ = FALSE;
				_tmp11_ = self->priv->selection_args;
				_tmp11__length1 = self->priv->selection_args_length1;
				if (!(i < _tmp11__length1)) {
					break;
				}
				_tmp12_ = self->priv->selection_args;
				_tmp12__length1 = self->priv->selection_args_length1;
				_tmp13_ = _tmp12_[i];
				_tmp14_ = stmt;
				qlite_statement_builder_abstract_field_bind (_tmp13_, _tmp14_, i + 1);
			}
		}
	}
	result = stmt;
	return result;
}

void
qlite_delete_builder_perform (QliteDeleteBuilder* self)
{
	sqlite3_stmt* _tmp0_;
	sqlite3_stmt* _tmp1_;
	gboolean _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = qlite_statement_builder_prepare ((QliteStatementBuilder*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = sqlite3_step (_tmp1_) != SQLITE_DONE;
	_sqlite3_finalize0 (_tmp1_);
	if (_tmp2_) {
		QliteDatabase* _tmp3_;
		QliteDatabase* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp3_ = ((QliteStatementBuilder*) self)->db;
		_tmp4_ = ((QliteStatementBuilder*) self)->db;
		_tmp5_ = qlite_database_errmsg (_tmp4_);
		_tmp6_ = _tmp5_;
		g_critical ("delete_builder.vala:56: SQLite error: %d - %s", qlite_database_errcode (_tmp3_), _tmp6_);
		_g_free0 (_tmp6_);
	}
}

static void
qlite_delete_builder_class_init (QliteDeleteBuilderClass * klass,
                                 gpointer klass_data)
{
	qlite_delete_builder_parent_class = g_type_class_peek_parent (klass);
	((QliteStatementBuilderClass *) klass)->finalize = qlite_delete_builder_finalize;
	g_type_class_adjust_private_offset (klass, &QliteDeleteBuilder_private_offset);
	((QliteStatementBuilderClass *) klass)->prepare = (sqlite3_stmt* (*) (QliteStatementBuilder*)) qlite_delete_builder_real_prepare;
}

static void
qlite_delete_builder_instance_init (QliteDeleteBuilder * self,
                                    gpointer klass)
{
	gchar* _tmp0_;
	QliteStatementBuilderAbstractField** _tmp1_;
	self->priv = qlite_delete_builder_get_instance_private (self);
	_tmp0_ = g_strdup ("1");
	self->priv->selection = _tmp0_;
	_tmp1_ = g_new0 (QliteStatementBuilderAbstractField*, 0 + 1);
	self->priv->selection_args = _tmp1_;
	self->priv->selection_args_length1 = 0;
	self->priv->_selection_args_size_ = self->priv->selection_args_length1;
}

static void
qlite_delete_builder_finalize (QliteStatementBuilder * obj)
{
	QliteDeleteBuilder * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, QLITE_TYPE_DELETE_BUILDER, QliteDeleteBuilder);
	_qlite_table_unref0 (self->priv->table);
	_g_free0 (self->priv->table_name);
	_g_free0 (self->priv->selection);
	self->priv->selection_args = (_vala_array_free (self->priv->selection_args, self->priv->selection_args_length1, (GDestroyNotify) qlite_statement_builder_abstract_field_unref), NULL);
	QLITE_STATEMENT_BUILDER_CLASS (qlite_delete_builder_parent_class)->finalize (obj);
}

static GType
qlite_delete_builder_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (QliteDeleteBuilderClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) qlite_delete_builder_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (QliteDeleteBuilder), 0, (GInstanceInitFunc) qlite_delete_builder_instance_init, NULL };
	GType qlite_delete_builder_type_id;
	qlite_delete_builder_type_id = g_type_register_static (QLITE_TYPE_STATEMENT_BUILDER, "QliteDeleteBuilder", &g_define_type_info, 0);
	QliteDeleteBuilder_private_offset = g_type_add_instance_private (qlite_delete_builder_type_id, sizeof (QliteDeleteBuilderPrivate));
	return qlite_delete_builder_type_id;
}

GType
qlite_delete_builder_get_type (void)
{
	static volatile gsize qlite_delete_builder_type_id__once = 0;
	if (g_once_init_enter (&qlite_delete_builder_type_id__once)) {
		GType qlite_delete_builder_type_id;
		qlite_delete_builder_type_id = qlite_delete_builder_get_type_once ();
		g_once_init_leave (&qlite_delete_builder_type_id__once, qlite_delete_builder_type_id);
	}
	return qlite_delete_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);
}

