Exemplo n.º 1
0
        internal override void Open(string strFilename, SQLiteOpenFlagsEnum flags, int maxPoolSize, bool usePool)
        {
            if (_sql != null)
            {
                return;
            }

            _usePool = usePool;
            if (usePool)
            {
                _fileName = strFilename;
                _sql      = SqliteConnectionPool.Remove(strFilename, maxPoolSize, out _poolVersion);
            }

            if (_sql == null)
            {
                if ((flags & SQLiteOpenFlagsEnum.Create) == 0 && FileExists(strFilename) == false)
                {
                    throw new SqliteException((int)SQLiteErrorCode.CantOpen, strFilename);
                }

                SqliteConnectionHandle db;
                int n = UnsafeNativeMethods.sqlite3_open_v2(ToUTF8(strFilename), out db, (int)flags, string.Empty);
                if (n > 0)
                {
                    throw new SqliteException(n, null);
                }

                _sql = db;
            }
            // Bind functions to this connection.  If any previous functions of the same name
            // were already bound, then the new bindings replace the old.
            _functionsArray = SqliteFunction.BindFunctions(this);
            SetTimeout(0);
        }
Exemplo n.º 2
0
        internal override void Open(string strFilename, SQLiteOpenFlagsEnum flags, int maxPoolSize, bool usePool)
        {
            if (_sql != null)
            {
                return;
            }

            _usePool = usePool;
            if (usePool)
            {
                _fileName = strFilename;
                _sql      = SqliteConnectionPool.Remove(strFilename, maxPoolSize, out _poolVersion);
            }

            if (_sql == null)
            {
                SqliteConnectionHandle db;

                if ((flags & SQLiteOpenFlagsEnum.Create) == 0 && FileExists(strFilename) == false)
                {
                    throw new SqliteException((int)SQLiteErrorCode.CantOpen, strFilename);
                }

                int n = UnsafeNativeMethods.sqlite3_open16(strFilename, out db);
                if (n > 0)
                {
                    throw new SqliteException(n, null);
                }

                _sql = db;
            }

            _functionsArray = SqliteFunction.BindFunctions(this);
        }
Exemplo n.º 3
0
        // It isn't necessary to cleanup any functions we've registered.  If the connection
        // goes to the pool and is resurrected later, re-registered functions will overwrite the
        // previous functions.  The SqliteFunctionCookieHandle will take care of freeing unmanaged
        // resources belonging to the previously-registered functions.
        internal override void Close()
        {
            if (_sql != null)
            {
                if (_usePool)
                {
                    SQLiteBase.ResetConnection(_sql);
                    SqliteConnectionPool.Add(_fileName, _sql, _poolVersion);
                }
                else
                {
                    _sql.Dispose();
                }
            }

            _sql = null;
        }
Exemplo n.º 4
0
        internal override void Open(string strFilename, SQLiteOpenFlagsEnum flags, int maxPoolSize, bool usePool)
        {
            if (_sql != null)
            {
                return;
            }

            _usePool = usePool;
            if (usePool)
            {
                _fileName = strFilename;
                _sql      = SqliteConnectionPool.Remove(strFilename, maxPoolSize, out _poolVersion);
            }

            if (_sql == null)
            {
                IntPtr db;

#if !SQLITE_STANDARD
                int n = UnsafeNativeMethods.sqlite3_open_interop(ToUTF8(strFilename), (int)flags, out db);
#else
                // Compatibility with versions < 3.5.0
                int n;

                if (UnsafeNativeMethods.use_sqlite3_open_v2)
                {
                    n = UnsafeNativeMethods.sqlite3_open_v2(ToUTF8(strFilename), out db, (int)flags, IntPtr.Zero);
                }
                else
                {
                    Console.WriteLine("Your sqlite3 version is old - please upgrade to at least v3.5.0!");
                    n = UnsafeNativeMethods.sqlite3_open(ToUTF8(strFilename), out db);
                }
#endif
                if (n > 0)
                {
                    throw new SqliteException(n, null);
                }

                _sql = db;
            }
            // Bind functions to this connection.  If any previous functions of the same name
            // were already bound, then the new bindings replace the old.
            _functionsArray = SqliteFunction.BindFunctions(this);
            SetTimeout(0);
        }
Exemplo n.º 5
0
        // It isn't necessary to cleanup any functions we've registered.  If the connection
        // goes to the pool and is resurrected later, re-registered functions will overwrite the
        // previous functions.  The SqliteFunctionCookieHandle will take care of freeing unmanaged
        // resources belonging to the previously-registered functions.
        internal override void Close()
        {
            if (_sql != null)
            {
                if (_usePool)
                {
                    SQLiteBase.ResetConnection(_sql);
                    SqliteConnectionPool.Add(_fileName, _sql, _poolVersion);
                }
                else
                {
                    _sql.Dispose();
                }
            }

            _sql = null;
#if MONOTOUCH
            if (gch.IsAllocated)
            {
                gch.Free();
            }
#endif
        }
Exemplo n.º 6
0
        internal override void Open(string strFilename, SQLiteOpenFlagsEnum flags, int maxPoolSize, bool usePool)
        {
            if (_sql != null)
            {
                return;
            }

            _usePool = usePool;
            if (usePool)
            {
                _fileName = strFilename;
                _sql      = SqliteConnectionPool.Remove(strFilename, maxPoolSize, out _poolVersion);
            }

            if (_sql == null)
            {
                IntPtr db;

#if !SQLITE_STANDARD
                int n = UnsafeNativeMethods.sqlite3_open16_interop(ToUTF8(strFilename), (int)flags, out db);
#else
                if ((flags & SQLiteOpenFlagsEnum.Create) == 0 && System.IO.File.Exists(strFilename) == false)
                {
                    throw new SqliteException((int)SQLiteErrorCode.CantOpen, strFilename);
                }

                int n = UnsafeNativeMethods.sqlite3_open16(strFilename, out db);
#endif
                if (n > 0)
                {
                    throw new SqliteException(n, null);
                }

                _sql = db;
            }
            _functionsArray = SqliteFunction.BindFunctions(this);
        }
Exemplo n.º 7
0
 internal override void ClearPool()
 {
     SqliteConnectionPool.ClearPool(_fileName);
 }
 /// <summary>
 /// Clears all connection pools.  Any active connections will be discarded instead of sent to the pool when they are closed.
 /// </summary>
 public static void ClearAllPools()
 {
     SqliteConnectionPool.ClearAllPools();
 }