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


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

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



gint _vala_main (gchar** args, int args_length1);


/**
 * Demonstrates a few of the user-defined functions SQLHeavy can
 * register.
 */
static gchar* string_to_utf8 (const gchar* self, int* result_length1) {
	gchar* result = NULL;
	gint _tmp0_;
	gint _tmp1_;
	gchar* _tmp2_ = NULL;
	gchar* _result_;
	gint _result__length1;
	gint __result__size_;
	gint _tmp3_;
	gchar* _tmp4_;
	gint _tmp4__length1;
	gint _tmp5_;
	gint _tmp6_;
	gchar* _tmp7_;
	gint _tmp7__length1;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_new0 (gchar, _tmp1_ + 1);
	_result_ = _tmp2_;
	_result__length1 = _tmp1_ + 1;
	__result__size_ = _result__length1;
	_tmp3_ = _result__length1;
	_result__length1 = _tmp3_ - 1;
	_tmp4_ = _result_;
	_tmp4__length1 = _result__length1;
	_tmp5_ = strlen (self);
	_tmp6_ = _tmp5_;
	memcpy (_tmp4_, self, (gsize) _tmp6_);
	_tmp7_ = _result_;
	_tmp7__length1 = _result__length1;
	if (result_length1) {
		*result_length1 = _tmp7__length1;
	}
	result = _tmp7_;
	return result;
}


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	GError * _inner_error_ = NULL;
	{
		SQLHeavyDatabase* _tmp0_;
		SQLHeavyDatabase* db;
		SQLHeavyDatabase* _tmp1_;
		gchar* _tmp2_;
		gchar* test_string;
		FILE* _tmp3_;
		SQLHeavyDatabase* _tmp4_;
		SQLHeavyQuery* _tmp5_ = NULL;
		SQLHeavyQuery* query;
		SQLHeavyQuery* _tmp6_;
		const gchar* _tmp7_;
		SQLHeavyQuery* _tmp8_;
		SQLHeavyQueryResult* _tmp9_ = NULL;
		SQLHeavyQueryResult* res;
		SQLHeavyQueryResult* _tmp10_;
		gchar* _tmp11_ = NULL;
		gchar* _tmp12_;
		FILE* _tmp13_;
		gchar* _tmp14_;
		SQLHeavyQueryResult* _tmp15_;
		gchar* _tmp16_ = NULL;
		gchar* _tmp17_;
		FILE* _tmp18_;
		gchar* _tmp19_;
		SQLHeavyQueryResult* _tmp20_;
		gchar* _tmp21_ = NULL;
		gchar* _tmp22_;
		FILE* _tmp23_;
		gchar* _tmp24_;
		FILE* _tmp25_;
		FILE* _tmp26_;
		const gchar* _tmp27_;
		gint _tmp28_ = 0;
		gchar* _tmp29_ = NULL;
		guint8* data;
		gint data_length1;
		gint _data_size_;
		FILE* _tmp30_;
		const gchar* _tmp31_;
		gint _tmp32_;
		gint _tmp33_;
		SQLHeavyDatabase* _tmp34_;
		SQLHeavyQuery* _tmp35_ = NULL;
		SQLHeavyQuery* _tmp36_;
		SQLHeavyQuery* _tmp37_;
		guint8* _tmp38_;
		gint _tmp38__length1;
		SQLHeavyQuery* _tmp39_;
		SQLHeavyQueryResult* _tmp40_ = NULL;
		SQLHeavyQueryResult* _tmp41_;
		SQLHeavyQueryResult* _tmp42_;
		gint _tmp43_ = 0;
		guint8* _tmp44_ = NULL;
		guint8* _tmp45_;
		gint _tmp45__length1;
		guint8* compressed;
		gint compressed_length1;
		gint _compressed_size_;
		FILE* _tmp46_;
		guint8* _tmp47_;
		gint _tmp47__length1;
		SQLHeavyDatabase* _tmp48_;
		SQLHeavyQuery* _tmp49_ = NULL;
		SQLHeavyQuery* _tmp50_;
		SQLHeavyQuery* _tmp51_;
		guint8* _tmp52_;
		gint _tmp52__length1;
		const gchar* _tmp53_ = NULL;
		SQLHeavyQuery* _tmp54_;
		SQLHeavyQueryResult* _tmp55_ = NULL;
		SQLHeavyQueryResult* _tmp56_;
		SQLHeavyQueryResult* _tmp57_;
		gchar* _tmp58_ = NULL;
		gchar* _tmp59_;
		gchar* _tmp60_;
		gchar* _tmp61_;
		const gchar* _tmp62_;
		gboolean _tmp63_;
		FILE* _tmp64_;
		const gchar* _tmp65_;
		gchar* _tmp66_;
		gchar* _tmp67_;
		gchar* _tmp68_;
		gchar* _tmp69_;
		_tmp0_ = sql_heavy_database_new (NULL, (SQL_HEAVY_FILE_MODE_READ | SQL_HEAVY_FILE_MODE_WRITE) | SQL_HEAVY_FILE_MODE_CREATE, &_inner_error_);
		db = _tmp0_;
		if (_inner_error_ != NULL) {
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp1_ = db;
		sql_heavy_database_register_common_functions (_tmp1_);
		_tmp2_ = g_strdup ("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur ege" \
"stas, risus eu consectetur malesuada, lacus dolor lobortis arcu, id vu" \
"lputate justo quam ut quam. Aenean nulla arcu, placerat eu pellentesqu" \
"e et, scelerisque non nunc. Praesent id mi metus. Aenean dignissim ves" \
"tibulum dolor, ac blandit massa sodales a. Lorem ipsum dolor sit amet," \
" consectetur adipiscing elit. Integer sem nunc, faucibus vel vestibulu" \
"m nec, luctus eu leo. Class aptent taciti sociosqu ad litora torquent " \
"per conubia nostra, per inceptos himenaeos. Pellentesque ultricies odi" \
"o a turpis pharetra rhoncus. Curabitur ut lectus eu nisl elementum imp" \
"erdiet sed at lectus. Cras vehicula urna sit amet arcu accumsan tristi" \
"que. Proin ultrices, leo auctor tempor commodo, metus justo luctus lor" \
"em, a egestas urna purus sit amet dolor. Praesent ullamcorper elit et " \
"leo interdum porta.");
		test_string = _tmp2_;
		_tmp3_ = stdout;
		fputs ("Testing cryptographic hashes...\n", _tmp3_);
		_tmp4_ = db;
		_tmp5_ = sql_heavy_queryable_prepare ((SQLHeavyQueryable*) _tmp4_, "SELECT MD5(:data), SHA1(:data), SHA256(:data);", &_inner_error_);
		query = _tmp5_;
		if (_inner_error_ != NULL) {
			_g_free0 (test_string);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			_g_free0 (test_string);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp6_ = query;
		_tmp7_ = test_string;
		sql_heavy_query_set_string (_tmp6_, ":data", _tmp7_, &_inner_error_);
		if (_inner_error_ != NULL) {
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp8_ = query;
		_tmp9_ = sql_heavy_query_execute (_tmp8_, NULL, &_inner_error_, NULL);
		res = _tmp9_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp10_ = res;
		_tmp11_ = sql_heavy_record_fetch_string ((SQLHeavyRecord*) _tmp10_, 0, &_inner_error_);
		_tmp12_ = _tmp11_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp13_ = stdout;
		_tmp14_ = _tmp12_;
		fprintf (_tmp13_, "   MD5: %s\n", _tmp14_);
		_g_free0 (_tmp14_);
		_tmp15_ = res;
		_tmp16_ = sql_heavy_record_fetch_string ((SQLHeavyRecord*) _tmp15_, 1, &_inner_error_);
		_tmp17_ = _tmp16_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp18_ = stdout;
		_tmp19_ = _tmp17_;
		fprintf (_tmp18_, "  SHA1: %s\n", _tmp19_);
		_g_free0 (_tmp19_);
		_tmp20_ = res;
		_tmp21_ = sql_heavy_record_fetch_string ((SQLHeavyRecord*) _tmp20_, 2, &_inner_error_);
		_tmp22_ = _tmp21_;
		if (_inner_error_ != NULL) {
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp23_ = stdout;
		_tmp24_ = _tmp22_;
		fprintf (_tmp23_, "SHA256: %s\n", _tmp24_);
		_g_free0 (_tmp24_);
		_tmp25_ = stdout;
		fputc ('\n', _tmp25_);
		_tmp26_ = stdout;
		fputs ("Testing compression...\n", _tmp26_);
		_tmp27_ = test_string;
		_tmp29_ = string_to_utf8 (_tmp27_, &_tmp28_);
		data = (guint8*) _tmp29_;
		data_length1 = _tmp28_;
		_data_size_ = data_length1;
		_tmp30_ = stdout;
		_tmp31_ = test_string;
		_tmp32_ = strlen (_tmp31_);
		_tmp33_ = _tmp32_;
		fprintf (_tmp30_, "Original size: %d bytes\n", (gint) _tmp33_);
		_tmp34_ = db;
		_tmp35_ = sql_heavy_queryable_prepare ((SQLHeavyQueryable*) _tmp34_, "SELECT COMPRESS(:data);", &_inner_error_);
		_tmp36_ = _tmp35_;
		if (_inner_error_ != NULL) {
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_g_object_unref0 (query);
		query = _tmp36_;
		_tmp37_ = query;
		_tmp38_ = data;
		_tmp38__length1 = data_length1;
		sql_heavy_query_set_blob (_tmp37_, ":data", _tmp38_, _tmp38__length1, &_inner_error_);
		if (_inner_error_ != NULL) {
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp39_ = query;
		_tmp40_ = sql_heavy_query_execute (_tmp39_, NULL, &_inner_error_, NULL);
		_tmp41_ = _tmp40_;
		if (_inner_error_ != NULL) {
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp42_ = _tmp41_;
		_tmp44_ = sql_heavy_record_fetch_blob ((SQLHeavyRecord*) _tmp42_, 0, &_tmp43_, &_inner_error_);
		_tmp45_ = _tmp44_;
		_tmp45__length1 = _tmp43_;
		_g_object_unref0 (_tmp42_);
		compressed = _tmp45_;
		compressed_length1 = _tmp45__length1;
		_compressed_size_ = compressed_length1;
		if (_inner_error_ != NULL) {
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp46_ = stdout;
		_tmp47_ = compressed;
		_tmp47__length1 = compressed_length1;
		fprintf (_tmp46_, "Compressed size: %d bytes\n", _tmp47__length1);
		_tmp48_ = db;
		_tmp49_ = sql_heavy_queryable_prepare ((SQLHeavyQueryable*) _tmp48_, "SELECT DECOMPRESS(:data);", &_inner_error_);
		_tmp50_ = _tmp49_;
		if (_inner_error_ != NULL) {
			compressed = (g_free (compressed), NULL);
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			compressed = (g_free (compressed), NULL);
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_g_object_unref0 (query);
		query = _tmp50_;
		_tmp51_ = query;
		_tmp52_ = compressed;
		_tmp52__length1 = compressed_length1;
		sql_heavy_query_set_blob (_tmp51_, ":data", _tmp52_, _tmp52__length1, &_inner_error_);
		if (_inner_error_ != NULL) {
			compressed = (g_free (compressed), NULL);
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			compressed = (g_free (compressed), NULL);
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp54_ = query;
		_tmp55_ = sql_heavy_query_execute (_tmp54_, NULL, &_inner_error_, NULL);
		_tmp56_ = _tmp55_;
		if (_inner_error_ != NULL) {
			compressed = (g_free (compressed), NULL);
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			compressed = (g_free (compressed), NULL);
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp57_ = _tmp56_;
		_tmp58_ = sql_heavy_record_fetch_string ((SQLHeavyRecord*) _tmp57_, 0, &_inner_error_);
		_tmp59_ = _tmp58_;
		_g_object_unref0 (_tmp57_);
		_tmp60_ = _tmp59_;
		if (_inner_error_ != NULL) {
			compressed = (g_free (compressed), NULL);
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			if (_inner_error_->domain == SQL_HEAVY_ERROR) {
				goto __catch0_sql_heavy_error;
			}
			compressed = (g_free (compressed), NULL);
			data = (g_free (data), NULL);
			_g_object_unref0 (res);
			_g_object_unref0 (query);
			_g_free0 (test_string);
			_g_object_unref0 (db);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_tmp61_ = _tmp60_;
		_tmp62_ = test_string;
		_tmp63_ = g_strcmp0 (_tmp61_, _tmp62_) == 0;
		_g_free0 (_tmp61_);
		if (_tmp63_) {
			_tmp53_ = "successful";
		} else {
			_tmp53_ = "failed";
		}
		_tmp64_ = stdout;
		_tmp65_ = _tmp53_;
		_tmp66_ = g_strconcat ("Decompression ", _tmp65_, NULL);
		_tmp67_ = _tmp66_;
		_tmp68_ = g_strconcat (_tmp67_, ".\n", NULL);
		_tmp69_ = _tmp68_;
		fputs (_tmp69_, _tmp64_);
		_g_free0 (_tmp69_);
		_g_free0 (_tmp67_);
		compressed = (g_free (compressed), NULL);
		data = (g_free (data), NULL);
		_g_object_unref0 (res);
		_g_object_unref0 (query);
		_g_free0 (test_string);
		_g_object_unref0 (db);
	}
	goto __finally0;
	__catch0_sql_heavy_error:
	{
		GError* e = NULL;
		const gchar* _tmp70_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp70_ = e->message;
		g_error ("common-functions.vala:34: %s", _tmp70_);
		_g_error_free0 (e);
	}
	__finally0:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return 0;
	}
	result = 0;
	return result;
}


int main (int argc, char ** argv) {
	g_type_init ();
	return _vala_main (argv, argc);
}



