<commit_before>/* sqlite3.vala
 *
 * Copyright (C) 2007 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	<NAME> <<EMAIL>>
 */

[CCode (lower_case_cprefix = "sqlite3_", cheader_filename = "sqlite3.h")]
namespace Sqlite {
	/* Database Connection Handle */
	[Compact]
	[CCode (free_function = "sqlite3_close", cname = "sqlite3", cprefix = "sqlite3_")]
	public class Database {
		public int busy_timeout (int ms);
		public int changes ();
		[CCode (cname = "sqlite3_exec")]
		public int _exec (string sql, Callback? sqlite3_callback = null, [CCode (type = "char**")] out unowned string errmsg = null);
		[CCode (cname = "_sqlite3_exec")]
		public int exec (string sql, Callback? sqlite3_callback = null, out string errmsg = null) {
			unowned string sqlite_errmsg;
			var ec = this._exec (sql, sqlite3_callback, out sqlite_errmsg);
			if (&errmsg != null) {
				errmsg = sqlite_errmsg;
			}
			Sqlite.Memory.free ((void*) sqlite_errmsg);
			return ec;
		}
		public int extended_result_codes (int onoff);
		public int get_autocommit ();
		public void interrupt ();
		public int64 last_insert_rowid ();
		public int limit (Sqlite.Limit id, int new_val);
		public int total_changes ();
		public int complete (string sql);
		[CCode (cname = "sqlite3_get_table")]
		public int _get_table (string sql, [CCode (array_length = false)] out unowned string[] resultp, out int nrow, out int ncolumn, [CCode (type = "char**")] out unowned string? errmsg = null);
		private static void free_table ([CCode (array_length = false)] string[] result);
		[CCode (cname = "_sqlite3_get_table")]
		public int get_table (string sql, out string[] resultp, out int nrow, out int ncolumn, out string? errmsg = null) {
			unowned string sqlite_errmsg;
			unowned string[] sqlite_resultp;

			var ec = this._get_table (sql, out sqlite_resultp, out nrow, out ncolumn, out sqlite_errmsg);

			resultp = new string[(nrow + 1) * ncolumn];
			for (var entry = 0 ; entry < resultp.length ; entry++ ) {
				resultp[entry] = sqlite_resultp[entry];
			}
			Sqlite.Database.free_table (sqlite_resultp);

			if (&errmsg != null) {
				errmsg = sqlite_errmsg;
			}
			Sqlite.Memory.free ((void*) sqlite_errmsg);
			return ec;
		}
		public static int open (string filename, out Database db);
		public static int open_v2 (string filename, out Database db, int flags = OPEN_READWRITE | OPEN_CREATE, string? zVfs = null);
		public int errcode ();
		public unowned string errmsg ();
		public unowned Sqlite.Statement next_stmt (Sqlite.Statement? current);
		public int prepare (string sql, int n_bytes, out Statement stmt, out unowned string tail = null);
		public int prepare_v2 (string sql, int n_bytes, out Statement stmt, out unowned string tail = null);
		public int set_authorizer (AuthorizeCallback? auth);
		[CCode (cname = "sqlite3_db_status")]
		public int status (Sqlite.DatabaseStatus op, out int pCurrent, out int pHighwater, int resetFlag = 0);
		public int table_column_metadata (string db_name, string table_name, string column_name, out string? data_type, out string? collation_sequence, out int? not_null, out int? primary_key, out int? auto_increment);
		public void trace (TraceCallback? xtrace);
		public void profile (ProfileCallback? xprofile);
		public void progress_handler (int n_opcodes, Sqlite.ProgressCallback? progress_handler);
		public void commit_hook (CommitCallback? commit_hook);
		public void rollback_hook (RollbackCallback? rollback_hook);
		public void update_hook (UpdateCallback? update_hook);
		public int create_function (string zFunctionName, int nArg, int eTextRep, void * user_data, UserFuncCallback? xFunc, UserFuncCallback? xStep, UserFuncFinishCallback? xFinal);
	}

	[CCode (instance_pos = 0)]
	public delegate int AuthorizeCallback (Sqlite.Action action, string? p1, string? p2, string db_name, string? responsible);
	[CCode (instance_pos = 0)]
	public delegate void TraceCallback (string message);
	[CCode (instance_pos = 0)]
	public delegate void ProfileCallback (string sql, uint64 time);
	public delegate int ProgressCallback ();
	public delegate int CommitCallback ();
	public delegate void RollbackCallback ();
	[CCode (has_target = false)]
	public delegate void UserFuncCallback (Sqlite.Context context, [CCode (array_length_pos = 1.1)] Sqlite.Value[] values);
	[CCode (has_target = false)]
	public delegate void UserFuncFinishCallback (Sqlite.Context context);
	[CCode (instance_pos = 0)]
	public delegate void UpdateCallback (Sqlite.Action action, string dbname, string table, int64 rowid);

	public unowned string? compileoption_get (int n);
	public int compileoption_used (string option_name);
	public static int complete (string sql);
	[CCode (sentinel = "")]
	public static int config (Sqlite.Config op, ...);
	public unowned string libversion ();<commit_msg>sqlite3: Add sqlite3_create_collation binding.<commit_after>/* sqlite3.vala
 *
 * Copyright (C) 2007 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	<NAME> <<EMAIL>>
 */

[CCode (lower_case_cprefix = "sqlite3_", cheader_filename = "sqlite3.h")]
namespace Sqlite {
	/* Database Connection Handle */
	[Compact]
	[CCode (free_function = "sqlite3_close", cname = "sqlite3", cprefix = "sqlite3_")]
	public class Database {
		public int busy_timeout (int ms);
		public int changes ();
		[CCode (cname = "sqlite3_exec")]
		public int _exec (string sql, Callback? sqlite3_callback = null, [CCode (type = "char**")] out unowned string errmsg = null);
		[CCode (cname = "_sqlite3_exec")]
		public int exec (string sql, Callback? sqlite3_callback = null, out string errmsg = null) {
			unowned string sqlite_errmsg;
			var ec = this._exec (sql, sqlite3_callback, out sqlite_errmsg);
			if (&errmsg != null) {
				errmsg = sqlite_errmsg;
			}
			Sqlite.Memory.free ((void*) sqlite_errmsg);
			return ec;
		}
		public int extended_result_codes (int onoff);
		public int get_autocommit ();
		public void interrupt ();
		public int64 last_insert_rowid ();
		public int limit (Sqlite.Limit id, int new_val);
		public int total_changes ();
		public int complete (string sql);
		[CCode (cname = "sqlite3_get_table")]
		public int _get_table (string sql, [CCode (array_length = false)] out unowned string[] resultp, out int nrow, out int ncolumn, [CCode (type = "char**")] out unowned string? errmsg = null);
		private static void free_table ([CCode (array_length = false)] string[] result);
		[CCode (cname = "_sqlite3_get_table")]
		public int get_table (string sql, out string[] resultp, out int nrow, out int ncolumn, out string? errmsg = null) {
			unowned string sqlite_errmsg;
			unowned string[] sqlite_resultp;

			var ec = this._get_table (sql, out sqlite_resultp, out nrow, out ncolumn, out sqlite_errmsg);

			resultp = new string[(nrow + 1) * ncolumn];
			for (var entry = 0 ; entry < resultp.length ; entry++ ) {
				resultp[entry] = sqlite_resultp[entry];
			}
			Sqlite.Database.free_table (sqlite_resultp);

			if (&errmsg != null) {
				errmsg = sqlite_errmsg;
			}
			Sqlite.Memory.free ((void*) sqlite_errmsg);
			return ec;
		}
		public static int open (string filename, out Database db);
		public static int open_v2 (string filename, out Database db, int flags = OPEN_READWRITE | OPEN_CREATE, string? zVfs = null);
		public int errcode ();
		public unowned string errmsg ();
		public unowned Sqlite.Statement next_stmt (Sqlite.Statement? current);
		public int prepare (string sql, int n_bytes, out Statement stmt, out unowned string tail = null);
		public int prepare_v2 (string sql, int n_bytes, out Statement stmt, out unowned string tail = null);
		public int set_authorizer (AuthorizeCallback? auth);
		[CCode (cname = "sqlite3_db_status")]
		public int status (Sqlite.DatabaseStatus op, out int pCurrent, out int pHighwater, int resetFlag = 0);
		public int table_column_metadata (string db_name, string table_name, string column_name, out string? data_type, out string? collation_sequence, out int? not_null, out int? primary_key, out int? auto_increment);
		public void trace (TraceCallback? xtrace);
		public void profile (ProfileCallback? xprofile);
		public void progress_handler (int n_opcodes, Sqlite.ProgressCallback? progress_handler);
		public void commit_hook (CommitCallback? commit_hook);
		public void rollback_hook (RollbackCallback? rollback_hook);
		public void update_hook (UpdateCallback? update_hook);
		public int create_function (string zFunctionName, int nArg, int eTextRep, void * user_data, UserFuncCallback? xFunc, UserFuncCallback? xStep, UserFuncFinishCallback? xFinal);
		public int create_collation (string zName, int eTextRep, [CCode (delegate_target_pos = 2.9, type = "int (*)(void *, int,  const void *, int,  const void *)")] CompareCallback xCompare);
	}

	[CCode (instance_pos = 0)]
	public delegate int AuthorizeCallback (Sqlite.Action action, string? p1, string? p2, string db_name, string? responsible);
	[CCode (instance_pos = 0)]
	public delegate void TraceCallback (string message);
	[CCode (instance_pos = 0)]
	public delegate void ProfileCallback (string sql, uint64 time);
	public delegate int ProgressCallback ();
	public delegate int CommitCallback ();
	public delegate void RollbackCallback ();
	[CCode (has_target = false)]
	public delegate void UserFuncCallback (Sqlite.Context context, [CCode (array_length_pos = 1.1)] Sqlite.Value[] values);
	[CCode (has_target = false)]
	public delegate void UserFuncFinishCallback (Sqlite.Context context);
	[CCode (instance_pos = 0)]
	public delegate void UpdateCallback (Sqlite.Action action, string dbname, string table, int64 rowid);
	[CCode (instance_pos = 0)]
	public delegate int CompareCallback (int alen, void* a, int blen, void* b);

	public unowned string? compileoption_get (int n);
	public int compileoption_used (string option_name);
	public static int complete (string sql);
	[CCode (sentinel = "")]
	public static int config (Sqlite.Config op, ...);
	public unowned string libversion ();
{'fraction_non_alphanumeric': 0.09800106138333628, 'fraction_numerical': 0.00928710419246418, 'mean_word_length': 4.816358024691358, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4252659', 'n_tokens_mistral': 3629, 'n_tokens_neox': 3360, 'n_words': 1277}