⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqliteconnection.cs

📁 破解的飞信源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace Imps.Client.Data
{
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.Runtime.CompilerServices;
    using System.Text;

    public sealed class SQLiteConnection : ICloneable, IDisposable
    {
        internal bool _binaryGuid;
        internal List<WeakReference> _commandList;
        private SQLiteCommitCallback _commitCallback;
        private ConnectionState _connectionState;
        private string _connectionString;
        private const string _dataDirectory = "|DataDirectory|";
        private string _dataSource;
        private byte[] _password;
        private SQLiteRollbackCallback _rollbackCallback;
        internal SQLiteBase _sql;
        internal int _transactionLevel;
        private SQLiteUpdateCallback _updateCallback;
        internal long _version;

        private event SQLiteCommitHandler _commitHandler;

        private event EventHandler _rollbackHandler;

        private event SQLiteUpdateEventHandler _updateHandler;

        public event SQLiteCommitHandler Commit
        {
            add
            {
                if (this._commitHandler == null)
                {
                    this._commitCallback = new SQLiteCommitCallback(this.CommitCallback);
                    this._sql.SetCommitHook(this._commitCallback);
                }
                this._commitHandler = (SQLiteCommitHandler) Delegate.Combine(this._commitHandler, value);
            }
            remove
            {
                this._commitHandler = (SQLiteCommitHandler) Delegate.Remove(this._commitHandler, value);
                if (this._commitHandler == null)
                {
                    this._sql.SetCommitHook(null);
                    this._commitCallback = null;
                }
            }
        }

        public event EventHandler RollBack
        {
            add
            {
                if (this._rollbackHandler == null)
                {
                    this._rollbackCallback = new SQLiteRollbackCallback(this.RollbackCallback);
                    this._sql.SetRollbackHook(this._rollbackCallback);
                }
                this._rollbackHandler = (EventHandler) Delegate.Combine(this._rollbackHandler, value);
            }
            remove
            {
                this._rollbackHandler = (EventHandler) Delegate.Remove(this._rollbackHandler, value);
                if (this._rollbackHandler == null)
                {
                    this._sql.SetRollbackHook(null);
                    this._rollbackCallback = null;
                }
            }
        }

        public event StateChangeEventHandler StateChange;

        public event SQLiteUpdateEventHandler Update
        {
            add
            {
                if (this._updateHandler == null)
                {
                    this._updateCallback = new SQLiteUpdateCallback(this.UpdateCallback);
                    this._sql.SetUpdateHook(this._updateCallback);
                }
                this._updateHandler = (SQLiteUpdateEventHandler) Delegate.Combine(this._updateHandler, value);
            }
            remove
            {
                this._updateHandler = (SQLiteUpdateEventHandler) Delegate.Remove(this._updateHandler, value);
                if (this._updateHandler == null)
                {
                    this._sql.SetUpdateHook(null);
                    this._updateCallback = null;
                }
            }
        }

        public SQLiteConnection() : this("")
        {
        }

        public SQLiteConnection(SQLiteConnection connection) : this(connection.ConnectionString)
        {
            if (connection.State == ConnectionState.Open)
            {
                this.Open();
            }
        }

        public SQLiteConnection(string connectionString)
        {
            this._sql = null;
            this._connectionState = ConnectionState.Closed;
            this._connectionString = "";
            this._transactionLevel = 0;
            this._version = 0;
            this._commandList = new List<WeakReference>();
            if (connectionString != null)
            {
                this.ConnectionString = connectionString;
            }
        }

        internal void AddCommand(SQLiteCommand cmd)
        {
            lock (this._commandList)
            {
                this._commandList.Add(new WeakReference(cmd, false));
            }
        }

        private SQLiteTransaction BeginDbTransaction(IsolationLevel isolationLevel)
        {
            return this.BeginTransaction(false);
        }

        public SQLiteTransaction BeginTransaction()
        {
            return this.BeginTransaction(false);
        }

        public SQLiteTransaction BeginTransaction(IsolationLevel isolationLevel)
        {
            return this.BeginTransaction(false);
        }

        public SQLiteTransaction BeginTransaction(bool deferredLock)
        {
            if (this._connectionState != ConnectionState.Open)
            {
                throw new InvalidOperationException();
            }
            return new SQLiteTransaction(this, deferredLock);
        }

        public SQLiteTransaction BeginTransaction(IsolationLevel isolationLevel, bool deferredLock)
        {
            return this.BeginTransaction(deferredLock);
        }

        public void ChangeDatabase(string databaseName)
        {
            throw new NotImplementedException();
        }

        public void ChangePassword(byte[] newPassword)
        {
            if (this._connectionState != ConnectionState.Open)
            {
                throw new InvalidOperationException("Database must be opened before changing the password.");
            }
            this._sql.ChangePassword(newPassword);
        }

        public void ChangePassword(string newPassword)
        {
            this.ChangePassword(string.IsNullOrEmpty(newPassword) ? null : Encoding.UTF8.GetBytes(newPassword));
        }

        public object Clone()
        {
            return new SQLiteConnection(this);
        }

        public void Close()
        {
            if (this._sql != null)
            {
                WeakReference[] referenceArray;
                lock (this._commandList)
                {
                    referenceArray = new WeakReference[this._commandList.get_Count()];
                    this._commandList.CopyTo(referenceArray);
                }
                for (int i = 0; i < referenceArray.Length; i++)
                {
                    SQLiteCommand command = null;
                    try
                    {
                        command = referenceArray[i].Target as SQLiteCommand;
                    }
                    catch
                    {
                    }
                    if (command != null)
                    {
                        command.ClearCommands();
                    }
                }
                this._sql.Close();
                this._sql = null;
                this._transactionLevel = 0;
            }
            this.OnStateChange(ConnectionState.Closed);
        }

        private int CommitCallback()
        {
            CommitEventArgs e = new CommitEventArgs();
            this._commitHandler(this, e);
            if (!e.AbortTransaction)
            {
                return 0;
            }
            return 1;
        }

        public static void CompressFile(string databaseFileName)
        {
            UnsafeNativeMethods.sqlite3_compressfile(databaseFileName);
        }

        public SQLiteCommand CreateCommand()
        {
            return new SQLiteCommand(this);
        }

        public static void CreateFile(string databaseFileName)
        {
            File.Create(databaseFileName).Close();
        }

        public static void DecompressFile(string databaseFileName)
        {
            UnsafeNativeMethods.sqlite3_decompressfile(databaseFileName);
        }

        public void Dispose()
        {
            this.Dispose(true);
        }

        private void Dispose(bool disposing)
        {
            if (disposing)
            {
                this.Close();
            }
        }

        private string ExpandFileName(string sourceFile)
        {
            if (!string.IsNullOrEmpty(sourceFile))
            {
                if (!sourceFile.StartsWith("|DataDirectory|", 5))
                {
                    return sourceFile;
                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -