<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using SQLite.Net.Attributes;
using SQLite.Net.Builders;
using SQLite.Net.Expressions;
using SQLite.Net.Helpers;
using SQLite.Net.Translation;
using SQLitePCL;

namespace SQLite.Net
{
	public class SQLiteException : Exception
	{
		public SQLiteException() { }

		public SQLiteException(string message) : base(message) { }
	}

	public enum TransactionType
	{
		Deferred, Immediate, Exclusive
	}

	/// <summary>
	/// Represents a connection to an SQLite Database.
	/// </summary>
	public abstract class SQLiteDatabase : IDisposable
    {
		static SQLiteDatabase() { Batteries_V2.Init(); }

	    private readonly sqlite3 _db;
	    private readonly SQLiteQueryProvider _provider;

		/// <summary>
		/// The path of the database file this connection represents.
		/// Is null if it is an in-memory database.
		/// </summary>
		public string Path { get; }
		/// <summary>
		/// Is true if the connection to the databse is open.
		/// </summary>
		public bool IsOpen { get; private set; }
		/// <summary>
		/// Set this property to log the SQL generated by this <see cref="SQLiteDatabase"/> to the given delegate.
		/// </summary>
		public Action<string> Log { get; set; }

	    private readonly Stack<string> _transactionStack = new Stack<string>();
		/// <summary>
		/// Number representing how deep in the transaction stack the database is in.
		/// </summary>
	    public int TransactionDepth => _transactionStack.Count;
		/// <summary>
		/// True if the database is currently in a transaction.
		/// </summary>
	    public bool IsInTransaction => TransactionDepth > 0;

	    public long LastInsertRowId => raw.sqlite3_last_insert_rowid(_db);
		/// <summary>
		/// <returns>
		/// The number of database rows that were changed or inserted or deleted
		/// by the most recently completed INSERT, DELETE, or UPDATE statement,
		/// exclusive of statements in lower-level triggers.
		/// </returns>
		/// </summary>
		public int Changes => raw.sqlite3_changes(_db);
		/// <summary>
		/// <returns>
		/// This function returns the total number of rows inserted,
		/// modified or deleted by all INSERT, UPDATE or DELETE statements completed
		/// since the database connection was opened,
		/// including those executed as part of trigger programs.
		/// </returns>
		/// </summary>
		public int TotalChanges => raw.sqlite3_total_changes(_db);

	    public TimeSpan BusyTimeout
		{
		    get => TimeSpan.FromMilliseconds(ExecuteScalar<long>("PRAGMA busy_timeout;"));
			set => raw.sqlite3_busy_timeout(_db, (int) value.TotalMilliseconds);
	    }
		/// <summary>
		/// The user-version is an integer that is available to applications to use however they want.
		/// SQLite makes no use of the user-version itself.
		/// 
		/// It is usually used to keep track of migrations.
		/// It's initial value is 0.
		/// </summary>
		public long UserVersion
	    {
		    get => ExecuteScalar<long>("PRAGMA user_version");
		    set => Execute($"PRAGMA user_version = {value}");
	    }
		/// <summary>
		/// Query, set, or clear the enforcement of foreign key constraints.
		/// 
	    /// This pragma is a no-op within a transaction;
	    /// foreign key constraint enforcement may only be enabled or disabled when there is no pending BEGIN or SAVEPOINT.
		/// </summary>
		public bool ForeignKeysEnabled
	    {
			get => ExecuteScalar<bool>("PRAGMA foreign_keys");
		    set => Execute($"PRAGMA foreign_keys = {value}");
		}

		/// <summary>
		/// <para>
		/// Every SQLite database has an SQLITE_MASTER table that defines the schema for the database.
		/// </para>
		/// <para>
		///	For tables, the type field will always be 'table' and the name field will be the name of the table.
		///	For indices, type is equal to 'index', name is the name of the index and tbl_name is the name of the table to which the index belongs.
		/// For both tables and indices, the sql field is the text of the original CREATE TABLE or CREATE INDEX statement that created the table or index.
		/// For automatically created indices (used to implement the PRIMARY KEY or UNIQUE constraints) the sql field is NULL.
		/// </para>
		/// <para>
		/// The SQLITE_MASTER table is read-only.
		/// You cannot change this table using UPDATE, INSERT, or DELETE.
		/// The table is automatically updated by CREATE TABLE, CREATE INDEX, DROP TABLE, and DROP INDEX commands.
		/// </para>
		/// </summary>
		/// 
		/// <example>
		/// So to get a list of all tables in the database, use the following SELECT command:
		///	<code>
		/// SQLiteMaster.Where(o => o.Type == "table").OrderBy(o => o.Name).Select(o => o.Name)
		/// </code>
		/// </example>
		public Table<DatabaseObject> SQLiteMaster { get; set; }
		/// <summary>
		/// Temporary tables do not appear in the SQLITE_MASTER table.
		/// Temporary tables and their indices and triggers occur in another special table named SQLITE_TEMP_MASTER.
		/// <para>
		/// SQLITE_TEMP_MASTER works just like SQLITE_MASTER,
		/// except that it is only visible to the application that created the temporary tables.
		/// </para>
		/// </summary>
		public Table<DatabaseObject> SQLiteTempMaster { get; set; }

		/// <summary><commit_msg>Added documentation and made slight changes.<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using SQLite.Net.Attributes;
using SQLite.Net.Builders;
using SQLite.Net.Exceptions;
using SQLite.Net.Expressions;
using SQLite.Net.Helpers;
using SQLite.Net.Translation;
using SQLitePCL;

namespace SQLite.Net
{
	public enum TransactionType
	{
		Deferred, Immediate, Exclusive
	}

	/// <summary>
	/// Represents a connection to an SQLite Database.
	/// </summary>
	public abstract class SQLiteDatabase : IDisposable
    {
		static SQLiteDatabase() { Batteries_V2.Init(); }

	    private readonly sqlite3 _db;
	    private readonly SQLiteQueryProvider _provider;

		/// <summary>
		/// The path of the database file this connection represents.
		/// Is null if it is an in-memory database.
		/// </summary>
		public string Path { get; }
		/// <summary>
		/// Is true if the connection to the databse is open.
		/// </summary>
		public bool IsOpen { get; private set; }
		/// <summary>
		/// Set this property to log the SQL generated by this <see cref="SQLiteDatabase"/> to the given delegate.
		/// </summary>
		public Action<string> Log { get; set; }

	    private readonly Stack<string> _transactionStack = new Stack<string>();
		/// <summary>
		/// Number representing how deep in the transaction stack the database is in.
		/// </summary>
	    public int TransactionDepth => _transactionStack.Count;
		/// <summary>
		/// True if the database is currently in a transaction.
		/// </summary>
	    public bool IsInTransaction => TransactionDepth > 0;

		/// <summary>
		/// <returns>The ROWID of the last row insert from the database connection which invoked the function.</returns>
		/// </summary>
		public long LastInsertRowId => raw.sqlite3_last_insert_rowid(_db);
		/// <summary>
		/// <returns>
		/// The number of database rows that were changed or inserted or deleted
		/// by the most recently completed INSERT, DELETE, or UPDATE statement,
		/// exclusive of statements in lower-level triggers.
		/// </returns>
		/// </summary>
		public int Changes => raw.sqlite3_changes(_db);
		/// <summary>
		/// <returns>
		/// This function returns the total number of rows inserted,
		/// modified or deleted by all INSERT, UPDATE or DELETE statements completed
		/// since the database connection was opened,
		/// including those executed as part of trigger programs.
		/// </returns>
		/// </summary>
		public int TotalChanges => raw.sqlite3_total_changes(_db);

	    public TimeSpan BusyTimeout
		{
		    get => TimeSpan.FromMilliseconds(ExecuteScalar<long>("PRAGMA busy_timeout;"));
			set => raw.sqlite3_busy_timeout(_db, (int) value.TotalMilliseconds);
	    }
		/// <summary>
		/// The user-version is an integer that is available to applications to use however they want.
		/// SQLite makes no use of the user-version itself.
		/// 
		/// It is usually used to keep track of migrations.
		/// It's initial value is 0.
		/// </summary>
		public long UserVersion
	    {
		    get => ExecuteScalar<long>("PRAGMA user_version");
		    set => Execute($"PRAGMA user_version = {value}");
	    }
		/// <summary>
		/// Query, set, or clear the enforcement of foreign key constraints.
		/// 
	    /// This pragma is a no-op within a transaction;
	    /// foreign key constraint enforcement may only be enabled or disabled when there is no pending BEGIN or SAVEPOINT.
		/// </summary>
		public bool ForeignKeysEnabled
	    {
			get => ExecuteScalar<bool>("PRAGMA foreign_keys");
		    set => Execute($"PRAGMA foreign_keys = {value}");
		}

		/// <summary>
		/// <para>
		/// Every SQLite database has an SQLITE_MASTER table that defines the schema for the database.
		/// </para>
		/// <para>
		///	For tables, the type field will always be 'table' and the name field will be the name of the table.
		///	For indices, type is equal to 'index', name is the name of the index and tbl_name is the name of the table to which the index belongs.
		/// For both tables and indices, the sql field is the text of the original CREATE TABLE or CREATE INDEX statement that created the table or index.
		/// For automatically created indices (used to implement the PRIMARY KEY or UNIQUE constraints) the sql field is NULL.
		/// </para>
		/// <para>
		/// The SQLITE_MASTER table is read-only.
		/// You cannot change this table using UPDATE, INSERT, or DELETE.
		/// The table is automatically updated by CREATE TABLE, CREATE INDEX, DROP TABLE, and DROP INDEX commands.
		/// </para>
		/// </summary>
		/// 
		/// <example>
		/// So to get a list of all tables in the database, use the following SELECT command:
		///	<code>
		/// SQLiteMaster.Where(o => o.Type == "table").OrderBy(o => o.Name).Select(o => o.Name)
		/// </code>
		/// </example>
		public Table<DatabaseObject> SQLiteMaster { get; }
		/// <summary>
		/// Temporary tables do not appear in the SQLITE_MASTER table.
		/// Temporary tables and their indices and triggers occur in another special table named SQLITE_TEMP_MASTER.
		/// <para>
		/// SQLITE_TEMP_MASTER works just like SQLITE_MASTER,
		/// except that it is only visible to the application that created the temporary tables.
		/// </para>
		/// </summary>
		public Table<DatabaseObject> SQLiteTempMaster { get; }

		/// <summary>
{'fraction_non_alphanumeric': 0.11734932983409879, 'fraction_numerical': 0.0014996719467616458, 'mean_word_length': 2.9562476826103077, 'pattern_counts': {'":': 0, '<': 107, '<?xml version=': 0, '>': 137, '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': '2460705', 'n_tokens_mistral': 3290, 'n_tokens_neox': 3003, 'n_words': 1189}