internal static bool IsAutocommit(SQLiteConnectionHandle hdl, IntPtr db)
        {
            if (hdl == null || db == IntPtr.Zero)
            {
                return(false);
            }
            bool flag = false;

            try
            {
            }
            finally
            {
                lock (hdl)
                {
                    if (!hdl.IsInvalid && !hdl.IsClosed)
                    {
                        flag = UnsafeNativeMethods.sqlite3_get_autocommit(db) == 1;
                    }
                }
            }
            GC.KeepAlive(hdl);
            return(flag);
        }
 internal SQLiteChangeSetBase(SQLiteConnectionHandle handle, SQLiteConnectionFlags flags) : base(handle, flags, true)
 {
 }
 internal SQLiteBlobHandle(SQLiteConnectionHandle cnn, IntPtr blob) : this()
 {
     this.cnn = cnn;
     base.SetHandle(blob);
 }
 internal SQLiteBackupHandle(SQLiteConnectionHandle cnn, IntPtr backup) : this()
 {
     this.cnn = cnn;
     base.SetHandle(backup);
 }
示例#5
0
 internal SQLiteStatementHandle(SQLiteConnectionHandle cnn, IntPtr stmt) : this()
 {
     this.cnn = cnn;
     base.SetHandle(stmt);
 }
示例#6
0
 public SQLiteSession(SQLiteConnectionHandle handle, SQLiteConnectionFlags flags, string databaseName) : base(handle, flags, true)
 {
     this.databaseName = databaseName;
     this.InitializeHandle();
 }
示例#7
0
        internal static SQLiteConnectionHandle Remove(string fileName, int maxPoolSize, out int version)
        {
            int num;
            Queue <WeakReference> queue;

            SQLiteConnectionPool.PoolQueue poolQueue;
            SQLiteConnectionPool.PoolQueue poolQueue1;
            bool flag;
            SQLiteConnectionHandle sQLiteConnectionHandle;
            ISQLiteConnectionPool  connectionPool = SQLiteConnectionPool.GetConnectionPool();

            if (connectionPool != null)
            {
                return(connectionPool.Remove(fileName, maxPoolSize, out version) as SQLiteConnectionHandle);
            }
            lock (SQLiteConnectionPool._syncRoot)
            {
                version = SQLiteConnectionPool._poolVersion;
                if (SQLiteConnectionPool._queueList.TryGetValue(fileName, out poolQueue))
                {
                    int poolVersion = poolQueue.PoolVersion;
                    num     = poolVersion;
                    version = poolVersion;
                    poolQueue.MaxPoolSize = maxPoolSize;
                    SQLiteConnectionPool.ResizePool(poolQueue, false);
                    queue = poolQueue.Queue;
                    if (queue != null)
                    {
                        SQLiteConnectionPool._queueList.Remove(fileName);
                        queue = new Queue <WeakReference>(queue);
                        goto Label0;
                    }
                    else
                    {
                        sQLiteConnectionHandle = null;
                    }
                }
                else
                {
                    poolQueue = new SQLiteConnectionPool.PoolQueue(SQLiteConnectionPool._poolVersion, maxPoolSize);
                    SQLiteConnectionPool._queueList.Add(fileName, poolQueue);
                    sQLiteConnectionHandle = null;
                }
            }
            return(sQLiteConnectionHandle);

Label0:
            try
            {
                while (queue.Count > 0)
                {
                    WeakReference weakReference = queue.Dequeue();
                    if (weakReference == null)
                    {
                        continue;
                    }
                    SQLiteConnectionHandle target = weakReference.Target as SQLiteConnectionHandle;
                    if (target == null)
                    {
                        continue;
                    }
                    GC.SuppressFinalize(target);
                    try
                    {
                        GC.WaitForPendingFinalizers();
                        if (!target.IsInvalid && !target.IsClosed)
                        {
                            Interlocked.Increment(ref SQLiteConnectionPool._poolOpened);
                            sQLiteConnectionHandle = target;
                            return(sQLiteConnectionHandle);
                        }
                    }
                    finally
                    {
                        GC.ReRegisterForFinalize(target);
                    }
                    GC.KeepAlive(target);
                }
            }
            finally
            {
                lock (SQLiteConnectionPool._syncRoot)
                {
                    if (!SQLiteConnectionPool._queueList.TryGetValue(fileName, out poolQueue1))
                    {
                        flag       = true;
                        poolQueue1 = new SQLiteConnectionPool.PoolQueue(num, maxPoolSize);
                    }
                    else
                    {
                        flag = false;
                    }
                    Queue <WeakReference> weakReferences = poolQueue1.Queue;
                    while (queue.Count > 0)
                    {
                        weakReferences.Enqueue(queue.Dequeue());
                    }
                    SQLiteConnectionPool.ResizePool(poolQueue1, false);
                    if (flag)
                    {
                        SQLiteConnectionPool._queueList.Add(fileName, poolQueue1);
                    }
                }
            }
            return(null);
        }
        internal override void Open(string strFilename, string vfsName, SQLiteConnectionFlags connectionFlags, SQLiteOpenFlagsEnum openFlags, int maxPoolSize, bool usePool)
        {
            SQLiteErrorCode sQLiteErrorCode;

            if (this._sql != null)
            {
                this.Close(true);
            }
            if (this._sql != null)
            {
                throw new SQLiteException("connection handle is still active");
            }
            this._usePool  = usePool;
            this._fileName = strFilename;
            this._flags    = connectionFlags;
            if (usePool)
            {
                this._sql = SQLiteConnectionPool.Remove(strFilename, maxPoolSize, out this._poolVersion);
                SQLiteConnectionHandle sQLiteConnectionHandle = this._sql;
                object[] objArray = new object[] { typeof(SQLite3_UTF16), strFilename, vfsName, connectionFlags, openFlags, maxPoolSize, usePool, this._poolVersion };
                SQLiteConnection.OnChanged(null, new ConnectionEventArgs(SQLiteConnectionEventType.OpenedFromPool, null, null, null, null, sQLiteConnectionHandle, strFilename, objArray));
            }
            if (this._sql == null)
            {
                try
                {
                }
                finally
                {
                    IntPtr zero = IntPtr.Zero;
                    int    num  = ((connectionFlags & SQLiteConnectionFlags.NoExtensionFunctions) != SQLiteConnectionFlags.NoExtensionFunctions ? 1 : 0);
                    if (vfsName != null || num != 0)
                    {
                        sQLiteErrorCode = UnsafeNativeMethods.sqlite3_open16_interop(SQLiteConvert.ToUTF8(strFilename), SQLiteConvert.ToUTF8(vfsName), openFlags, num, ref zero);
                    }
                    else
                    {
                        if ((openFlags & SQLiteOpenFlagsEnum.Create) != SQLiteOpenFlagsEnum.Create && !File.Exists(strFilename))
                        {
                            throw new SQLiteException(SQLiteErrorCode.CantOpen, strFilename);
                        }
                        if (vfsName != null)
                        {
                            CultureInfo currentCulture = CultureInfo.CurrentCulture;
                            object[]    objArray1      = new object[] { vfsName };
                            throw new SQLiteException(SQLiteErrorCode.CantOpen, HelperMethods.StringFormat(currentCulture, "cannot open using UTF-16 and VFS \"{0}\": need interop assembly", objArray1));
                        }
                        sQLiteErrorCode = UnsafeNativeMethods.sqlite3_open16(strFilename, ref zero);
                    }
                    if (sQLiteErrorCode != SQLiteErrorCode.Ok)
                    {
                        throw new SQLiteException(sQLiteErrorCode, null);
                    }
                    this._sql = new SQLiteConnectionHandle(zero, true);
                }
                lock (this._sql)
                {
                }
                SQLiteConnectionHandle sQLiteConnectionHandle1 = this._sql;
                object[] objArray2 = new object[] { typeof(SQLite3_UTF16), strFilename, vfsName, connectionFlags, openFlags, maxPoolSize, usePool };
                SQLiteConnection.OnChanged(null, new ConnectionEventArgs(SQLiteConnectionEventType.NewCriticalHandle, null, null, null, null, sQLiteConnectionHandle1, strFilename, objArray2));
            }
            if ((connectionFlags & SQLiteConnectionFlags.NoBindFunctions) != SQLiteConnectionFlags.NoBindFunctions)
            {
                if (this._functions == null)
                {
                    this._functions = new Dictionary <SQLiteFunctionAttribute, SQLiteFunction>();
                }
                foreach (KeyValuePair <SQLiteFunctionAttribute, SQLiteFunction> value in SQLiteFunction.BindFunctions(this, connectionFlags))
                {
                    this._functions[value.Key] = value.Value;
                }
            }
            this.SetTimeout(0);
            GC.KeepAlive(this._sql);
        }
 internal SQLiteMemoryChangeSet(byte[] rawData, SQLiteConnectionHandle handle, SQLiteConnectionFlags flags) : base(handle, flags)
 {
     this.rawData = rawData;
 }
示例#10
0
 internal SQLiteStreamChangeSet(Stream inputStream, Stream outputStream, SQLiteConnectionHandle handle, SQLiteConnectionFlags flags) : base(handle, flags)
 {
     this.inputStream  = inputStream;
     this.outputStream = outputStream;
 }