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

#include "omemo.h"
#include "qlite.h"
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <gee.h>
#include <omemo/curve.h>
#include <native/helper.h>
#include <omemo/signal_protocol_types.h>
#include <omemo/signal_protocol.h>
#include "libdino.h"

#define DINO_PLUGINS_OMEMO_DATABASE_VERSION 5
#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_table_unref0(var) ((var == NULL) ? NULL : (var = (qlite_table_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))
#define _qlite_column_unref0(var) ((var == NULL) ? NULL : (var = (qlite_column_unref (var), NULL)))
#define _qlite_statement_builder_unref0(var) ((var == NULL) ? NULL : (var = (qlite_statement_builder_unref (var), NULL)))
#define _g_date_time_unref0(var) ((var == NULL) ? NULL : (var = (g_date_time_unref (var), NULL)))
#define _signal_type_unref_vapi0(var) ((var == NULL) ? NULL : (var = (signal_type_unref_vapi (var), NULL)))
#define _signal_buffer_free0(var) ((var == NULL) ? NULL : (var = (signal_buffer_free (var), NULL)))
#define _qlite_row_option_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_option_unref (var), NULL)))
#define _qlite_row_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_unref (var), NULL)))

struct _DinoPluginsOmemoDatabasePrivate {
	DinoPluginsOmemoDatabaseIdentityMetaTable* _identity_meta;
	DinoPluginsOmemoDatabaseTrustTable* _trust;
	DinoPluginsOmemoDatabaseIdentityTable* _identity;
	DinoPluginsOmemoDatabaseSignedPreKeyTable* _signed_pre_key;
	DinoPluginsOmemoDatabasePreKeyTable* _pre_key;
	DinoPluginsOmemoDatabaseSessionTable* _session;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _content_item_meta;
};

static gint DinoPluginsOmemoDatabase_private_offset;
static gpointer dino_plugins_omemo_database_parent_class = NULL;
static gpointer dino_plugins_omemo_database_identity_meta_table_parent_class = NULL;
static gpointer dino_plugins_omemo_database_trust_table_parent_class = NULL;
static gpointer dino_plugins_omemo_database_identity_table_parent_class = NULL;
static gpointer dino_plugins_omemo_database_signed_pre_key_table_parent_class = NULL;
static gpointer dino_plugins_omemo_database_pre_key_table_parent_class = NULL;
static gpointer dino_plugins_omemo_database_session_table_parent_class = NULL;
static gpointer dino_plugins_omemo_database_content_item_meta_table_parent_class = NULL;

VALA_EXTERN DinoPluginsOmemoDatabaseIdentityMetaTable* dino_plugins_omemo_database_identity_meta_table_new (DinoPluginsOmemoDatabase* db);
VALA_EXTERN DinoPluginsOmemoDatabaseIdentityMetaTable* dino_plugins_omemo_database_identity_meta_table_construct (GType object_type,
                                                                                                      DinoPluginsOmemoDatabase* db);
static void dino_plugins_omemo_database_set_identity_meta (DinoPluginsOmemoDatabase* self,
                                                    DinoPluginsOmemoDatabaseIdentityMetaTable* value);
VALA_EXTERN DinoPluginsOmemoDatabaseTrustTable* dino_plugins_omemo_database_trust_table_new (DinoPluginsOmemoDatabase* db);
VALA_EXTERN DinoPluginsOmemoDatabaseTrustTable* dino_plugins_omemo_database_trust_table_construct (GType object_type,
                                                                                       DinoPluginsOmemoDatabase* db);
static void dino_plugins_omemo_database_set_trust (DinoPluginsOmemoDatabase* self,
                                            DinoPluginsOmemoDatabaseTrustTable* value);
VALA_EXTERN DinoPluginsOmemoDatabaseIdentityTable* dino_plugins_omemo_database_identity_table_new (DinoPluginsOmemoDatabase* db);
VALA_EXTERN DinoPluginsOmemoDatabaseIdentityTable* dino_plugins_omemo_database_identity_table_construct (GType object_type,
                                                                                             DinoPluginsOmemoDatabase* db);
static void dino_plugins_omemo_database_set_identity (DinoPluginsOmemoDatabase* self,
                                               DinoPluginsOmemoDatabaseIdentityTable* value);
VALA_EXTERN DinoPluginsOmemoDatabaseSignedPreKeyTable* dino_plugins_omemo_database_signed_pre_key_table_new (DinoPluginsOmemoDatabase* db);
VALA_EXTERN DinoPluginsOmemoDatabaseSignedPreKeyTable* dino_plugins_omemo_database_signed_pre_key_table_construct (GType object_type,
                                                                                                       DinoPluginsOmemoDatabase* db);
static void dino_plugins_omemo_database_set_signed_pre_key (DinoPluginsOmemoDatabase* self,
                                                     DinoPluginsOmemoDatabaseSignedPreKeyTable* value);
VALA_EXTERN DinoPluginsOmemoDatabasePreKeyTable* dino_plugins_omemo_database_pre_key_table_new (DinoPluginsOmemoDatabase* db);
VALA_EXTERN DinoPluginsOmemoDatabasePreKeyTable* dino_plugins_omemo_database_pre_key_table_construct (GType object_type,
                                                                                          DinoPluginsOmemoDatabase* db);
static void dino_plugins_omemo_database_set_pre_key (DinoPluginsOmemoDatabase* self,
                                              DinoPluginsOmemoDatabasePreKeyTable* value);
VALA_EXTERN DinoPluginsOmemoDatabaseSessionTable* dino_plugins_omemo_database_session_table_new (DinoPluginsOmemoDatabase* db);
VALA_EXTERN DinoPluginsOmemoDatabaseSessionTable* dino_plugins_omemo_database_session_table_construct (GType object_type,
                                                                                           DinoPluginsOmemoDatabase* db);
static void dino_plugins_omemo_database_set_session (DinoPluginsOmemoDatabase* self,
                                              DinoPluginsOmemoDatabaseSessionTable* value);
VALA_EXTERN DinoPluginsOmemoDatabaseContentItemMetaTable* dino_plugins_omemo_database_content_item_meta_table_new (DinoPluginsOmemoDatabase* db);
VALA_EXTERN DinoPluginsOmemoDatabaseContentItemMetaTable* dino_plugins_omemo_database_content_item_meta_table_construct (GType object_type,
                                                                                                             DinoPluginsOmemoDatabase* db);
static void dino_plugins_omemo_database_set_content_item_meta (DinoPluginsOmemoDatabase* self,
                                                        DinoPluginsOmemoDatabaseContentItemMetaTable* value);
static void dino_plugins_omemo_database_real_migrate (QliteDatabase* base,
                                               glong oldVersion);
static guint8* _vala_array_dup9 (guint8* self,
                          gssize length);
static void dino_plugins_omemo_database_identity_meta_table_finalize (QliteTable * obj);
static GType dino_plugins_omemo_database_identity_meta_table_get_type_once (void);
static void dino_plugins_omemo_database_trust_table_finalize (QliteTable * obj);
static GType dino_plugins_omemo_database_trust_table_get_type_once (void);
static void dino_plugins_omemo_database_identity_table_finalize (QliteTable * obj);
static GType dino_plugins_omemo_database_identity_table_get_type_once (void);
static void dino_plugins_omemo_database_signed_pre_key_table_finalize (QliteTable * obj);
static GType dino_plugins_omemo_database_signed_pre_key_table_get_type_once (void);
static void dino_plugins_omemo_database_pre_key_table_finalize (QliteTable * obj);
static GType dino_plugins_omemo_database_pre_key_table_get_type_once (void);
static void dino_plugins_omemo_database_session_table_finalize (QliteTable * obj);
static GType dino_plugins_omemo_database_session_table_get_type_once (void);
static void dino_plugins_omemo_database_content_item_meta_table_finalize (QliteTable * obj);
static GType dino_plugins_omemo_database_content_item_meta_table_get_type_once (void);
static void dino_plugins_omemo_database_finalize (QliteDatabase * obj);
static GType dino_plugins_omemo_database_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 _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_plugins_omemo_database_get_instance_private (DinoPluginsOmemoDatabase* self)
{
	return G_STRUCT_MEMBER_P (self, DinoPluginsOmemoDatabase_private_offset);
}

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

DinoPluginsOmemoDatabase*
dino_plugins_omemo_database_construct (GType object_type,
                                       const gchar* fileName)
{
	DinoPluginsOmemoDatabase* self = NULL;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp0_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp1_;
	DinoPluginsOmemoDatabaseTrustTable* _tmp2_;
	DinoPluginsOmemoDatabaseTrustTable* _tmp3_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp4_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp5_;
	DinoPluginsOmemoDatabaseSignedPreKeyTable* _tmp6_;
	DinoPluginsOmemoDatabaseSignedPreKeyTable* _tmp7_;
	DinoPluginsOmemoDatabasePreKeyTable* _tmp8_;
	DinoPluginsOmemoDatabasePreKeyTable* _tmp9_;
	DinoPluginsOmemoDatabaseSessionTable* _tmp10_;
	DinoPluginsOmemoDatabaseSessionTable* _tmp11_;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp12_;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp13_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp14_;
	QliteTable* _tmp15_;
	DinoPluginsOmemoDatabaseTrustTable* _tmp16_;
	QliteTable* _tmp17_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp18_;
	QliteTable* _tmp19_;
	DinoPluginsOmemoDatabaseSignedPreKeyTable* _tmp20_;
	QliteTable* _tmp21_;
	DinoPluginsOmemoDatabasePreKeyTable* _tmp22_;
	QliteTable* _tmp23_;
	DinoPluginsOmemoDatabaseSessionTable* _tmp24_;
	QliteTable* _tmp25_;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp26_;
	QliteTable* _tmp27_;
	QliteTable** _tmp28_;
	QliteTable** _tmp29_;
	gint _tmp29__length1;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (fileName != NULL, NULL);
	self = (DinoPluginsOmemoDatabase*) qlite_database_construct (object_type, fileName, (glong) DINO_PLUGINS_OMEMO_DATABASE_VERSION);
	_tmp0_ = dino_plugins_omemo_database_identity_meta_table_new (self);
	_tmp1_ = _tmp0_;
	dino_plugins_omemo_database_set_identity_meta (self, _tmp1_);
	_qlite_table_unref0 (_tmp1_);
	_tmp2_ = dino_plugins_omemo_database_trust_table_new (self);
	_tmp3_ = _tmp2_;
	dino_plugins_omemo_database_set_trust (self, _tmp3_);
	_qlite_table_unref0 (_tmp3_);
	_tmp4_ = dino_plugins_omemo_database_identity_table_new (self);
	_tmp5_ = _tmp4_;
	dino_plugins_omemo_database_set_identity (self, _tmp5_);
	_qlite_table_unref0 (_tmp5_);
	_tmp6_ = dino_plugins_omemo_database_signed_pre_key_table_new (self);
	_tmp7_ = _tmp6_;
	dino_plugins_omemo_database_set_signed_pre_key (self, _tmp7_);
	_qlite_table_unref0 (_tmp7_);
	_tmp8_ = dino_plugins_omemo_database_pre_key_table_new (self);
	_tmp9_ = _tmp8_;
	dino_plugins_omemo_database_set_pre_key (self, _tmp9_);
	_qlite_table_unref0 (_tmp9_);
	_tmp10_ = dino_plugins_omemo_database_session_table_new (self);
	_tmp11_ = _tmp10_;
	dino_plugins_omemo_database_set_session (self, _tmp11_);
	_qlite_table_unref0 (_tmp11_);
	_tmp12_ = dino_plugins_omemo_database_content_item_meta_table_new (self);
	_tmp13_ = _tmp12_;
	dino_plugins_omemo_database_set_content_item_meta (self, _tmp13_);
	_qlite_table_unref0 (_tmp13_);
	_tmp14_ = self->priv->_identity_meta;
	_tmp15_ = _qlite_table_ref0 ((QliteTable*) _tmp14_);
	_tmp16_ = self->priv->_trust;
	_tmp17_ = _qlite_table_ref0 ((QliteTable*) _tmp16_);
	_tmp18_ = self->priv->_identity;
	_tmp19_ = _qlite_table_ref0 ((QliteTable*) _tmp18_);
	_tmp20_ = self->priv->_signed_pre_key;
	_tmp21_ = _qlite_table_ref0 ((QliteTable*) _tmp20_);
	_tmp22_ = self->priv->_pre_key;
	_tmp23_ = _qlite_table_ref0 ((QliteTable*) _tmp22_);
	_tmp24_ = self->priv->_session;
	_tmp25_ = _qlite_table_ref0 ((QliteTable*) _tmp24_);
	_tmp26_ = self->priv->_content_item_meta;
	_tmp27_ = _qlite_table_ref0 ((QliteTable*) _tmp26_);
	_tmp28_ = g_new0 (QliteTable*, 7 + 1);
	_tmp28_[0] = _tmp15_;
	_tmp28_[1] = _tmp17_;
	_tmp28_[2] = _tmp19_;
	_tmp28_[3] = _tmp21_;
	_tmp28_[4] = _tmp23_;
	_tmp28_[5] = _tmp25_;
	_tmp28_[6] = _tmp27_;
	_tmp29_ = _tmp28_;
	_tmp29__length1 = 7;
	qlite_database_init ((QliteDatabase*) self, _tmp29_, (gint) 7);
	_tmp29_ = (_vala_array_free (_tmp29_, _tmp29__length1, (GDestroyNotify) qlite_table_unref), NULL);
	{
		qlite_database_exec ((QliteDatabase*) self, "PRAGMA journal_mode = WAL", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		qlite_database_exec ((QliteDatabase*) self, "PRAGMA synchronous = NORMAL", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		qlite_database_exec ((QliteDatabase*) self, "PRAGMA secure_delete = ON", &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		const gchar* _tmp30_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp30_ = e->message;
		g_error ("database.vala:265: Failed to set OMEMO database properties: %s", _tmp30_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return NULL;
	}
	return self;
}

DinoPluginsOmemoDatabase*
dino_plugins_omemo_database_new (const gchar* fileName)
{
	return dino_plugins_omemo_database_construct (DINO_PLUGINS_OMEMO_TYPE_DATABASE, fileName);
}

static void
dino_plugins_omemo_database_real_migrate (QliteDatabase* base,
                                          glong oldVersion)
{
	DinoPluginsOmemoDatabase * self;
	GError* _inner_error0_ = NULL;
	self = (DinoPluginsOmemoDatabase*) base;
	if (oldVersion == ((glong) 1)) {
		{
			qlite_database_exec ((QliteDatabase*) self, "DROP INDEX identity_meta_idx", &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			qlite_database_exec ((QliteDatabase*) self, "DROP INDEX identity_meta_list_idx", &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			qlite_database_exec ((QliteDatabase*) self, "CREATE UNIQUE INDEX identity_meta_idx ON identity_meta (identity_id, a" \
"ddress_name, device_id)", &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
			qlite_database_exec ((QliteDatabase*) self, "CREATE INDEX identity_meta_list_idx ON identity_meta (identity_id, add" \
"ress_name)", &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				goto __catch0_g_error;
			}
		}
		goto __finally0;
		__catch0_g_error:
		{
			FILE* _tmp0_;
			g_clear_error (&_inner_error0_);
			_tmp0_ = stderr;
			fprintf (_tmp0_, "Failed to migrate OMEMO database\n");
			exit (-1);
		}
		__finally0:
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return;
		}
	}
}

DinoPluginsOmemoDatabaseIdentityMetaTable*
dino_plugins_omemo_database_get_identity_meta (DinoPluginsOmemoDatabase* self)
{
	DinoPluginsOmemoDatabaseIdentityMetaTable* result;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_identity_meta;
	result = _tmp0_;
	return result;
}

static void
dino_plugins_omemo_database_set_identity_meta (DinoPluginsOmemoDatabase* self,
                                               DinoPluginsOmemoDatabaseIdentityMetaTable* value)
{
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _qlite_table_ref0 (value);
	_qlite_table_unref0 (self->priv->_identity_meta);
	self->priv->_identity_meta = _tmp0_;
}

DinoPluginsOmemoDatabaseTrustTable*
dino_plugins_omemo_database_get_trust (DinoPluginsOmemoDatabase* self)
{
	DinoPluginsOmemoDatabaseTrustTable* result;
	DinoPluginsOmemoDatabaseTrustTable* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_trust;
	result = _tmp0_;
	return result;
}

static void
dino_plugins_omemo_database_set_trust (DinoPluginsOmemoDatabase* self,
                                       DinoPluginsOmemoDatabaseTrustTable* value)
{
	DinoPluginsOmemoDatabaseTrustTable* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _qlite_table_ref0 (value);
	_qlite_table_unref0 (self->priv->_trust);
	self->priv->_trust = _tmp0_;
}

DinoPluginsOmemoDatabaseIdentityTable*
dino_plugins_omemo_database_get_identity (DinoPluginsOmemoDatabase* self)
{
	DinoPluginsOmemoDatabaseIdentityTable* result;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_identity;
	result = _tmp0_;
	return result;
}

static void
dino_plugins_omemo_database_set_identity (DinoPluginsOmemoDatabase* self,
                                          DinoPluginsOmemoDatabaseIdentityTable* value)
{
	DinoPluginsOmemoDatabaseIdentityTable* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _qlite_table_ref0 (value);
	_qlite_table_unref0 (self->priv->_identity);
	self->priv->_identity = _tmp0_;
}

DinoPluginsOmemoDatabaseSignedPreKeyTable*
dino_plugins_omemo_database_get_signed_pre_key (DinoPluginsOmemoDatabase* self)
{
	DinoPluginsOmemoDatabaseSignedPreKeyTable* result;
	DinoPluginsOmemoDatabaseSignedPreKeyTable* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_signed_pre_key;
	result = _tmp0_;
	return result;
}

static void
dino_plugins_omemo_database_set_signed_pre_key (DinoPluginsOmemoDatabase* self,
                                                DinoPluginsOmemoDatabaseSignedPreKeyTable* value)
{
	DinoPluginsOmemoDatabaseSignedPreKeyTable* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _qlite_table_ref0 (value);
	_qlite_table_unref0 (self->priv->_signed_pre_key);
	self->priv->_signed_pre_key = _tmp0_;
}

DinoPluginsOmemoDatabasePreKeyTable*
dino_plugins_omemo_database_get_pre_key (DinoPluginsOmemoDatabase* self)
{
	DinoPluginsOmemoDatabasePreKeyTable* result;
	DinoPluginsOmemoDatabasePreKeyTable* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_pre_key;
	result = _tmp0_;
	return result;
}

static void
dino_plugins_omemo_database_set_pre_key (DinoPluginsOmemoDatabase* self,
                                         DinoPluginsOmemoDatabasePreKeyTable* value)
{
	DinoPluginsOmemoDatabasePreKeyTable* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _qlite_table_ref0 (value);
	_qlite_table_unref0 (self->priv->_pre_key);
	self->priv->_pre_key = _tmp0_;
}

DinoPluginsOmemoDatabaseSessionTable*
dino_plugins_omemo_database_get_session (DinoPluginsOmemoDatabase* self)
{
	DinoPluginsOmemoDatabaseSessionTable* result;
	DinoPluginsOmemoDatabaseSessionTable* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_session;
	result = _tmp0_;
	return result;
}

static void
dino_plugins_omemo_database_set_session (DinoPluginsOmemoDatabase* self,
                                         DinoPluginsOmemoDatabaseSessionTable* value)
{
	DinoPluginsOmemoDatabaseSessionTable* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _qlite_table_ref0 (value);
	_qlite_table_unref0 (self->priv->_session);
	self->priv->_session = _tmp0_;
}

DinoPluginsOmemoDatabaseContentItemMetaTable*
dino_plugins_omemo_database_get_content_item_meta (DinoPluginsOmemoDatabase* self)
{
	DinoPluginsOmemoDatabaseContentItemMetaTable* result;
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_content_item_meta;
	result = _tmp0_;
	return result;
}

static void
dino_plugins_omemo_database_set_content_item_meta (DinoPluginsOmemoDatabase* self,
                                                   DinoPluginsOmemoDatabaseContentItemMetaTable* value)
{
	DinoPluginsOmemoDatabaseContentItemMetaTable* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = _qlite_table_ref0 (value);
	_qlite_table_unref0 (self->priv->_content_item_meta);
	self->priv->_content_item_meta = _tmp0_;
}

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

DinoPluginsOmemoDatabaseIdentityMetaTable*
dino_plugins_omemo_database_identity_meta_table_construct (GType object_type,
                                                           DinoPluginsOmemoDatabase* db)
{
	DinoPluginsOmemoDatabaseIdentityMetaTable* self = NULL;
	QliteColumn* _tmp0_;
	QliteColumn* _tmp1_;
	QliteColumn* _tmp2_;
	QliteColumn* _tmp3_;
	QliteColumn* _tmp4_;
	QliteColumn* _tmp5_;
	QliteColumn* _tmp6_;
	QliteColumn* _tmp7_;
	QliteColumn* _tmp8_;
	QliteColumn* _tmp9_;
	QliteColumn* _tmp10_;
	QliteColumn* _tmp11_;
	QliteColumn* _tmp12_;
	QliteColumn* _tmp13_;
	QliteColumn* _tmp14_;
	QliteColumn* _tmp15_;
	QliteColumn* _tmp16_;
	QliteColumn* _tmp17_;
	QliteColumn* _tmp18_;
	QliteColumn* _tmp19_;
	QliteColumn** _tmp20_;
	QliteColumn** _tmp21_;
	gint _tmp21__length1;
	QliteColumn* _tmp22_;
	QliteColumn* _tmp23_;
	QliteColumn* _tmp24_;
	QliteColumn* _tmp25_;
	QliteColumn* _tmp26_;
	QliteColumn* _tmp27_;
	QliteColumn** _tmp28_;
	QliteColumn** _tmp29_;
	gint _tmp29__length1;
	QliteColumn* _tmp30_;
	QliteColumn* _tmp31_;
	QliteColumn* _tmp32_;
	QliteColumn* _tmp33_;
	QliteColumn** _tmp34_;
	QliteColumn** _tmp35_;
	gint _tmp35__length1;
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoPluginsOmemoDatabaseIdentityMetaTable*) qlite_table_construct (object_type, (QliteDatabase*) db, "identity_meta");
	_tmp0_ = self->identity_id;
	_tmp1_ = _qlite_column_ref0 (_tmp0_);
	_tmp2_ = self->address_name;
	_tmp3_ = _qlite_column_ref0 (_tmp2_);
	_tmp4_ = self->device_id;
	_tmp5_ = _qlite_column_ref0 (_tmp4_);
	_tmp6_ = self->identity_key_public_base64;
	_tmp7_ = _qlite_column_ref0 (_tmp6_);
	_tmp8_ = self->trusted_identity;
	_tmp9_ = _qlite_column_ref0 (_tmp8_);
	_tmp10_ = self->trust_level;
	_tmp11_ = _qlite_column_ref0 (_tmp10_);
	_tmp12_ = self->now_active;
	_tmp13_ = _qlite_column_ref0 (_tmp12_);
	_tmp14_ = self->last_active;
	_tmp15_ = _qlite_column_ref0 (_tmp14_);
	_tmp16_ = self->last_message_untrusted;
	_tmp17_ = _qlite_column_ref0 (_tmp16_);
	_tmp18_ = self->last_message_undecryptable;
	_tmp19_ = _qlite_column_ref0 (_tmp18_);
	_tmp20_ = g_new0 (QliteColumn*, 10 + 1);
	_tmp20_[0] = _tmp1_;
	_tmp20_[1] = _tmp3_;
	_tmp20_[2] = _tmp5_;
	_tmp20_[3] = _tmp7_;
	_tmp20_[4] = _tmp9_;
	_tmp20_[5] = _tmp11_;
	_tmp20_[6] = _tmp13_;
	_tmp20_[7] = _tmp15_;
	_tmp20_[8] = _tmp17_;
	_tmp20_[9] = _tmp19_;
	_tmp21_ = _tmp20_;
	_tmp21__length1 = 10;
	qlite_table_init ((QliteTable*) self, _tmp21_, (gint) 10, "");
	_tmp21_ = (_vala_array_free (_tmp21_, _tmp21__length1, (GDestroyNotify) qlite_column_unref), NULL);
	_tmp22_ = self->identity_id;
	_tmp23_ = _qlite_column_ref0 (_tmp22_);
	_tmp24_ = self->address_name;
	_tmp25_ = _qlite_column_ref0 (_tmp24_);
	_tmp26_ = self->device_id;
	_tmp27_ = _qlite_column_ref0 (_tmp26_);
	_tmp28_ = g_new0 (QliteColumn*, 3 + 1);
	_tmp28_[0] = _tmp23_;
	_tmp28_[1] = _tmp25_;
	_tmp28_[2] = _tmp27_;
	_tmp29_ = _tmp28_;
	_tmp29__length1 = 3;
	qlite_table_index ((QliteTable*) self, "identity_meta_idx", _tmp29_, (gint) 3, TRUE);
	_tmp29_ = (_vala_array_free (_tmp29_, _tmp29__length1, (GDestroyNotify) qlite_column_unref), NULL);
	_tmp30_ = self->identity_id;
	_tmp31_ = _qlite_column_ref0 (_tmp30_);
	_tmp32_ = self->address_name;
	_tmp33_ = _qlite_column_ref0 (_tmp32_);
	_tmp34_ = g_new0 (QliteColumn*, 2 + 1);
	_tmp34_[0] = _tmp31_;
	_tmp34_[1] = _tmp33_;
	_tmp35_ = _tmp34_;
	_tmp35__length1 = 2;
	qlite_table_index ((QliteTable*) self, "identity_meta_list_idx", _tmp35_, (gint) 2, FALSE);
	_tmp35_ = (_vala_array_free (_tmp35_, _tmp35__length1, (GDestroyNotify) qlite_column_unref), NULL);
	return self;
}

DinoPluginsOmemoDatabaseIdentityMetaTable*
dino_plugins_omemo_database_identity_meta_table_new (DinoPluginsOmemoDatabase* db)
{
	return dino_plugins_omemo_database_identity_meta_table_construct (DINO_PLUGINS_OMEMO_DATABASE_TYPE_IDENTITY_META_TABLE, db);
}

QliteQueryBuilder*
dino_plugins_omemo_database_identity_meta_table_with_address (DinoPluginsOmemoDatabaseIdentityMetaTable* self,
                                                              gint identity_id,
                                                              const gchar* address_name)
{
	QliteQueryBuilder* _tmp0_;
	QliteQueryBuilder* _tmp1_;
	QliteColumn* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	QliteQueryBuilder* _tmp4_;
	QliteColumn* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	QliteQueryBuilder* _tmp7_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (address_name != NULL, NULL);
	_tmp0_ = qlite_table_select ((QliteTable*) self, NULL, (gint) 0);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->identity_id;
	_tmp3_ = qlite_query_builder_with (_tmp1_, G_TYPE_INT, NULL, NULL, _tmp2_, "=", (gpointer) ((gintptr) identity_id));
	_tmp4_ = _tmp3_;
	_tmp5_ = self->address_name;
	_tmp6_ = qlite_query_builder_with (_tmp4_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp5_, "=", address_name);
	_tmp7_ = _tmp6_;
	_qlite_statement_builder_unref0 (_tmp4_);
	_qlite_statement_builder_unref0 (_tmp1_);
	result = _tmp7_;
	return result;
}

QliteQueryBuilder*
dino_plugins_omemo_database_identity_meta_table_get_with_device_id (DinoPluginsOmemoDatabaseIdentityMetaTable* self,
                                                                    gint identity_id,
                                                                    gint device_id)
{
	QliteQueryBuilder* _tmp0_;
	QliteQueryBuilder* _tmp1_;
	QliteColumn* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	QliteQueryBuilder* _tmp4_;
	QliteColumn* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	QliteQueryBuilder* _tmp7_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = qlite_table_select ((QliteTable*) self, NULL, (gint) 0);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->identity_id;
	_tmp3_ = qlite_query_builder_with (_tmp1_, G_TYPE_INT, NULL, NULL, _tmp2_, "=", (gpointer) ((gintptr) identity_id));
	_tmp4_ = _tmp3_;
	_tmp5_ = self->device_id;
	_tmp6_ = qlite_query_builder_with (_tmp4_, G_TYPE_INT, NULL, NULL, _tmp5_, "=", (gpointer) ((gintptr) device_id));
	_tmp7_ = _tmp6_;
	_qlite_statement_builder_unref0 (_tmp4_);
	_qlite_statement_builder_unref0 (_tmp1_);
	result = _tmp7_;
	return result;
}

void
dino_plugins_omemo_database_identity_meta_table_insert_device_list (DinoPluginsOmemoDatabaseIdentityMetaTable* self,
                                                                    gint32 identity_id,
                                                                    const gchar* address_name,
                                                                    GeeArrayList* devices)
{
	QliteUpdateBuilder* _tmp0_;
	QliteUpdateBuilder* _tmp1_;
	QliteColumn* _tmp2_;
	QliteUpdateBuilder* _tmp3_;
	QliteUpdateBuilder* _tmp4_;
	QliteColumn* _tmp5_;
	QliteUpdateBuilder* _tmp6_;
	QliteUpdateBuilder* _tmp7_;
	QliteColumn* _tmp8_;
	QliteUpdateBuilder* _tmp9_;
	QliteUpdateBuilder* _tmp10_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (address_name != NULL);
	g_return_if_fail (devices != NULL);
	_tmp0_ = qlite_table_update ((QliteTable*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->identity_id;
	_tmp3_ = qlite_update_builder_with (_tmp1_, G_TYPE_INT, NULL, NULL, _tmp2_, "=", (gpointer) ((gintptr) identity_id));
	_tmp4_ = _tmp3_;
	_tmp5_ = self->address_name;
	_tmp6_ = qlite_update_builder_with (_tmp4_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp5_, "=", address_name);
	_tmp7_ = _tmp6_;
	_tmp8_ = self->now_active;
	_tmp9_ = qlite_update_builder_set (_tmp7_, G_TYPE_BOOLEAN, NULL, NULL, _tmp8_, (gpointer) ((gintptr) FALSE));
	_tmp10_ = _tmp9_;
	qlite_update_builder_perform (_tmp10_);
	_qlite_statement_builder_unref0 (_tmp10_);
	_qlite_statement_builder_unref0 (_tmp7_);
	_qlite_statement_builder_unref0 (_tmp4_);
	_qlite_statement_builder_unref0 (_tmp1_);
	{
		GeeArrayList* _device_id_list = NULL;
		gint _device_id_size = 0;
		GeeArrayList* _tmp11_;
		gint _tmp12_;
		gint _tmp13_;
		gint _device_id_index = 0;
		_device_id_list = devices;
		_tmp11_ = _device_id_list;
		_tmp12_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp11_);
		_tmp13_ = _tmp12_;
		_device_id_size = _tmp13_;
		_device_id_index = -1;
		while (TRUE) {
			gint _tmp14_;
			gint _tmp15_;
			gint32 device_id = 0;
			GeeArrayList* _tmp16_;
			gpointer _tmp17_;
			QliteUpsertBuilder* _tmp18_;
			QliteUpsertBuilder* _tmp19_;
			QliteColumn* _tmp20_;
			QliteUpsertBuilder* _tmp21_;
			QliteUpsertBuilder* _tmp22_;
			QliteColumn* _tmp23_;
			QliteUpsertBuilder* _tmp24_;
			QliteUpsertBuilder* _tmp25_;
			QliteColumn* _tmp26_;
			QliteUpsertBuilder* _tmp27_;
			QliteUpsertBuilder* _tmp28_;
			QliteColumn* _tmp29_;
			QliteUpsertBuilder* _tmp30_;
			QliteUpsertBuilder* _tmp31_;
			QliteColumn* _tmp32_;
			GDateTime* _tmp33_;
			GDateTime* _tmp34_;
			QliteUpsertBuilder* _tmp35_;
			QliteUpsertBuilder* _tmp36_;
			_device_id_index = _device_id_index + 1;
			_tmp14_ = _device_id_index;
			_tmp15_ = _device_id_size;
			if (!(_tmp14_ < _tmp15_)) {
				break;
			}
			_tmp16_ = _device_id_list;
			_tmp17_ = gee_abstract_list_get ((GeeAbstractList*) _tmp16_, _device_id_index);
			device_id = (gint32) ((gintptr) _tmp17_);
			_tmp18_ = qlite_table_upsert ((QliteTable*) self);
			_tmp19_ = _tmp18_;
			_tmp20_ = self->identity_id;
			_tmp21_ = qlite_upsert_builder_value (_tmp19_, G_TYPE_INT, NULL, NULL, _tmp20_, (gpointer) ((gintptr) identity_id), TRUE);
			_tmp22_ = _tmp21_;
			_tmp23_ = self->address_name;
			_tmp24_ = qlite_upsert_builder_value (_tmp22_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp23_, address_name, TRUE);
			_tmp25_ = _tmp24_;
			_tmp26_ = self->device_id;
			_tmp27_ = qlite_upsert_builder_value (_tmp25_, G_TYPE_INT, NULL, NULL, _tmp26_, (gpointer) ((gintptr) device_id), TRUE);
			_tmp28_ = _tmp27_;
			_tmp29_ = self->now_active;
			_tmp30_ = qlite_upsert_builder_value (_tmp28_, G_TYPE_BOOLEAN, NULL, NULL, _tmp29_, (gpointer) ((gintptr) TRUE), FALSE);
			_tmp31_ = _tmp30_;
			_tmp32_ = self->last_active;
			_tmp33_ = g_date_time_new_now_utc ();
			_tmp34_ = _tmp33_;
			_tmp35_ = qlite_upsert_builder_value (_tmp31_, G_TYPE_LONG, NULL, NULL, _tmp32_, (gpointer) ((gintptr) g_date_time_to_unix (_tmp34_)), FALSE);
			_tmp36_ = _tmp35_;
			qlite_upsert_builder_perform (_tmp36_);
			_qlite_statement_builder_unref0 (_tmp36_);
			_g_date_time_unref0 (_tmp34_);
			_qlite_statement_builder_unref0 (_tmp31_);
			_qlite_statement_builder_unref0 (_tmp28_);
			_qlite_statement_builder_unref0 (_tmp25_);
			_qlite_statement_builder_unref0 (_tmp22_);
			_qlite_statement_builder_unref0 (_tmp19_);
		}
	}
}

static guint8*
signal_buffer_get_data (signal_buffer* self,
                        gint* result_length1)
{
	guint8* result;
	gint x = 0;
	guint8* res = NULL;
	guint8* _tmp0_;
	gint res_length1;
	gint _res_size_;
	guint8* _tmp1_;
	gint _tmp1__length1;
	g_return_val_if_fail (self != NULL, NULL);
	x = (gint) signal_buffer_len (self);
	_tmp0_ = signal_buffer_data (self);
	res = _tmp0_;
	res_length1 = -1;
	_res_size_ = res_length1;
	res_length1 = x;
	_tmp1_ = res;
	_tmp1__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp1__length1;
	}
	result = _tmp1_;
	return result;
}

static guint8*
_vala_array_dup9 (guint8* self,
                  gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static guint8*
ec_public_key_serialize_ (ec_public_key* self,
                          gint* result_length1)
{
	signal_buffer* buffer = NULL;
	gint code = 0;
	signal_buffer* _tmp0_ = NULL;
	gint _tmp1_;
	gboolean _tmp2_ = FALSE;
	signal_buffer* _tmp3_;
	guint8* _tmp4_;
	gint _tmp4__length1;
	gint _tmp5_ = 0;
	guint8* _tmp6_;
	gint _tmp6__length1;
	guint8* _tmp7_;
	gint _tmp7__length1;
	guint8* _tmp8_;
	gint _tmp8__length1;
	guint8* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = ec_public_key_serialize (&_tmp0_, self);
	_signal_buffer_free0 (buffer);
	buffer = _tmp0_;
	code = _tmp1_;
	if (code < 0) {
		_tmp2_ = code > SG_ERR_MINIMUM;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		g_assert_not_reached ();
	}
	_tmp3_ = buffer;
	_tmp4_ = signal_buffer_get_data (_tmp3_, &_tmp5_);
	_tmp4__length1 = _tmp5_;
	_tmp6_ = _tmp4_;
	_tmp6__length1 = _tmp4__length1;
	_tmp7_ = (_tmp6_ != NULL) ? _vala_array_dup9 (_tmp6_, _tmp6__length1) : _tmp6_;
	_tmp7__length1 = _tmp6__length1;
	_tmp8_ = _tmp7_;
	_tmp8__length1 = _tmp7__length1;
	if (result_length1) {
		*result_length1 = _tmp8__length1;
	}
	result = _tmp8_;
	_signal_buffer_free0 (buffer);
	return result;
}

gint64
dino_plugins_omemo_database_identity_meta_table_insert_device_bundle (DinoPluginsOmemoDatabaseIdentityMetaTable* self,
                                                                      gint32 identity_id,
                                                                      const gchar* address_name,
                                                                      gint device_id,
                                                                      DinoPluginsOmemoBundle* bundle,
                                                                      DinoPluginsOmemoTrustLevel trust)
{
	gboolean _tmp0_ = FALSE;
	gchar* identity_key = NULL;
	ec_public_key* _tmp4_;
	ec_public_key* _tmp5_;
	ec_public_key* _tmp6_;
	gint _tmp7_ = 0;
	guint8* _tmp8_;
	guint8* _tmp9_;
	gint _tmp9__length1;
	gchar* _tmp10_;
	gchar* _tmp11_;
	QliteRowOption* row = NULL;
	QliteQueryBuilder* _tmp12_;
	QliteQueryBuilder* _tmp13_;
	QliteColumn* _tmp14_;
	QliteQueryBuilder* _tmp15_;
	QliteQueryBuilder* _tmp16_;
	QliteQueryBuilder* _tmp17_;
	QliteQueryBuilder* _tmp18_;
	QliteRowOption* _tmp19_;
	QliteRowOption* _tmp20_;
	gboolean _tmp21_ = FALSE;
	gboolean _tmp22_ = FALSE;
	QliteRowOption* _tmp23_;
	QliteUpsertBuilder* _tmp33_;
	QliteUpsertBuilder* _tmp34_;
	QliteColumn* _tmp35_;
	QliteUpsertBuilder* _tmp36_;
	QliteUpsertBuilder* _tmp37_;
	QliteColumn* _tmp38_;
	QliteUpsertBuilder* _tmp39_;
	QliteUpsertBuilder* _tmp40_;
	QliteColumn* _tmp41_;
	QliteUpsertBuilder* _tmp42_;
	QliteUpsertBuilder* _tmp43_;
	QliteColumn* _tmp44_;
	const gchar* _tmp45_;
	QliteUpsertBuilder* _tmp46_;
	QliteUpsertBuilder* _tmp47_;
	QliteColumn* _tmp48_;
	QliteUpsertBuilder* _tmp49_;
	QliteUpsertBuilder* _tmp50_;
	gint64 _tmp51_;
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	g_return_val_if_fail (address_name != NULL, -1LL);
	g_return_val_if_fail (bundle != NULL, -1LL);
	if (bundle == NULL) {
		_tmp0_ = TRUE;
	} else {
		ec_public_key* _tmp1_;
		ec_public_key* _tmp2_;
		ec_public_key* _tmp3_;
		_tmp1_ = dino_plugins_omemo_bundle_get_identity_key (bundle);
		_tmp2_ = _tmp1_;
		_tmp3_ = _tmp2_;
		_tmp0_ = _tmp3_ == NULL;
		_signal_type_unref_vapi0 (_tmp3_);
	}
	if (_tmp0_) {
		result = (gint64) -1;
		return result;
	}
	_tmp4_ = dino_plugins_omemo_bundle_get_identity_key (bundle);
	_tmp5_ = _tmp4_;
	_tmp6_ = _tmp5_;
	_tmp8_ = ec_public_key_serialize_ (_tmp6_, &_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp9__length1 = _tmp7_;
	_tmp10_ = g_base64_encode (_tmp9_, (gint) _tmp7_);
	_tmp11_ = _tmp10_;
	_tmp9_ = (g_free (_tmp9_), NULL);
	_signal_type_unref_vapi0 (_tmp6_);
	identity_key = _tmp11_;
	_tmp12_ = dino_plugins_omemo_database_identity_meta_table_with_address (self, (gint) identity_id, address_name);
	_tmp13_ = _tmp12_;
	_tmp14_ = self->device_id;
	_tmp15_ = qlite_query_builder_with (_tmp13_, G_TYPE_INT, NULL, NULL, _tmp14_, "=", (gpointer) ((gintptr) device_id));
	_tmp16_ = _tmp15_;
	_tmp17_ = qlite_query_builder_single (_tmp16_);
	_tmp18_ = _tmp17_;
	_tmp19_ = qlite_query_builder_row (_tmp18_);
	_tmp20_ = _tmp19_;
	_qlite_statement_builder_unref0 (_tmp18_);
	_qlite_statement_builder_unref0 (_tmp16_);
	_qlite_statement_builder_unref0 (_tmp13_);
	row = _tmp20_;
	_tmp23_ = row;
	if (qlite_row_option_is_present (_tmp23_)) {
		QliteRowOption* _tmp24_;
		QliteColumn* _tmp25_;
		gpointer _tmp26_;
		gchar* _tmp27_;
		_tmp24_ = row;
		_tmp25_ = self->identity_key_public_base64;
		_tmp26_ = qlite_row_option_get (_tmp24_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp25_, NULL);
		_tmp27_ = (gchar*) _tmp26_;
		_tmp22_ = _tmp27_ != NULL;
		_g_free0 (_tmp27_);
	} else {
		_tmp22_ = FALSE;
	}
	if (_tmp22_) {
		QliteRowOption* _tmp28_;
		QliteColumn* _tmp29_;
		gpointer _tmp30_;
		gchar* _tmp31_;
		const gchar* _tmp32_;
		_tmp28_ = row;
		_tmp29_ = self->identity_key_public_base64;
		_tmp30_ = qlite_row_option_get (_tmp28_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp29_, NULL);
		_tmp31_ = (gchar*) _tmp30_;
		_tmp32_ = identity_key;
		_tmp21_ = g_strcmp0 (_tmp31_, _tmp32_) != 0;
		_g_free0 (_tmp31_);
	} else {
		_tmp21_ = FALSE;
	}
	if (_tmp21_) {
		g_critical ("database.vala:58: Tried to change the identity key for a known device " \
"id. Likely an attack.");
		result = (gint64) -1;
		_qlite_row_option_unref0 (row);
		_g_free0 (identity_key);
		return result;
	}
	_tmp33_ = qlite_table_upsert ((QliteTable*) self);
	_tmp34_ = _tmp33_;
	_tmp35_ = self->identity_id;
	_tmp36_ = qlite_upsert_builder_value (_tmp34_, G_TYPE_INT, NULL, NULL, _tmp35_, (gpointer) ((gintptr) identity_id), TRUE);
	_tmp37_ = _tmp36_;
	_tmp38_ = self->address_name;
	_tmp39_ = qlite_upsert_builder_value (_tmp37_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp38_, address_name, TRUE);
	_tmp40_ = _tmp39_;
	_tmp41_ = self->device_id;
	_tmp42_ = qlite_upsert_builder_value (_tmp40_, G_TYPE_INT, NULL, NULL, _tmp41_, (gpointer) ((gintptr) device_id), TRUE);
	_tmp43_ = _tmp42_;
	_tmp44_ = self->identity_key_public_base64;
	_tmp45_ = identity_key;
	_tmp46_ = qlite_upsert_builder_value (_tmp43_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp44_, _tmp45_, FALSE);
	_tmp47_ = _tmp46_;
	_tmp48_ = self->trust_level;
	_tmp49_ = qlite_upsert_builder_value (_tmp47_, G_TYPE_INT, NULL, NULL, _tmp48_, (gpointer) ((gintptr) trust), FALSE);
	_tmp50_ = _tmp49_;
	_tmp51_ = qlite_upsert_builder_perform (_tmp50_);
	_qlite_statement_builder_unref0 (_tmp50_);
	_qlite_statement_builder_unref0 (_tmp47_);
	_qlite_statement_builder_unref0 (_tmp43_);
	_qlite_statement_builder_unref0 (_tmp40_);
	_qlite_statement_builder_unref0 (_tmp37_);
	_qlite_statement_builder_unref0 (_tmp34_);
	result = _tmp51_;
	_qlite_row_option_unref0 (row);
	_g_free0 (identity_key);
	return result;
}

gint64
dino_plugins_omemo_database_identity_meta_table_insert_device_session (DinoPluginsOmemoDatabaseIdentityMetaTable* self,
                                                                       gint32 identity_id,
                                                                       const gchar* address_name,
                                                                       gint device_id,
                                                                       const gchar* identity_key,
                                                                       DinoPluginsOmemoTrustLevel trust)
{
	QliteRowOption* row = NULL;
	QliteQueryBuilder* _tmp0_;
	QliteQueryBuilder* _tmp1_;
	QliteColumn* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	QliteQueryBuilder* _tmp4_;
	QliteQueryBuilder* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	QliteRowOption* _tmp7_;
	QliteRowOption* _tmp8_;
	gboolean _tmp9_ = FALSE;
	gboolean _tmp10_ = FALSE;
	QliteRowOption* _tmp11_;
	QliteUpsertBuilder* _tmp20_;
	QliteUpsertBuilder* _tmp21_;
	QliteColumn* _tmp22_;
	QliteUpsertBuilder* _tmp23_;
	QliteUpsertBuilder* _tmp24_;
	QliteColumn* _tmp25_;
	QliteUpsertBuilder* _tmp26_;
	QliteUpsertBuilder* _tmp27_;
	QliteColumn* _tmp28_;
	QliteUpsertBuilder* _tmp29_;
	QliteUpsertBuilder* _tmp30_;
	QliteColumn* _tmp31_;
	QliteUpsertBuilder* _tmp32_;
	QliteUpsertBuilder* _tmp33_;
	QliteColumn* _tmp34_;
	QliteUpsertBuilder* _tmp35_;
	QliteUpsertBuilder* _tmp36_;
	gint64 _tmp37_;
	gint64 result;
	g_return_val_if_fail (self != NULL, -1LL);
	g_return_val_if_fail (address_name != NULL, -1LL);
	g_return_val_if_fail (identity_key != NULL, -1LL);
	_tmp0_ = dino_plugins_omemo_database_identity_meta_table_with_address (self, (gint) identity_id, address_name);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->device_id;
	_tmp3_ = qlite_query_builder_with (_tmp1_, G_TYPE_INT, NULL, NULL, _tmp2_, "=", (gpointer) ((gintptr) device_id));
	_tmp4_ = _tmp3_;
	_tmp5_ = qlite_query_builder_single (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = qlite_query_builder_row (_tmp6_);
	_tmp8_ = _tmp7_;
	_qlite_statement_builder_unref0 (_tmp6_);
	_qlite_statement_builder_unref0 (_tmp4_);
	_qlite_statement_builder_unref0 (_tmp1_);
	row = _tmp8_;
	_tmp11_ = row;
	if (qlite_row_option_is_present (_tmp11_)) {
		QliteRowOption* _tmp12_;
		QliteColumn* _tmp13_;
		gpointer _tmp14_;
		gchar* _tmp15_;
		_tmp12_ = row;
		_tmp13_ = self->identity_key_public_base64;
		_tmp14_ = qlite_row_option_get (_tmp12_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp13_, NULL);
		_tmp15_ = (gchar*) _tmp14_;
		_tmp10_ = _tmp15_ != NULL;
		_g_free0 (_tmp15_);
	} else {
		_tmp10_ = FALSE;
	}
	if (_tmp10_) {
		QliteRowOption* _tmp16_;
		QliteColumn* _tmp17_;
		gpointer _tmp18_;
		gchar* _tmp19_;
		_tmp16_ = row;
		_tmp17_ = self->identity_key_public_base64;
		_tmp18_ = qlite_row_option_get (_tmp16_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp17_, NULL);
		_tmp19_ = (gchar*) _tmp18_;
		_tmp9_ = g_strcmp0 (_tmp19_, identity_key) != 0;
		_g_free0 (_tmp19_);
	} else {
		_tmp9_ = FALSE;
	}
	if (_tmp9_) {
		g_critical ("database.vala:72: Tried to change the identity key for a known device " \
"id. Likely an attack.");
		result = (gint64) -1;
		_qlite_row_option_unref0 (row);
		return result;
	}
	_tmp20_ = qlite_table_upsert ((QliteTable*) self);
	_tmp21_ = _tmp20_;
	_tmp22_ = self->identity_id;
	_tmp23_ = qlite_upsert_builder_value (_tmp21_, G_TYPE_INT, NULL, NULL, _tmp22_, (gpointer) ((gintptr) identity_id), TRUE);
	_tmp24_ = _tmp23_;
	_tmp25_ = self->address_name;
	_tmp26_ = qlite_upsert_builder_value (_tmp24_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp25_, address_name, TRUE);
	_tmp27_ = _tmp26_;
	_tmp28_ = self->device_id;
	_tmp29_ = qlite_upsert_builder_value (_tmp27_, G_TYPE_INT, NULL, NULL, _tmp28_, (gpointer) ((gintptr) device_id), TRUE);
	_tmp30_ = _tmp29_;
	_tmp31_ = self->identity_key_public_base64;
	_tmp32_ = qlite_upsert_builder_value (_tmp30_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp31_, identity_key, FALSE);
	_tmp33_ = _tmp32_;
	_tmp34_ = self->trust_level;
	_tmp35_ = qlite_upsert_builder_value (_tmp33_, G_TYPE_INT, NULL, NULL, _tmp34_, (gpointer) ((gintptr) trust), FALSE);
	_tmp36_ = _tmp35_;
	_tmp37_ = qlite_upsert_builder_perform (_tmp36_);
	_qlite_statement_builder_unref0 (_tmp36_);
	_qlite_statement_builder_unref0 (_tmp33_);
	_qlite_statement_builder_unref0 (_tmp30_);
	_qlite_statement_builder_unref0 (_tmp27_);
	_qlite_statement_builder_unref0 (_tmp24_);
	_qlite_statement_builder_unref0 (_tmp21_);
	result = _tmp37_;
	_qlite_row_option_unref0 (row);
	return result;
}

void
dino_plugins_omemo_database_identity_meta_table_update_last_message_untrusted (DinoPluginsOmemoDatabaseIdentityMetaTable* self,
                                                                               gint identity_id,
                                                                               gint device_id,
                                                                               GDateTime* time)
{
	QliteUpdateBuilder* stmt = NULL;
	QliteUpdateBuilder* _tmp0_;
	QliteUpdateBuilder* _tmp1_;
	QliteColumn* _tmp2_;
	QliteUpdateBuilder* _tmp3_;
	QliteUpdateBuilder* _tmp4_;
	QliteColumn* _tmp5_;
	QliteUpdateBuilder* _tmp6_;
	QliteUpdateBuilder* _tmp7_;
	QliteUpdateBuilder* _tmp16_;
	g_return_if_fail (self != NULL);
	_tmp0_ = qlite_table_update ((QliteTable*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->identity_id;
	_tmp3_ = qlite_update_builder_with (_tmp1_, G_TYPE_INT, NULL, NULL, _tmp2_, "=", (gpointer) ((gintptr) identity_id));
	_tmp4_ = _tmp3_;
	_tmp5_ = self->device_id;
	_tmp6_ = qlite_update_builder_with (_tmp4_, G_TYPE_INT, NULL, NULL, _tmp5_, "=", (gpointer) ((gintptr) device_id));
	_tmp7_ = _tmp6_;
	_qlite_statement_builder_unref0 (_tmp4_);
	_qlite_statement_builder_unref0 (_tmp1_);
	stmt = _tmp7_;
	if (time != NULL) {
		QliteUpdateBuilder* _tmp8_;
		QliteColumn* _tmp9_;
		QliteUpdateBuilder* _tmp10_;
		QliteUpdateBuilder* _tmp11_;
		_tmp8_ = stmt;
		_tmp9_ = self->last_message_untrusted;
		_tmp10_ = qlite_update_builder_set (_tmp8_, G_TYPE_LONG, NULL, NULL, _tmp9_, (gpointer) ((gintptr) g_date_time_to_unix (time)));
		_tmp11_ = _tmp10_;
		_qlite_statement_builder_unref0 (_tmp11_);
	} else {
		QliteUpdateBuilder* _tmp12_;
		QliteColumn* _tmp13_;
		QliteUpdateBuilder* _tmp14_;
		QliteUpdateBuilder* _tmp15_;
		_tmp12_ = stmt;
		_tmp13_ = self->last_message_untrusted;
		_tmp14_ = qlite_update_builder_set_null (_tmp12_, G_TYPE_LONG, NULL, NULL, _tmp13_);
		_tmp15_ = _tmp14_;
		_qlite_statement_builder_unref0 (_tmp15_);
	}
	_tmp16_ = stmt;
	qlite_update_builder_perform (_tmp16_);
	_qlite_statement_builder_unref0 (stmt);
}

void
dino_plugins_omemo_database_identity_meta_table_update_last_message_undecryptable (DinoPluginsOmemoDatabaseIdentityMetaTable* self,
                                                                                   gint identity_id,
                                                                                   gint device_id,
                                                                                   GDateTime* time)
{
	QliteUpdateBuilder* stmt = NULL;
	QliteUpdateBuilder* _tmp0_;
	QliteUpdateBuilder* _tmp1_;
	QliteColumn* _tmp2_;
	QliteUpdateBuilder* _tmp3_;
	QliteUpdateBuilder* _tmp4_;
	QliteColumn* _tmp5_;
	QliteUpdateBuilder* _tmp6_;
	QliteUpdateBuilder* _tmp7_;
	QliteUpdateBuilder* _tmp16_;
	g_return_if_fail (self != NULL);
	_tmp0_ = qlite_table_update ((QliteTable*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->identity_id;
	_tmp3_ = qlite_update_builder_with (_tmp1_, G_TYPE_INT, NULL, NULL, _tmp2_, "=", (gpointer) ((gintptr) identity_id));
	_tmp4_ = _tmp3_;
	_tmp5_ = self->device_id;
	_tmp6_ = qlite_update_builder_with (_tmp4_, G_TYPE_INT, NULL, NULL, _tmp5_, "=", (gpointer) ((gintptr) device_id));
	_tmp7_ = _tmp6_;
	_qlite_statement_builder_unref0 (_tmp4_);
	_qlite_statement_builder_unref0 (_tmp1_);
	stmt = _tmp7_;
	if (time != NULL) {
		QliteUpdateBuilder* _tmp8_;
		QliteColumn* _tmp9_;
		QliteUpdateBuilder* _tmp10_;
		QliteUpdateBuilder* _tmp11_;
		_tmp8_ = stmt;
		_tmp9_ = self->last_message_undecryptable;
		_tmp10_ = qlite_update_builder_set (_tmp8_, G_TYPE_LONG, NULL, NULL, _tmp9_, (gpointer) ((gintptr) g_date_time_to_unix (time)));
		_tmp11_ = _tmp10_;
		_qlite_statement_builder_unref0 (_tmp11_);
	} else {
		QliteUpdateBuilder* _tmp12_;
		QliteColumn* _tmp13_;
		QliteUpdateBuilder* _tmp14_;
		QliteUpdateBuilder* _tmp15_;
		_tmp12_ = stmt;
		_tmp13_ = self->last_message_undecryptable;
		_tmp14_ = qlite_update_builder_set_null (_tmp12_, G_TYPE_LONG, NULL, NULL, _tmp13_);
		_tmp15_ = _tmp14_;
		_qlite_statement_builder_unref0 (_tmp15_);
	}
	_tmp16_ = stmt;
	qlite_update_builder_perform (_tmp16_);
	_qlite_statement_builder_unref0 (stmt);
}

QliteQueryBuilder*
dino_plugins_omemo_database_identity_meta_table_get_trusted_devices (DinoPluginsOmemoDatabaseIdentityMetaTable* self,
                                                                     gint identity_id,
                                                                     const gchar* address_name)
{
	QliteQueryBuilder* _tmp0_;
	QliteQueryBuilder* _tmp1_;
	QliteColumn* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	QliteQueryBuilder* _tmp4_;
	QliteColumn* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	QliteQueryBuilder* _tmp7_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (address_name != NULL, NULL);
	_tmp0_ = dino_plugins_omemo_database_identity_meta_table_with_address (self, identity_id, address_name);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->trust_level;
	_tmp3_ = qlite_query_builder_with (_tmp1_, G_TYPE_INT, NULL, NULL, _tmp2_, "!=", (gpointer) ((gintptr) DINO_PLUGINS_OMEMO_TRUST_LEVEL_UNTRUSTED));
	_tmp4_ = _tmp3_;
	_tmp5_ = self->now_active;
	_tmp6_ = qlite_query_builder_with (_tmp4_, G_TYPE_BOOLEAN, NULL, NULL, _tmp5_, "=", (gpointer) ((gintptr) TRUE));
	_tmp7_ = _tmp6_;
	_qlite_statement_builder_unref0 (_tmp4_);
	_qlite_statement_builder_unref0 (_tmp1_);
	result = _tmp7_;
	return result;
}

QliteQueryBuilder*
dino_plugins_omemo_database_identity_meta_table_get_known_devices (DinoPluginsOmemoDatabaseIdentityMetaTable* self,
                                                                   gint identity_id,
                                                                   const gchar* address_name)
{
	QliteQueryBuilder* _tmp0_;
	QliteQueryBuilder* _tmp1_;
	QliteColumn* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	QliteQueryBuilder* _tmp4_;
	QliteColumn* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	QliteQueryBuilder* _tmp7_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (address_name != NULL, NULL);
	_tmp0_ = dino_plugins_omemo_database_identity_meta_table_with_address (self, identity_id, address_name);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->trust_level;
	_tmp3_ = qlite_query_builder_with (_tmp1_, G_TYPE_INT, NULL, NULL, _tmp2_, "!=", (gpointer) ((gintptr) DINO_PLUGINS_OMEMO_TRUST_LEVEL_UNKNOWN));
	_tmp4_ = _tmp3_;
	_tmp5_ = self->identity_key_public_base64;
	_tmp6_ = qlite_query_builder_without_null (_tmp4_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp5_);
	_tmp7_ = _tmp6_;
	_qlite_statement_builder_unref0 (_tmp4_);
	_qlite_statement_builder_unref0 (_tmp1_);
	result = _tmp7_;
	return result;
}

QliteQueryBuilder*
dino_plugins_omemo_database_identity_meta_table_get_unknown_devices (DinoPluginsOmemoDatabaseIdentityMetaTable* self,
                                                                     gint identity_id,
                                                                     const gchar* address_name)
{
	QliteQueryBuilder* _tmp0_;
	QliteQueryBuilder* _tmp1_;
	QliteColumn* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	QliteQueryBuilder* _tmp4_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (address_name != NULL, NULL);
	_tmp0_ = dino_plugins_omemo_database_identity_meta_table_with_address (self, identity_id, address_name);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->identity_key_public_base64;
	_tmp3_ = qlite_query_builder_with_null (_tmp1_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp2_);
	_tmp4_ = _tmp3_;
	_qlite_statement_builder_unref0 (_tmp1_);
	result = _tmp4_;
	return result;
}

QliteQueryBuilder*
dino_plugins_omemo_database_identity_meta_table_get_new_devices (DinoPluginsOmemoDatabaseIdentityMetaTable* self,
                                                                 gint identity_id,
                                                                 const gchar* address_name)
{
	QliteQueryBuilder* _tmp0_;
	QliteQueryBuilder* _tmp1_;
	QliteColumn* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	QliteQueryBuilder* _tmp4_;
	QliteColumn* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	QliteQueryBuilder* _tmp7_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (address_name != NULL, NULL);
	_tmp0_ = dino_plugins_omemo_database_identity_meta_table_with_address (self, identity_id, address_name);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->trust_level;
	_tmp3_ = qlite_query_builder_with (_tmp1_, G_TYPE_INT, NULL, NULL, _tmp2_, "=", (gpointer) ((gintptr) DINO_PLUGINS_OMEMO_TRUST_LEVEL_UNKNOWN));
	_tmp4_ = _tmp3_;
	_tmp5_ = self->identity_key_public_base64;
	_tmp6_ = qlite_query_builder_without_null (_tmp4_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp5_);
	_tmp7_ = _tmp6_;
	_qlite_statement_builder_unref0 (_tmp4_);
	_qlite_statement_builder_unref0 (_tmp1_);
	result = _tmp7_;
	return result;
}

static gpointer
_qlite_row_ref0 (gpointer self)
{
	return self ? qlite_row_ref (self) : NULL;
}

QliteRow*
dino_plugins_omemo_database_identity_meta_table_get_device (DinoPluginsOmemoDatabaseIdentityMetaTable* self,
                                                            gint identity_id,
                                                            const gchar* address_name,
                                                            gint device_id)
{
	QliteQueryBuilder* _tmp0_;
	QliteQueryBuilder* _tmp1_;
	QliteColumn* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	QliteQueryBuilder* _tmp4_;
	QliteQueryBuilder* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	QliteRowOption* _tmp7_;
	QliteRowOption* _tmp8_;
	QliteRow* _tmp9_;
	QliteRow* _tmp10_;
	QliteRow* _tmp11_;
	QliteRow* _tmp12_;
	QliteRow* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (address_name != NULL, NULL);
	_tmp0_ = dino_plugins_omemo_database_identity_meta_table_with_address (self, identity_id, address_name);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->device_id;
	_tmp3_ = qlite_query_builder_with (_tmp1_, G_TYPE_INT, NULL, NULL, _tmp2_, "=", (gpointer) ((gintptr) device_id));
	_tmp4_ = _tmp3_;
	_tmp5_ = qlite_query_builder_single (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = qlite_query_builder_row (_tmp6_);
	_tmp8_ = _tmp7_;
	_tmp9_ = qlite_row_option_get_inner (_tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = _qlite_row_ref0 (_tmp10_);
	_tmp12_ = _tmp11_;
	_qlite_row_option_unref0 (_tmp8_);
	_qlite_statement_builder_unref0 (_tmp6_);
	_qlite_statement_builder_unref0 (_tmp4_);
	_qlite_statement_builder_unref0 (_tmp1_);
	result = _tmp12_;
	return result;
}

static void
dino_plugins_omemo_database_identity_meta_table_class_init (DinoPluginsOmemoDatabaseIdentityMetaTableClass * klass,
                                                            gpointer klass_data)
{
	dino_plugins_omemo_database_identity_meta_table_parent_class = g_type_class_peek_parent (klass);
	((QliteTableClass *) klass)->finalize = dino_plugins_omemo_database_identity_meta_table_finalize;
}

static void
dino_plugins_omemo_database_identity_meta_table_instance_init (DinoPluginsOmemoDatabaseIdentityMetaTable * self,
                                                               gpointer klass)
{
	gchar* _tmp0_;
	QliteColumnInteger* _tmp1_ = NULL;
	QliteColumnText* _tmp2_ = NULL;
	QliteColumnInteger* _tmp3_ = NULL;
	QliteColumnText* _tmp4_;
	gchar* _tmp5_;
	QliteColumnBoolInt* _tmp6_ = NULL;
	gchar* _tmp7_;
	QliteColumnInteger* _tmp8_ = NULL;
	gchar* _tmp9_;
	QliteColumnBoolInt* _tmp10_ = NULL;
	QliteColumnLong* _tmp11_;
	QliteColumnLong* _tmp12_ = NULL;
	QliteColumnLong* _tmp13_ = NULL;
	_tmp0_ = g_strdup ("-1");
	_tmp1_ = qlite_column_integer_new ("identity_id");
	qlite_column_set_not_null ((QliteColumn*) _tmp1_, TRUE);
	qlite_column_set_min_version ((QliteColumn*) _tmp1_, (glong) 2);
	qlite_column_set_default ((QliteColumn*) _tmp1_, _tmp0_);
	_g_free0 (_tmp0_);
	self->identity_id = (QliteColumn*) _tmp1_;
	_tmp2_ = qlite_column_text_new ("address_name");
	qlite_column_set_not_null ((QliteColumn*) _tmp2_, TRUE);
	self->address_name = (QliteColumn*) _tmp2_;
	_tmp3_ = qlite_column_integer_new ("device_id");
	qlite_column_set_not_null ((QliteColumn*) _tmp3_, TRUE);
	self->device_id = (QliteColumn*) _tmp3_;
	_tmp4_ = qlite_column_text_new ("identity_key_public_base64");
	self->identity_key_public_base64 = (QliteColumn*) _tmp4_;
	_tmp5_ = g_strdup ("0");
	_tmp6_ = qlite_column_bool_int_new ("trusted_identity");
	qlite_column_set_default ((QliteColumn*) _tmp6_, _tmp5_);
	_g_free0 (_tmp5_);
	qlite_column_set_max_version ((QliteColumn*) _tmp6_, (glong) 1);
	self->trusted_identity = (QliteColumn*) _tmp6_;
	_tmp7_ = dino_plugins_omemo_trust_level_to_string (DINO_PLUGINS_OMEMO_TRUST_LEVEL_UNKNOWN);
	_tmp8_ = qlite_column_integer_new ("trust_level");
	qlite_column_set_default ((QliteColumn*) _tmp8_, _tmp7_);
	_g_free0 (_tmp7_);
	qlite_column_set_min_version ((QliteColumn*) _tmp8_, (glong) 2);
	self->trust_level = (QliteColumn*) _tmp8_;
	_tmp9_ = g_strdup ("1");
	_tmp10_ = qlite_column_bool_int_new ("now_active");
	qlite_column_set_default ((QliteColumn*) _tmp10_, _tmp9_);
	_g_free0 (_tmp9_);
	self->now_active = (QliteColumn*) _tmp10_;
	_tmp11_ = qlite_column_long_new ("last_active");
	self->last_active = (QliteColumn*) _tmp11_;
	_tmp12_ = qlite_column_long_new ("last_message_untrusted");
	qlite_column_set_min_version ((QliteColumn*) _tmp12_, (glong) 5);
	self->last_message_untrusted = (QliteColumn*) _tmp12_;
	_tmp13_ = qlite_column_long_new ("last_message_undecryptable");
	qlite_column_set_min_version ((QliteColumn*) _tmp13_, (glong) 5);
	self->last_message_undecryptable = (QliteColumn*) _tmp13_;
}

static void
dino_plugins_omemo_database_identity_meta_table_finalize (QliteTable * obj)
{
	DinoPluginsOmemoDatabaseIdentityMetaTable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_DATABASE_TYPE_IDENTITY_META_TABLE, DinoPluginsOmemoDatabaseIdentityMetaTable);
	_qlite_column_unref0 (self->identity_id);
	_qlite_column_unref0 (self->address_name);
	_qlite_column_unref0 (self->device_id);
	_qlite_column_unref0 (self->identity_key_public_base64);
	_qlite_column_unref0 (self->trusted_identity);
	_qlite_column_unref0 (self->trust_level);
	_qlite_column_unref0 (self->now_active);
	_qlite_column_unref0 (self->last_active);
	_qlite_column_unref0 (self->last_message_untrusted);
	_qlite_column_unref0 (self->last_message_undecryptable);
	QLITE_TABLE_CLASS (dino_plugins_omemo_database_identity_meta_table_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_database_identity_meta_table_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoDatabaseIdentityMetaTableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_database_identity_meta_table_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoDatabaseIdentityMetaTable), 0, (GInstanceInitFunc) dino_plugins_omemo_database_identity_meta_table_instance_init, NULL };
	GType dino_plugins_omemo_database_identity_meta_table_type_id;
	dino_plugins_omemo_database_identity_meta_table_type_id = g_type_register_static (QLITE_TYPE_TABLE, "DinoPluginsOmemoDatabaseIdentityMetaTable", &g_define_type_info, 0);
	return dino_plugins_omemo_database_identity_meta_table_type_id;
}

GType
dino_plugins_omemo_database_identity_meta_table_get_type (void)
{
	static volatile gsize dino_plugins_omemo_database_identity_meta_table_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_database_identity_meta_table_type_id__once)) {
		GType dino_plugins_omemo_database_identity_meta_table_type_id;
		dino_plugins_omemo_database_identity_meta_table_type_id = dino_plugins_omemo_database_identity_meta_table_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_database_identity_meta_table_type_id__once, dino_plugins_omemo_database_identity_meta_table_type_id);
	}
	return dino_plugins_omemo_database_identity_meta_table_type_id__once;
}

DinoPluginsOmemoDatabaseTrustTable*
dino_plugins_omemo_database_trust_table_construct (GType object_type,
                                                   DinoPluginsOmemoDatabase* db)
{
	DinoPluginsOmemoDatabaseTrustTable* self = NULL;
	QliteColumn* _tmp0_;
	QliteColumn* _tmp1_;
	QliteColumn* _tmp2_;
	QliteColumn* _tmp3_;
	QliteColumn* _tmp4_;
	QliteColumn* _tmp5_;
	QliteColumn** _tmp6_;
	QliteColumn** _tmp7_;
	gint _tmp7__length1;
	QliteColumn* _tmp8_;
	QliteColumn* _tmp9_;
	QliteColumn* _tmp10_;
	QliteColumn* _tmp11_;
	QliteColumn** _tmp12_;
	QliteColumn** _tmp13_;
	gint _tmp13__length1;
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoPluginsOmemoDatabaseTrustTable*) qlite_table_construct (object_type, (QliteDatabase*) db, "trust");
	_tmp0_ = self->identity_id;
	_tmp1_ = _qlite_column_ref0 (_tmp0_);
	_tmp2_ = self->address_name;
	_tmp3_ = _qlite_column_ref0 (_tmp2_);
	_tmp4_ = self->blind_trust;
	_tmp5_ = _qlite_column_ref0 (_tmp4_);
	_tmp6_ = g_new0 (QliteColumn*, 3 + 1);
	_tmp6_[0] = _tmp1_;
	_tmp6_[1] = _tmp3_;
	_tmp6_[2] = _tmp5_;
	_tmp7_ = _tmp6_;
	_tmp7__length1 = 3;
	qlite_table_init ((QliteTable*) self, _tmp7_, (gint) 3, "");
	_tmp7_ = (_vala_array_free (_tmp7_, _tmp7__length1, (GDestroyNotify) qlite_column_unref), NULL);
	_tmp8_ = self->identity_id;
	_tmp9_ = _qlite_column_ref0 (_tmp8_);
	_tmp10_ = self->address_name;
	_tmp11_ = _qlite_column_ref0 (_tmp10_);
	_tmp12_ = g_new0 (QliteColumn*, 2 + 1);
	_tmp12_[0] = _tmp9_;
	_tmp12_[1] = _tmp11_;
	_tmp13_ = _tmp12_;
	_tmp13__length1 = 2;
	qlite_table_index ((QliteTable*) self, "trust_idx", _tmp13_, (gint) 2, TRUE);
	_tmp13_ = (_vala_array_free (_tmp13_, _tmp13__length1, (GDestroyNotify) qlite_column_unref), NULL);
	return self;
}

DinoPluginsOmemoDatabaseTrustTable*
dino_plugins_omemo_database_trust_table_new (DinoPluginsOmemoDatabase* db)
{
	return dino_plugins_omemo_database_trust_table_construct (DINO_PLUGINS_OMEMO_DATABASE_TYPE_TRUST_TABLE, db);
}

gboolean
dino_plugins_omemo_database_trust_table_get_blind_trust (DinoPluginsOmemoDatabaseTrustTable* self,
                                                         gint32 identity_id,
                                                         const gchar* address_name,
                                                         gboolean def)
{
	QliteRowOption* row = NULL;
	QliteQueryBuilder* _tmp0_;
	QliteQueryBuilder* _tmp1_;
	QliteColumn* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	QliteQueryBuilder* _tmp4_;
	QliteColumn* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	QliteQueryBuilder* _tmp7_;
	QliteQueryBuilder* _tmp8_;
	QliteQueryBuilder* _tmp9_;
	QliteRowOption* _tmp10_;
	QliteRowOption* _tmp11_;
	QliteRowOption* _tmp12_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (address_name != NULL, FALSE);
	_tmp0_ = qlite_table_select ((QliteTable*) self, NULL, (gint) 0);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->identity_id;
	_tmp3_ = qlite_query_builder_with (_tmp1_, G_TYPE_INT, NULL, NULL, _tmp2_, "=", (gpointer) ((gintptr) identity_id));
	_tmp4_ = _tmp3_;
	_tmp5_ = self->address_name;
	_tmp6_ = qlite_query_builder_with (_tmp4_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp5_, "=", address_name);
	_tmp7_ = _tmp6_;
	_tmp8_ = qlite_query_builder_single (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = qlite_query_builder_row (_tmp9_);
	_tmp11_ = _tmp10_;
	_qlite_statement_builder_unref0 (_tmp9_);
	_qlite_statement_builder_unref0 (_tmp7_);
	_qlite_statement_builder_unref0 (_tmp4_);
	_qlite_statement_builder_unref0 (_tmp1_);
	row = _tmp11_;
	_tmp12_ = row;
	if (qlite_row_option_is_present (_tmp12_)) {
		QliteRowOption* _tmp13_;
		QliteColumn* _tmp14_;
		gpointer _tmp15_;
		_tmp13_ = row;
		_tmp14_ = self->blind_trust;
		_tmp15_ = qlite_row_option_get (_tmp13_, G_TYPE_BOOLEAN, NULL, NULL, _tmp14_, NULL);
		result = (gboolean) ((gintptr) _tmp15_);
		_qlite_row_option_unref0 (row);
		return result;
	}
	result = def;
	_qlite_row_option_unref0 (row);
	return result;
}

static void
dino_plugins_omemo_database_trust_table_class_init (DinoPluginsOmemoDatabaseTrustTableClass * klass,
                                                    gpointer klass_data)
{
	dino_plugins_omemo_database_trust_table_parent_class = g_type_class_peek_parent (klass);
	((QliteTableClass *) klass)->finalize = dino_plugins_omemo_database_trust_table_finalize;
}

static void
dino_plugins_omemo_database_trust_table_instance_init (DinoPluginsOmemoDatabaseTrustTable * self,
                                                       gpointer klass)
{
	QliteColumnInteger* _tmp0_ = NULL;
	QliteColumnText* _tmp1_;
	gchar* _tmp2_;
	QliteColumnBoolInt* _tmp3_ = NULL;
	_tmp0_ = qlite_column_integer_new ("identity_id");
	qlite_column_set_not_null ((QliteColumn*) _tmp0_, TRUE);
	self->identity_id = (QliteColumn*) _tmp0_;
	_tmp1_ = qlite_column_text_new ("address_name");
	self->address_name = (QliteColumn*) _tmp1_;
	_tmp2_ = g_strdup ("1");
	_tmp3_ = qlite_column_bool_int_new ("blind_trust");
	qlite_column_set_default ((QliteColumn*) _tmp3_, _tmp2_);
	_g_free0 (_tmp2_);
	self->blind_trust = (QliteColumn*) _tmp3_;
}

static void
dino_plugins_omemo_database_trust_table_finalize (QliteTable * obj)
{
	DinoPluginsOmemoDatabaseTrustTable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_DATABASE_TYPE_TRUST_TABLE, DinoPluginsOmemoDatabaseTrustTable);
	_qlite_column_unref0 (self->identity_id);
	_qlite_column_unref0 (self->address_name);
	_qlite_column_unref0 (self->blind_trust);
	QLITE_TABLE_CLASS (dino_plugins_omemo_database_trust_table_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_database_trust_table_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoDatabaseTrustTableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_database_trust_table_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoDatabaseTrustTable), 0, (GInstanceInitFunc) dino_plugins_omemo_database_trust_table_instance_init, NULL };
	GType dino_plugins_omemo_database_trust_table_type_id;
	dino_plugins_omemo_database_trust_table_type_id = g_type_register_static (QLITE_TYPE_TABLE, "DinoPluginsOmemoDatabaseTrustTable", &g_define_type_info, 0);
	return dino_plugins_omemo_database_trust_table_type_id;
}

GType
dino_plugins_omemo_database_trust_table_get_type (void)
{
	static volatile gsize dino_plugins_omemo_database_trust_table_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_database_trust_table_type_id__once)) {
		GType dino_plugins_omemo_database_trust_table_type_id;
		dino_plugins_omemo_database_trust_table_type_id = dino_plugins_omemo_database_trust_table_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_database_trust_table_type_id__once, dino_plugins_omemo_database_trust_table_type_id);
	}
	return dino_plugins_omemo_database_trust_table_type_id__once;
}

DinoPluginsOmemoDatabaseIdentityTable*
dino_plugins_omemo_database_identity_table_construct (GType object_type,
                                                      DinoPluginsOmemoDatabase* db)
{
	DinoPluginsOmemoDatabaseIdentityTable* self = NULL;
	QliteColumn* _tmp0_;
	QliteColumn* _tmp1_;
	QliteColumn* _tmp2_;
	QliteColumn* _tmp3_;
	QliteColumn* _tmp4_;
	QliteColumn* _tmp5_;
	QliteColumn* _tmp6_;
	QliteColumn* _tmp7_;
	QliteColumn* _tmp8_;
	QliteColumn* _tmp9_;
	QliteColumn** _tmp10_;
	QliteColumn** _tmp11_;
	gint _tmp11__length1;
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoPluginsOmemoDatabaseIdentityTable*) qlite_table_construct (object_type, (QliteDatabase*) db, "identity");
	_tmp0_ = self->id;
	_tmp1_ = _qlite_column_ref0 (_tmp0_);
	_tmp2_ = self->account_id;
	_tmp3_ = _qlite_column_ref0 (_tmp2_);
	_tmp4_ = self->device_id;
	_tmp5_ = _qlite_column_ref0 (_tmp4_);
	_tmp6_ = self->identity_key_private_base64;
	_tmp7_ = _qlite_column_ref0 (_tmp6_);
	_tmp8_ = self->identity_key_public_base64;
	_tmp9_ = _qlite_column_ref0 (_tmp8_);
	_tmp10_ = g_new0 (QliteColumn*, 5 + 1);
	_tmp10_[0] = _tmp1_;
	_tmp10_[1] = _tmp3_;
	_tmp10_[2] = _tmp5_;
	_tmp10_[3] = _tmp7_;
	_tmp10_[4] = _tmp9_;
	_tmp11_ = _tmp10_;
	_tmp11__length1 = 5;
	qlite_table_init ((QliteTable*) self, _tmp11_, (gint) 5, "");
	_tmp11_ = (_vala_array_free (_tmp11_, _tmp11__length1, (GDestroyNotify) qlite_column_unref), NULL);
	return self;
}

DinoPluginsOmemoDatabaseIdentityTable*
dino_plugins_omemo_database_identity_table_new (DinoPluginsOmemoDatabase* db)
{
	return dino_plugins_omemo_database_identity_table_construct (DINO_PLUGINS_OMEMO_DATABASE_TYPE_IDENTITY_TABLE, db);
}

gint
dino_plugins_omemo_database_identity_table_get_id (DinoPluginsOmemoDatabaseIdentityTable* self,
                                                   gint account_id)
{
	gint id = 0;
	QliteRow* row = NULL;
	QliteColumn* _tmp0_;
	QliteRowOption* _tmp1_;
	QliteRowOption* _tmp2_;
	QliteRow* _tmp3_;
	QliteRow* _tmp4_;
	QliteRow* _tmp5_;
	QliteRow* _tmp6_;
	QliteRow* _tmp7_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	id = -1;
	_tmp0_ = self->account_id;
	_tmp1_ = qlite_table_row_with ((QliteTable*) self, G_TYPE_INT, NULL, NULL, _tmp0_, (gpointer) ((gintptr) account_id));
	_tmp2_ = _tmp1_;
	_tmp3_ = qlite_row_option_get_inner (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _qlite_row_ref0 (_tmp4_);
	_tmp6_ = _tmp5_;
	_qlite_row_option_unref0 (_tmp2_);
	row = _tmp6_;
	_tmp7_ = row;
	if (_tmp7_ != NULL) {
		QliteRow* _tmp8_;
		QliteColumn* _tmp9_;
		gpointer _tmp10_;
		_tmp8_ = row;
		_tmp9_ = self->id;
		_tmp10_ = qlite_row_get (G_TYPE_CHECK_INSTANCE_CAST (_tmp8_, QLITE_TYPE_ROW, QliteRow), G_TYPE_INT, NULL, NULL, _tmp9_);
		id = (gint) ((gintptr) _tmp10_);
	}
	result = id;
	_qlite_row_unref0 (row);
	return result;
}

static void
dino_plugins_omemo_database_identity_table_class_init (DinoPluginsOmemoDatabaseIdentityTableClass * klass,
                                                       gpointer klass_data)
{
	dino_plugins_omemo_database_identity_table_parent_class = g_type_class_peek_parent (klass);
	((QliteTableClass *) klass)->finalize = dino_plugins_omemo_database_identity_table_finalize;
}

static void
dino_plugins_omemo_database_identity_table_instance_init (DinoPluginsOmemoDatabaseIdentityTable * self,
                                                          gpointer klass)
{
	QliteColumnInteger* _tmp0_ = NULL;
	QliteColumnInteger* _tmp1_ = NULL;
	QliteColumnInteger* _tmp2_ = NULL;
	QliteColumnNonNullText* _tmp3_;
	QliteColumnNonNullText* _tmp4_;
	_tmp0_ = qlite_column_integer_new ("id");
	qlite_column_set_primary_key ((QliteColumn*) _tmp0_, TRUE);
	qlite_column_set_auto_increment ((QliteColumn*) _tmp0_, TRUE);
	self->id = (QliteColumn*) _tmp0_;
	_tmp1_ = qlite_column_integer_new ("account_id");
	qlite_column_set_unique ((QliteColumn*) _tmp1_, TRUE);
	qlite_column_set_not_null ((QliteColumn*) _tmp1_, TRUE);
	self->account_id = (QliteColumn*) _tmp1_;
	_tmp2_ = qlite_column_integer_new ("device_id");
	qlite_column_set_not_null ((QliteColumn*) _tmp2_, TRUE);
	self->device_id = (QliteColumn*) _tmp2_;
	_tmp3_ = qlite_column_non_null_text_new ("identity_key_private_base64");
	self->identity_key_private_base64 = (QliteColumn*) _tmp3_;
	_tmp4_ = qlite_column_non_null_text_new ("identity_key_public_base64");
	self->identity_key_public_base64 = (QliteColumn*) _tmp4_;
}

static void
dino_plugins_omemo_database_identity_table_finalize (QliteTable * obj)
{
	DinoPluginsOmemoDatabaseIdentityTable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_DATABASE_TYPE_IDENTITY_TABLE, DinoPluginsOmemoDatabaseIdentityTable);
	_qlite_column_unref0 (self->id);
	_qlite_column_unref0 (self->account_id);
	_qlite_column_unref0 (self->device_id);
	_qlite_column_unref0 (self->identity_key_private_base64);
	_qlite_column_unref0 (self->identity_key_public_base64);
	QLITE_TABLE_CLASS (dino_plugins_omemo_database_identity_table_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_database_identity_table_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoDatabaseIdentityTableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_database_identity_table_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoDatabaseIdentityTable), 0, (GInstanceInitFunc) dino_plugins_omemo_database_identity_table_instance_init, NULL };
	GType dino_plugins_omemo_database_identity_table_type_id;
	dino_plugins_omemo_database_identity_table_type_id = g_type_register_static (QLITE_TYPE_TABLE, "DinoPluginsOmemoDatabaseIdentityTable", &g_define_type_info, 0);
	return dino_plugins_omemo_database_identity_table_type_id;
}

GType
dino_plugins_omemo_database_identity_table_get_type (void)
{
	static volatile gsize dino_plugins_omemo_database_identity_table_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_database_identity_table_type_id__once)) {
		GType dino_plugins_omemo_database_identity_table_type_id;
		dino_plugins_omemo_database_identity_table_type_id = dino_plugins_omemo_database_identity_table_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_database_identity_table_type_id__once, dino_plugins_omemo_database_identity_table_type_id);
	}
	return dino_plugins_omemo_database_identity_table_type_id__once;
}

DinoPluginsOmemoDatabaseSignedPreKeyTable*
dino_plugins_omemo_database_signed_pre_key_table_construct (GType object_type,
                                                            DinoPluginsOmemoDatabase* db)
{
	DinoPluginsOmemoDatabaseSignedPreKeyTable* self = NULL;
	QliteColumn* _tmp0_;
	QliteColumn* _tmp1_;
	QliteColumn* _tmp2_;
	QliteColumn* _tmp3_;
	QliteColumn* _tmp4_;
	QliteColumn* _tmp5_;
	QliteColumn** _tmp6_;
	QliteColumn** _tmp7_;
	gint _tmp7__length1;
	QliteColumn* _tmp8_;
	QliteColumn* _tmp9_;
	QliteColumn* _tmp10_;
	QliteColumn* _tmp11_;
	QliteColumn** _tmp12_;
	QliteColumn** _tmp13_;
	gint _tmp13__length1;
	QliteColumn* _tmp14_;
	QliteColumn* _tmp15_;
	QliteColumn* _tmp16_;
	QliteColumn* _tmp17_;
	QliteColumn** _tmp18_;
	QliteColumn** _tmp19_;
	gint _tmp19__length1;
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoPluginsOmemoDatabaseSignedPreKeyTable*) qlite_table_construct (object_type, (QliteDatabase*) db, "signed_pre_key");
	_tmp0_ = self->identity_id;
	_tmp1_ = _qlite_column_ref0 (_tmp0_);
	_tmp2_ = self->signed_pre_key_id;
	_tmp3_ = _qlite_column_ref0 (_tmp2_);
	_tmp4_ = self->record_base64;
	_tmp5_ = _qlite_column_ref0 (_tmp4_);
	_tmp6_ = g_new0 (QliteColumn*, 3 + 1);
	_tmp6_[0] = _tmp1_;
	_tmp6_[1] = _tmp3_;
	_tmp6_[2] = _tmp5_;
	_tmp7_ = _tmp6_;
	_tmp7__length1 = 3;
	qlite_table_init ((QliteTable*) self, _tmp7_, (gint) 3, "");
	_tmp7_ = (_vala_array_free (_tmp7_, _tmp7__length1, (GDestroyNotify) qlite_column_unref), NULL);
	_tmp8_ = self->identity_id;
	_tmp9_ = _qlite_column_ref0 (_tmp8_);
	_tmp10_ = self->signed_pre_key_id;
	_tmp11_ = _qlite_column_ref0 (_tmp10_);
	_tmp12_ = g_new0 (QliteColumn*, 2 + 1);
	_tmp12_[0] = _tmp9_;
	_tmp12_[1] = _tmp11_;
	_tmp13_ = _tmp12_;
	_tmp13__length1 = 2;
	qlite_table_unique ((QliteTable*) self, _tmp13_, (gint) 2, NULL);
	_tmp13_ = (_vala_array_free (_tmp13_, _tmp13__length1, (GDestroyNotify) qlite_column_unref), NULL);
	_tmp14_ = self->identity_id;
	_tmp15_ = _qlite_column_ref0 (_tmp14_);
	_tmp16_ = self->signed_pre_key_id;
	_tmp17_ = _qlite_column_ref0 (_tmp16_);
	_tmp18_ = g_new0 (QliteColumn*, 2 + 1);
	_tmp18_[0] = _tmp15_;
	_tmp18_[1] = _tmp17_;
	_tmp19_ = _tmp18_;
	_tmp19__length1 = 2;
	qlite_table_index ((QliteTable*) self, "signed_pre_key_idx", _tmp19_, (gint) 2, TRUE);
	_tmp19_ = (_vala_array_free (_tmp19_, _tmp19__length1, (GDestroyNotify) qlite_column_unref), NULL);
	return self;
}

DinoPluginsOmemoDatabaseSignedPreKeyTable*
dino_plugins_omemo_database_signed_pre_key_table_new (DinoPluginsOmemoDatabase* db)
{
	return dino_plugins_omemo_database_signed_pre_key_table_construct (DINO_PLUGINS_OMEMO_DATABASE_TYPE_SIGNED_PRE_KEY_TABLE, db);
}

static void
dino_plugins_omemo_database_signed_pre_key_table_class_init (DinoPluginsOmemoDatabaseSignedPreKeyTableClass * klass,
                                                             gpointer klass_data)
{
	dino_plugins_omemo_database_signed_pre_key_table_parent_class = g_type_class_peek_parent (klass);
	((QliteTableClass *) klass)->finalize = dino_plugins_omemo_database_signed_pre_key_table_finalize;
}

static void
dino_plugins_omemo_database_signed_pre_key_table_instance_init (DinoPluginsOmemoDatabaseSignedPreKeyTable * self,
                                                                gpointer klass)
{
	QliteColumnInteger* _tmp0_ = NULL;
	QliteColumnInteger* _tmp1_ = NULL;
	QliteColumnNonNullText* _tmp2_;
	_tmp0_ = qlite_column_integer_new ("identity_id");
	qlite_column_set_not_null ((QliteColumn*) _tmp0_, TRUE);
	self->identity_id = (QliteColumn*) _tmp0_;
	_tmp1_ = qlite_column_integer_new ("signed_pre_key_id");
	qlite_column_set_not_null ((QliteColumn*) _tmp1_, TRUE);
	self->signed_pre_key_id = (QliteColumn*) _tmp1_;
	_tmp2_ = qlite_column_non_null_text_new ("record_base64");
	self->record_base64 = (QliteColumn*) _tmp2_;
}

static void
dino_plugins_omemo_database_signed_pre_key_table_finalize (QliteTable * obj)
{
	DinoPluginsOmemoDatabaseSignedPreKeyTable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_DATABASE_TYPE_SIGNED_PRE_KEY_TABLE, DinoPluginsOmemoDatabaseSignedPreKeyTable);
	_qlite_column_unref0 (self->identity_id);
	_qlite_column_unref0 (self->signed_pre_key_id);
	_qlite_column_unref0 (self->record_base64);
	QLITE_TABLE_CLASS (dino_plugins_omemo_database_signed_pre_key_table_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_database_signed_pre_key_table_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoDatabaseSignedPreKeyTableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_database_signed_pre_key_table_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoDatabaseSignedPreKeyTable), 0, (GInstanceInitFunc) dino_plugins_omemo_database_signed_pre_key_table_instance_init, NULL };
	GType dino_plugins_omemo_database_signed_pre_key_table_type_id;
	dino_plugins_omemo_database_signed_pre_key_table_type_id = g_type_register_static (QLITE_TYPE_TABLE, "DinoPluginsOmemoDatabaseSignedPreKeyTable", &g_define_type_info, 0);
	return dino_plugins_omemo_database_signed_pre_key_table_type_id;
}

GType
dino_plugins_omemo_database_signed_pre_key_table_get_type (void)
{
	static volatile gsize dino_plugins_omemo_database_signed_pre_key_table_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_database_signed_pre_key_table_type_id__once)) {
		GType dino_plugins_omemo_database_signed_pre_key_table_type_id;
		dino_plugins_omemo_database_signed_pre_key_table_type_id = dino_plugins_omemo_database_signed_pre_key_table_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_database_signed_pre_key_table_type_id__once, dino_plugins_omemo_database_signed_pre_key_table_type_id);
	}
	return dino_plugins_omemo_database_signed_pre_key_table_type_id__once;
}

DinoPluginsOmemoDatabasePreKeyTable*
dino_plugins_omemo_database_pre_key_table_construct (GType object_type,
                                                     DinoPluginsOmemoDatabase* db)
{
	DinoPluginsOmemoDatabasePreKeyTable* self = NULL;
	QliteColumn* _tmp0_;
	QliteColumn* _tmp1_;
	QliteColumn* _tmp2_;
	QliteColumn* _tmp3_;
	QliteColumn* _tmp4_;
	QliteColumn* _tmp5_;
	QliteColumn** _tmp6_;
	QliteColumn** _tmp7_;
	gint _tmp7__length1;
	QliteColumn* _tmp8_;
	QliteColumn* _tmp9_;
	QliteColumn* _tmp10_;
	QliteColumn* _tmp11_;
	QliteColumn** _tmp12_;
	QliteColumn** _tmp13_;
	gint _tmp13__length1;
	QliteColumn* _tmp14_;
	QliteColumn* _tmp15_;
	QliteColumn* _tmp16_;
	QliteColumn* _tmp17_;
	QliteColumn** _tmp18_;
	QliteColumn** _tmp19_;
	gint _tmp19__length1;
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoPluginsOmemoDatabasePreKeyTable*) qlite_table_construct (object_type, (QliteDatabase*) db, "pre_key");
	_tmp0_ = self->identity_id;
	_tmp1_ = _qlite_column_ref0 (_tmp0_);
	_tmp2_ = self->pre_key_id;
	_tmp3_ = _qlite_column_ref0 (_tmp2_);
	_tmp4_ = self->record_base64;
	_tmp5_ = _qlite_column_ref0 (_tmp4_);
	_tmp6_ = g_new0 (QliteColumn*, 3 + 1);
	_tmp6_[0] = _tmp1_;
	_tmp6_[1] = _tmp3_;
	_tmp6_[2] = _tmp5_;
	_tmp7_ = _tmp6_;
	_tmp7__length1 = 3;
	qlite_table_init ((QliteTable*) self, _tmp7_, (gint) 3, "");
	_tmp7_ = (_vala_array_free (_tmp7_, _tmp7__length1, (GDestroyNotify) qlite_column_unref), NULL);
	_tmp8_ = self->identity_id;
	_tmp9_ = _qlite_column_ref0 (_tmp8_);
	_tmp10_ = self->pre_key_id;
	_tmp11_ = _qlite_column_ref0 (_tmp10_);
	_tmp12_ = g_new0 (QliteColumn*, 2 + 1);
	_tmp12_[0] = _tmp9_;
	_tmp12_[1] = _tmp11_;
	_tmp13_ = _tmp12_;
	_tmp13__length1 = 2;
	qlite_table_unique ((QliteTable*) self, _tmp13_, (gint) 2, NULL);
	_tmp13_ = (_vala_array_free (_tmp13_, _tmp13__length1, (GDestroyNotify) qlite_column_unref), NULL);
	_tmp14_ = self->identity_id;
	_tmp15_ = _qlite_column_ref0 (_tmp14_);
	_tmp16_ = self->pre_key_id;
	_tmp17_ = _qlite_column_ref0 (_tmp16_);
	_tmp18_ = g_new0 (QliteColumn*, 2 + 1);
	_tmp18_[0] = _tmp15_;
	_tmp18_[1] = _tmp17_;
	_tmp19_ = _tmp18_;
	_tmp19__length1 = 2;
	qlite_table_index ((QliteTable*) self, "pre_key_idx", _tmp19_, (gint) 2, TRUE);
	_tmp19_ = (_vala_array_free (_tmp19_, _tmp19__length1, (GDestroyNotify) qlite_column_unref), NULL);
	return self;
}

DinoPluginsOmemoDatabasePreKeyTable*
dino_plugins_omemo_database_pre_key_table_new (DinoPluginsOmemoDatabase* db)
{
	return dino_plugins_omemo_database_pre_key_table_construct (DINO_PLUGINS_OMEMO_DATABASE_TYPE_PRE_KEY_TABLE, db);
}

static void
dino_plugins_omemo_database_pre_key_table_class_init (DinoPluginsOmemoDatabasePreKeyTableClass * klass,
                                                      gpointer klass_data)
{
	dino_plugins_omemo_database_pre_key_table_parent_class = g_type_class_peek_parent (klass);
	((QliteTableClass *) klass)->finalize = dino_plugins_omemo_database_pre_key_table_finalize;
}

static void
dino_plugins_omemo_database_pre_key_table_instance_init (DinoPluginsOmemoDatabasePreKeyTable * self,
                                                         gpointer klass)
{
	QliteColumnInteger* _tmp0_ = NULL;
	QliteColumnInteger* _tmp1_ = NULL;
	QliteColumnNonNullText* _tmp2_;
	_tmp0_ = qlite_column_integer_new ("identity_id");
	qlite_column_set_not_null ((QliteColumn*) _tmp0_, TRUE);
	self->identity_id = (QliteColumn*) _tmp0_;
	_tmp1_ = qlite_column_integer_new ("pre_key_id");
	qlite_column_set_not_null ((QliteColumn*) _tmp1_, TRUE);
	self->pre_key_id = (QliteColumn*) _tmp1_;
	_tmp2_ = qlite_column_non_null_text_new ("record_base64");
	self->record_base64 = (QliteColumn*) _tmp2_;
}

static void
dino_plugins_omemo_database_pre_key_table_finalize (QliteTable * obj)
{
	DinoPluginsOmemoDatabasePreKeyTable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_DATABASE_TYPE_PRE_KEY_TABLE, DinoPluginsOmemoDatabasePreKeyTable);
	_qlite_column_unref0 (self->identity_id);
	_qlite_column_unref0 (self->pre_key_id);
	_qlite_column_unref0 (self->record_base64);
	QLITE_TABLE_CLASS (dino_plugins_omemo_database_pre_key_table_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_database_pre_key_table_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoDatabasePreKeyTableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_database_pre_key_table_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoDatabasePreKeyTable), 0, (GInstanceInitFunc) dino_plugins_omemo_database_pre_key_table_instance_init, NULL };
	GType dino_plugins_omemo_database_pre_key_table_type_id;
	dino_plugins_omemo_database_pre_key_table_type_id = g_type_register_static (QLITE_TYPE_TABLE, "DinoPluginsOmemoDatabasePreKeyTable", &g_define_type_info, 0);
	return dino_plugins_omemo_database_pre_key_table_type_id;
}

GType
dino_plugins_omemo_database_pre_key_table_get_type (void)
{
	static volatile gsize dino_plugins_omemo_database_pre_key_table_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_database_pre_key_table_type_id__once)) {
		GType dino_plugins_omemo_database_pre_key_table_type_id;
		dino_plugins_omemo_database_pre_key_table_type_id = dino_plugins_omemo_database_pre_key_table_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_database_pre_key_table_type_id__once, dino_plugins_omemo_database_pre_key_table_type_id);
	}
	return dino_plugins_omemo_database_pre_key_table_type_id__once;
}

DinoPluginsOmemoDatabaseSessionTable*
dino_plugins_omemo_database_session_table_construct (GType object_type,
                                                     DinoPluginsOmemoDatabase* db)
{
	DinoPluginsOmemoDatabaseSessionTable* self = NULL;
	QliteColumn* _tmp0_;
	QliteColumn* _tmp1_;
	QliteColumn* _tmp2_;
	QliteColumn* _tmp3_;
	QliteColumn* _tmp4_;
	QliteColumn* _tmp5_;
	QliteColumn* _tmp6_;
	QliteColumn* _tmp7_;
	QliteColumn** _tmp8_;
	QliteColumn** _tmp9_;
	gint _tmp9__length1;
	QliteColumn* _tmp10_;
	QliteColumn* _tmp11_;
	QliteColumn* _tmp12_;
	QliteColumn* _tmp13_;
	QliteColumn* _tmp14_;
	QliteColumn* _tmp15_;
	QliteColumn** _tmp16_;
	QliteColumn** _tmp17_;
	gint _tmp17__length1;
	QliteColumn* _tmp18_;
	QliteColumn* _tmp19_;
	QliteColumn* _tmp20_;
	QliteColumn* _tmp21_;
	QliteColumn* _tmp22_;
	QliteColumn* _tmp23_;
	QliteColumn** _tmp24_;
	QliteColumn** _tmp25_;
	gint _tmp25__length1;
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoPluginsOmemoDatabaseSessionTable*) qlite_table_construct (object_type, (QliteDatabase*) db, "session");
	_tmp0_ = self->identity_id;
	_tmp1_ = _qlite_column_ref0 (_tmp0_);
	_tmp2_ = self->address_name;
	_tmp3_ = _qlite_column_ref0 (_tmp2_);
	_tmp4_ = self->device_id;
	_tmp5_ = _qlite_column_ref0 (_tmp4_);
	_tmp6_ = self->record_base64;
	_tmp7_ = _qlite_column_ref0 (_tmp6_);
	_tmp8_ = g_new0 (QliteColumn*, 4 + 1);
	_tmp8_[0] = _tmp1_;
	_tmp8_[1] = _tmp3_;
	_tmp8_[2] = _tmp5_;
	_tmp8_[3] = _tmp7_;
	_tmp9_ = _tmp8_;
	_tmp9__length1 = 4;
	qlite_table_init ((QliteTable*) self, _tmp9_, (gint) 4, "");
	_tmp9_ = (_vala_array_free (_tmp9_, _tmp9__length1, (GDestroyNotify) qlite_column_unref), NULL);
	_tmp10_ = self->identity_id;
	_tmp11_ = _qlite_column_ref0 (_tmp10_);
	_tmp12_ = self->address_name;
	_tmp13_ = _qlite_column_ref0 (_tmp12_);
	_tmp14_ = self->device_id;
	_tmp15_ = _qlite_column_ref0 (_tmp14_);
	_tmp16_ = g_new0 (QliteColumn*, 3 + 1);
	_tmp16_[0] = _tmp11_;
	_tmp16_[1] = _tmp13_;
	_tmp16_[2] = _tmp15_;
	_tmp17_ = _tmp16_;
	_tmp17__length1 = 3;
	qlite_table_unique ((QliteTable*) self, _tmp17_, (gint) 3, NULL);
	_tmp17_ = (_vala_array_free (_tmp17_, _tmp17__length1, (GDestroyNotify) qlite_column_unref), NULL);
	_tmp18_ = self->identity_id;
	_tmp19_ = _qlite_column_ref0 (_tmp18_);
	_tmp20_ = self->address_name;
	_tmp21_ = _qlite_column_ref0 (_tmp20_);
	_tmp22_ = self->device_id;
	_tmp23_ = _qlite_column_ref0 (_tmp22_);
	_tmp24_ = g_new0 (QliteColumn*, 3 + 1);
	_tmp24_[0] = _tmp19_;
	_tmp24_[1] = _tmp21_;
	_tmp24_[2] = _tmp23_;
	_tmp25_ = _tmp24_;
	_tmp25__length1 = 3;
	qlite_table_index ((QliteTable*) self, "session_idx", _tmp25_, (gint) 3, TRUE);
	_tmp25_ = (_vala_array_free (_tmp25_, _tmp25__length1, (GDestroyNotify) qlite_column_unref), NULL);
	return self;
}

DinoPluginsOmemoDatabaseSessionTable*
dino_plugins_omemo_database_session_table_new (DinoPluginsOmemoDatabase* db)
{
	return dino_plugins_omemo_database_session_table_construct (DINO_PLUGINS_OMEMO_DATABASE_TYPE_SESSION_TABLE, db);
}

static void
dino_plugins_omemo_database_session_table_class_init (DinoPluginsOmemoDatabaseSessionTableClass * klass,
                                                      gpointer klass_data)
{
	dino_plugins_omemo_database_session_table_parent_class = g_type_class_peek_parent (klass);
	((QliteTableClass *) klass)->finalize = dino_plugins_omemo_database_session_table_finalize;
}

static void
dino_plugins_omemo_database_session_table_instance_init (DinoPluginsOmemoDatabaseSessionTable * self,
                                                         gpointer klass)
{
	QliteColumnInteger* _tmp0_ = NULL;
	QliteColumnNonNullText* _tmp1_;
	QliteColumnInteger* _tmp2_ = NULL;
	QliteColumnNonNullText* _tmp3_;
	_tmp0_ = qlite_column_integer_new ("identity_id");
	qlite_column_set_not_null ((QliteColumn*) _tmp0_, TRUE);
	self->identity_id = (QliteColumn*) _tmp0_;
	_tmp1_ = qlite_column_non_null_text_new ("name");
	self->address_name = (QliteColumn*) _tmp1_;
	_tmp2_ = qlite_column_integer_new ("device_id");
	qlite_column_set_not_null ((QliteColumn*) _tmp2_, TRUE);
	self->device_id = (QliteColumn*) _tmp2_;
	_tmp3_ = qlite_column_non_null_text_new ("record_base64");
	self->record_base64 = (QliteColumn*) _tmp3_;
}

static void
dino_plugins_omemo_database_session_table_finalize (QliteTable * obj)
{
	DinoPluginsOmemoDatabaseSessionTable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_DATABASE_TYPE_SESSION_TABLE, DinoPluginsOmemoDatabaseSessionTable);
	_qlite_column_unref0 (self->identity_id);
	_qlite_column_unref0 (self->address_name);
	_qlite_column_unref0 (self->device_id);
	_qlite_column_unref0 (self->record_base64);
	QLITE_TABLE_CLASS (dino_plugins_omemo_database_session_table_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_database_session_table_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoDatabaseSessionTableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_database_session_table_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoDatabaseSessionTable), 0, (GInstanceInitFunc) dino_plugins_omemo_database_session_table_instance_init, NULL };
	GType dino_plugins_omemo_database_session_table_type_id;
	dino_plugins_omemo_database_session_table_type_id = g_type_register_static (QLITE_TYPE_TABLE, "DinoPluginsOmemoDatabaseSessionTable", &g_define_type_info, 0);
	return dino_plugins_omemo_database_session_table_type_id;
}

GType
dino_plugins_omemo_database_session_table_get_type (void)
{
	static volatile gsize dino_plugins_omemo_database_session_table_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_database_session_table_type_id__once)) {
		GType dino_plugins_omemo_database_session_table_type_id;
		dino_plugins_omemo_database_session_table_type_id = dino_plugins_omemo_database_session_table_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_database_session_table_type_id__once, dino_plugins_omemo_database_session_table_type_id);
	}
	return dino_plugins_omemo_database_session_table_type_id__once;
}

DinoPluginsOmemoDatabaseContentItemMetaTable*
dino_plugins_omemo_database_content_item_meta_table_construct (GType object_type,
                                                               DinoPluginsOmemoDatabase* db)
{
	DinoPluginsOmemoDatabaseContentItemMetaTable* self = NULL;
	QliteColumn* _tmp0_;
	QliteColumn* _tmp1_;
	QliteColumn* _tmp2_;
	QliteColumn* _tmp3_;
	QliteColumn* _tmp4_;
	QliteColumn* _tmp5_;
	QliteColumn* _tmp6_;
	QliteColumn* _tmp7_;
	QliteColumn* _tmp8_;
	QliteColumn* _tmp9_;
	QliteColumn** _tmp10_;
	QliteColumn** _tmp11_;
	gint _tmp11__length1;
	QliteColumn* _tmp12_;
	QliteColumn* _tmp13_;
	QliteColumn* _tmp14_;
	QliteColumn* _tmp15_;
	QliteColumn* _tmp16_;
	QliteColumn* _tmp17_;
	QliteColumn** _tmp18_;
	QliteColumn** _tmp19_;
	gint _tmp19__length1;
	g_return_val_if_fail (db != NULL, NULL);
	self = (DinoPluginsOmemoDatabaseContentItemMetaTable*) qlite_table_construct (object_type, (QliteDatabase*) db, "content_item_meta");
	_tmp0_ = self->content_item_id;
	_tmp1_ = _qlite_column_ref0 (_tmp0_);
	_tmp2_ = self->identity_id;
	_tmp3_ = _qlite_column_ref0 (_tmp2_);
	_tmp4_ = self->address_name;
	_tmp5_ = _qlite_column_ref0 (_tmp4_);
	_tmp6_ = self->device_id;
	_tmp7_ = _qlite_column_ref0 (_tmp6_);
	_tmp8_ = self->trusted_when_received;
	_tmp9_ = _qlite_column_ref0 (_tmp8_);
	_tmp10_ = g_new0 (QliteColumn*, 5 + 1);
	_tmp10_[0] = _tmp1_;
	_tmp10_[1] = _tmp3_;
	_tmp10_[2] = _tmp5_;
	_tmp10_[3] = _tmp7_;
	_tmp10_[4] = _tmp9_;
	_tmp11_ = _tmp10_;
	_tmp11__length1 = 5;
	qlite_table_init ((QliteTable*) self, _tmp11_, (gint) 5, "");
	_tmp11_ = (_vala_array_free (_tmp11_, _tmp11__length1, (GDestroyNotify) qlite_column_unref), NULL);
	_tmp12_ = self->identity_id;
	_tmp13_ = _qlite_column_ref0 (_tmp12_);
	_tmp14_ = self->device_id;
	_tmp15_ = _qlite_column_ref0 (_tmp14_);
	_tmp16_ = self->address_name;
	_tmp17_ = _qlite_column_ref0 (_tmp16_);
	_tmp18_ = g_new0 (QliteColumn*, 3 + 1);
	_tmp18_[0] = _tmp13_;
	_tmp18_[1] = _tmp15_;
	_tmp18_[2] = _tmp17_;
	_tmp19_ = _tmp18_;
	_tmp19__length1 = 3;
	qlite_table_index ((QliteTable*) self, "content_item_meta_device_idx", _tmp19_, (gint) 3, FALSE);
	_tmp19_ = (_vala_array_free (_tmp19_, _tmp19__length1, (GDestroyNotify) qlite_column_unref), NULL);
	return self;
}

DinoPluginsOmemoDatabaseContentItemMetaTable*
dino_plugins_omemo_database_content_item_meta_table_new (DinoPluginsOmemoDatabase* db)
{
	return dino_plugins_omemo_database_content_item_meta_table_construct (DINO_PLUGINS_OMEMO_DATABASE_TYPE_CONTENT_ITEM_META_TABLE, db);
}

QliteRowOption*
dino_plugins_omemo_database_content_item_meta_table_with_content_item (DinoPluginsOmemoDatabaseContentItemMetaTable* self,
                                                                       DinoContentItem* item)
{
	QliteColumn* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	QliteRowOption* _tmp3_;
	QliteRowOption* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (item != NULL, NULL);
	_tmp0_ = self->content_item_id;
	_tmp1_ = dino_content_item_get_id (item);
	_tmp2_ = _tmp1_;
	_tmp3_ = qlite_table_row_with ((QliteTable*) self, G_TYPE_INT, NULL, NULL, _tmp0_, (gpointer) ((gintptr) _tmp2_));
	result = _tmp3_;
	return result;
}

QliteQueryBuilder*
dino_plugins_omemo_database_content_item_meta_table_with_device (DinoPluginsOmemoDatabaseContentItemMetaTable* self,
                                                                 gint identity_id,
                                                                 const gchar* address_name,
                                                                 gint device_id)
{
	QliteQueryBuilder* _tmp0_;
	QliteQueryBuilder* _tmp1_;
	QliteColumn* _tmp2_;
	QliteQueryBuilder* _tmp3_;
	QliteQueryBuilder* _tmp4_;
	QliteColumn* _tmp5_;
	QliteQueryBuilder* _tmp6_;
	QliteQueryBuilder* _tmp7_;
	QliteColumn* _tmp8_;
	QliteQueryBuilder* _tmp9_;
	QliteQueryBuilder* _tmp10_;
	QliteQueryBuilder* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (address_name != NULL, NULL);
	_tmp0_ = qlite_table_select ((QliteTable*) self, NULL, (gint) 0);
	_tmp1_ = _tmp0_;
	_tmp2_ = self->identity_id;
	_tmp3_ = qlite_query_builder_with (_tmp1_, G_TYPE_INT, NULL, NULL, _tmp2_, "=", (gpointer) ((gintptr) identity_id));
	_tmp4_ = _tmp3_;
	_tmp5_ = self->address_name;
	_tmp6_ = qlite_query_builder_with (_tmp4_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp5_, "=", address_name);
	_tmp7_ = _tmp6_;
	_tmp8_ = self->device_id;
	_tmp9_ = qlite_query_builder_with (_tmp7_, G_TYPE_INT, NULL, NULL, _tmp8_, "=", (gpointer) ((gintptr) device_id));
	_tmp10_ = _tmp9_;
	_qlite_statement_builder_unref0 (_tmp7_);
	_qlite_statement_builder_unref0 (_tmp4_);
	_qlite_statement_builder_unref0 (_tmp1_);
	result = _tmp10_;
	return result;
}

static void
dino_plugins_omemo_database_content_item_meta_table_class_init (DinoPluginsOmemoDatabaseContentItemMetaTableClass * klass,
                                                                gpointer klass_data)
{
	dino_plugins_omemo_database_content_item_meta_table_parent_class = g_type_class_peek_parent (klass);
	((QliteTableClass *) klass)->finalize = dino_plugins_omemo_database_content_item_meta_table_finalize;
}

static void
dino_plugins_omemo_database_content_item_meta_table_instance_init (DinoPluginsOmemoDatabaseContentItemMetaTable * self,
                                                                   gpointer klass)
{
	QliteColumnInteger* _tmp0_ = NULL;
	QliteColumnInteger* _tmp1_ = NULL;
	QliteColumnText* _tmp2_ = NULL;
	QliteColumnInteger* _tmp3_ = NULL;
	gchar* _tmp4_;
	QliteColumnBoolInt* _tmp5_ = NULL;
	_tmp0_ = qlite_column_integer_new ("message_id");
	qlite_column_set_primary_key ((QliteColumn*) _tmp0_, TRUE);
	self->content_item_id = (QliteColumn*) _tmp0_;
	_tmp1_ = qlite_column_integer_new ("identity_id");
	qlite_column_set_not_null ((QliteColumn*) _tmp1_, TRUE);
	self->identity_id = (QliteColumn*) _tmp1_;
	_tmp2_ = qlite_column_text_new ("address_name");
	qlite_column_set_not_null ((QliteColumn*) _tmp2_, TRUE);
	self->address_name = (QliteColumn*) _tmp2_;
	_tmp3_ = qlite_column_integer_new ("device_id");
	qlite_column_set_not_null ((QliteColumn*) _tmp3_, TRUE);
	self->device_id = (QliteColumn*) _tmp3_;
	_tmp4_ = g_strdup ("1");
	_tmp5_ = qlite_column_bool_int_new ("trusted_when_received");
	qlite_column_set_not_null ((QliteColumn*) _tmp5_, TRUE);
	qlite_column_set_default ((QliteColumn*) _tmp5_, _tmp4_);
	_g_free0 (_tmp4_);
	self->trusted_when_received = (QliteColumn*) _tmp5_;
}

static void
dino_plugins_omemo_database_content_item_meta_table_finalize (QliteTable * obj)
{
	DinoPluginsOmemoDatabaseContentItemMetaTable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_DATABASE_TYPE_CONTENT_ITEM_META_TABLE, DinoPluginsOmemoDatabaseContentItemMetaTable);
	_qlite_column_unref0 (self->content_item_id);
	_qlite_column_unref0 (self->identity_id);
	_qlite_column_unref0 (self->address_name);
	_qlite_column_unref0 (self->device_id);
	_qlite_column_unref0 (self->trusted_when_received);
	QLITE_TABLE_CLASS (dino_plugins_omemo_database_content_item_meta_table_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_database_content_item_meta_table_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoDatabaseContentItemMetaTableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_database_content_item_meta_table_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoDatabaseContentItemMetaTable), 0, (GInstanceInitFunc) dino_plugins_omemo_database_content_item_meta_table_instance_init, NULL };
	GType dino_plugins_omemo_database_content_item_meta_table_type_id;
	dino_plugins_omemo_database_content_item_meta_table_type_id = g_type_register_static (QLITE_TYPE_TABLE, "DinoPluginsOmemoDatabaseContentItemMetaTable", &g_define_type_info, 0);
	return dino_plugins_omemo_database_content_item_meta_table_type_id;
}

GType
dino_plugins_omemo_database_content_item_meta_table_get_type (void)
{
	static volatile gsize dino_plugins_omemo_database_content_item_meta_table_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_database_content_item_meta_table_type_id__once)) {
		GType dino_plugins_omemo_database_content_item_meta_table_type_id;
		dino_plugins_omemo_database_content_item_meta_table_type_id = dino_plugins_omemo_database_content_item_meta_table_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_database_content_item_meta_table_type_id__once, dino_plugins_omemo_database_content_item_meta_table_type_id);
	}
	return dino_plugins_omemo_database_content_item_meta_table_type_id__once;
}

static void
dino_plugins_omemo_database_class_init (DinoPluginsOmemoDatabaseClass * klass,
                                        gpointer klass_data)
{
	dino_plugins_omemo_database_parent_class = g_type_class_peek_parent (klass);
	((QliteDatabaseClass *) klass)->finalize = dino_plugins_omemo_database_finalize;
	g_type_class_adjust_private_offset (klass, &DinoPluginsOmemoDatabase_private_offset);
	((QliteDatabaseClass *) klass)->migrate = (void (*) (QliteDatabase*, glong)) dino_plugins_omemo_database_real_migrate;
}

static void
dino_plugins_omemo_database_instance_init (DinoPluginsOmemoDatabase * self,
                                           gpointer klass)
{
	self->priv = dino_plugins_omemo_database_get_instance_private (self);
}

static void
dino_plugins_omemo_database_finalize (QliteDatabase * obj)
{
	DinoPluginsOmemoDatabase * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_TYPE_DATABASE, DinoPluginsOmemoDatabase);
	_qlite_table_unref0 (self->priv->_identity_meta);
	_qlite_table_unref0 (self->priv->_trust);
	_qlite_table_unref0 (self->priv->_identity);
	_qlite_table_unref0 (self->priv->_signed_pre_key);
	_qlite_table_unref0 (self->priv->_pre_key);
	_qlite_table_unref0 (self->priv->_session);
	_qlite_table_unref0 (self->priv->_content_item_meta);
	QLITE_DATABASE_CLASS (dino_plugins_omemo_database_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_database_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoDatabaseClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_database_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoDatabase), 0, (GInstanceInitFunc) dino_plugins_omemo_database_instance_init, NULL };
	GType dino_plugins_omemo_database_type_id;
	dino_plugins_omemo_database_type_id = g_type_register_static (QLITE_TYPE_DATABASE, "DinoPluginsOmemoDatabase", &g_define_type_info, 0);
	DinoPluginsOmemoDatabase_private_offset = g_type_add_instance_private (dino_plugins_omemo_database_type_id, sizeof (DinoPluginsOmemoDatabasePrivate));
	return dino_plugins_omemo_database_type_id;
}

GType
dino_plugins_omemo_database_get_type (void)
{
	static volatile gsize dino_plugins_omemo_database_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_database_type_id__once)) {
		GType dino_plugins_omemo_database_type_id;
		dino_plugins_omemo_database_type_id = dino_plugins_omemo_database_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_database_type_id__once, dino_plugins_omemo_database_type_id);
	}
	return dino_plugins_omemo_database_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);
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

