/// <summary>
        /// Clears out all pooled connections and rev's up the default pool version to force all old active objects
        /// not in the pool to get discarded rather than returned to their pools.
        /// </summary>
        internal static void ClearAllPools()
        {
            lock (_connections) {
                foreach (KeyValuePair <string, Pool> pair in _connections)
                {
                    while (pair.Value.Queue.Count > 0)
                    {
                        WeakReference          cnn = pair.Value.Queue.Dequeue();
                        SqliteConnectionHandle hdl = cnn.Target as SqliteConnectionHandle;
                        if (hdl != null)
                        {
                            hdl.Dispose();
                        }
                    }

                    // Keep track of the highest revision so we can go one higher when we're finished
                    if (_poolVersion <= pair.Value.PoolVersion)
                    {
                        _poolVersion = pair.Value.PoolVersion + 1;
                    }
                }
                // All pools are cleared and we have a new highest version number to force all old version active items to get discarded
                // instead of going back to the queue when they are closed.
                // We can get away with this because we're pumped up the _poolVersion out of range of all active connections, so they
                // will all get discarded when they try to put themselves back in their pool.
                _connections.Clear();
            }
        }
        public static int sqlite3_table_column_metadata(
            SqliteConnectionHandle connection,
            string database, string table, string column,
            out string dataTypePtr, out string collSeqPtr,
            out int nnotNull, out int nprimaryKey, out int nautoInc)
        {
            string realdataTypePtr = null;
            string realcollSeqPtr  = null;
            int    realnnotNull    = 0;
            int    realnprimaryKey = 0;
            int    realnautoInc    = 0;

            var result = Community.CsharpSqlite.Sqlite3.sqlite3_table_column_metadata(
                connection.Handle,
                database, table, column,
                ref realdataTypePtr, ref realcollSeqPtr,
                ref realnnotNull, ref realnprimaryKey, ref realnautoInc);

            dataTypePtr = realdataTypePtr;
            collSeqPtr  = realcollSeqPtr;
            nnotNull    = realnnotNull;
            nprimaryKey = realnprimaryKey;
            nautoInc    = realnautoInc;

            return(result);
        }
        public static void sqlite3_exec(SqliteConnectionHandle connection, string query, out string msg)
        {
            string realMsg = null;

            Community.CsharpSqlite.Sqlite3.sqlite3_exec(connection.Handle, query, null, null, ref realMsg);
            msg = realMsg;
        }
Пример #4
0
 internal static void Dispose(this SqliteConnectionHandle connection)
 {
     try {
         SqliteBase.CloseConnection(connection);
     }
     catch (SqliteException) {
     }
 }
        public static int sqlite3_open(string filename, out SqliteConnectionHandle connection)
        {
            Community.CsharpSqlite.Sqlite3.sqlite3 innerConn;
            var res = Community.CsharpSqlite.Sqlite3.sqlite3_open(filename, out innerConn);

            connection = new SqliteConnectionHandle(innerConn);
            return(res);
        }
        public static int sqlite3_prepare16(
            SqliteConnectionHandle connection, string sql, int sqlLength,
            out SqliteStatementHandle statement, out string remainingSql)
        {
            SqliteStatementHandle innerStmt;
            var res = sqlite3_prepare(connection, sql, sqlLength, out innerStmt, out remainingSql);

            statement = innerStmt;
            return(res);
        }
        public static SqliteStatementHandle sqlite3_next_stmt(SqliteConnectionHandle connection, SqliteStatementHandle statement)
        {
            var res = Community.CsharpSqlite.Sqlite3.sqlite3_next_stmt(connection.Handle, statement == null ? null : statement.Handle);

            if (res == null)
            {
                return(null);
            }
            return(new SqliteStatementHandle(res));
        }
Пример #8
0
 internal static void CloseConnection(SqliteConnectionHandle db)
 {
     lock (_lock) {
         ResetConnection(db);
         int n = UnsafeNativeMethods.sqlite3_close(db);
         if (n > 0)
         {
             throw new SqliteException(n, SqliteLastError(db));
         }
     }
 }
        public static int sqlite3_prepare(
            SqliteConnectionHandle connection, string sql, int sqlLength,
            out SqliteStatementHandle statement, out string remainingSql)
        {
            Community.CsharpSqlite.Sqlite3.Vdbe stmt = null;
            string remSql = null;
            var    result = Community.CsharpSqlite.Sqlite3.sqlite3_prepare(connection.Handle, sql, sqlLength, ref stmt, ref remSql);

            statement    = new SqliteStatementHandle(stmt);
            remainingSql = remSql;
            return(result);
        }
Пример #10
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)
                {
                    ResetConnection(_sql);
                    SqliteConnectionPool.Add(_fileName, _sql, _poolVersion);
                }
                else
                {
                    _sql.Dispose();
                }
            }

            _sql = null;
        }
 /// <summary>
 /// Return a connection to the pool for someone else to use.
 /// </summary>
 /// <param name="fileName">The filename of the pool to use</param>
 /// <param name="hdl">The connection handle to pool</param>
 /// <param name="version">The pool version the handle was created under</param>
 /// <remarks>
 /// If the version numbers don't match between the connection and the pool, then the handle is discarded.
 /// </remarks>
 internal static void Add(string fileName, SqliteConnectionHandle hdl, int version)
 {
     lock (_connections) {
         // If the queue doesn't exist in the pool, then it must've been cleared sometime after the connection was created.
         Pool queue;
         if (_connections.TryGetValue(fileName, out queue) == true && version == queue.PoolVersion)
         {
             ResizePool(queue, true);
             queue.Queue.Enqueue(new WeakReference(hdl, false));
             GC.KeepAlive(hdl);
         }
         else
         {
             hdl.Dispose();
         }
     }
 }
Пример #12
0
        internal static void ResetConnection(SqliteConnectionHandle db)
        {
            lock (_lock) {
                SqliteStatementHandle stmt = null;
                do
                {
                    stmt = UnsafeNativeMethods.sqlite3_next_stmt(db, stmt);
                    if (stmt != null)
                    {
                        UnsafeNativeMethods.sqlite3_reset(stmt);
                    }
                } while (stmt != null);

                // Not overly concerned with the return value from a rollback.
                string msg = null;
                UnsafeNativeMethods.sqlite3_exec(db, "ROLLBACK", out msg);
            }
        }
        private static void ResizePool(Pool queue, bool forAdding)
        {
            int target = queue.MaxPoolSize;

            if (forAdding && target > 0)
            {
                target--;
            }

            while (queue.Queue.Count > target)
            {
                WeakReference          cnn = queue.Queue.Dequeue();
                SqliteConnectionHandle hdl = cnn.Target as SqliteConnectionHandle;
                if (hdl != null)
                {
                    hdl.Dispose();
                }
            }
        }
 /// <summary>
 /// Clear a given pool for a given filename.  Discards anything in the pool for the given file, and revs the pool
 /// version so current active objects on the old version of the pool will get discarded rather than be returned to the pool.
 /// </summary>
 /// <param name="fileName">The filename of the pool to clear</param>
 internal static void ClearPool(string fileName)
 {
     lock (_connections) {
         Pool queue;
         if (_connections.TryGetValue(fileName, out queue) == true)
         {
             queue.PoolVersion++;
             while (queue.Queue.Count > 0)
             {
                 WeakReference          cnn = queue.Queue.Dequeue();
                 SqliteConnectionHandle hdl = cnn.Target as SqliteConnectionHandle;
                 if (hdl != null)
                 {
                     hdl.Dispose();
                 }
             }
         }
     }
 }
        /// <summary>
        /// Attempt to pull a pooled connection out of the queue for active duty
        /// </summary>
        /// <param name="fileName">The filename for a desired connection</param>
        /// <param name="maxPoolSize">The maximum size the connection pool for the filename can be</param>
        /// <param name="version">The pool version the returned connection will belong to</param>
        /// <returns>Returns NULL if no connections were available.  Even if none are, the poolversion will still be a valid pool version</returns>
        internal static SqliteConnectionHandle Remove(string fileName, int maxPoolSize, out int version)
        {
            lock (_connections) {
                Pool queue;

                // Default to the highest pool version
                version = _poolVersion;

                // If we didn't find a pool for this file, create one even though it will be empty.
                // We have to do this here because otherwise calling ClearPool() on the file will not work for active connections
                // that have never seen the pool yet.
                if (_connections.TryGetValue(fileName, out queue) == false)
                {
                    queue = new Pool(_poolVersion, maxPoolSize);
                    _connections.Add(fileName, queue);

                    return(null);
                }

                // We found a pool for this file, so use its version number
                version           = queue.PoolVersion;
                queue.MaxPoolSize = maxPoolSize;

                ResizePool(queue, false);

                // Try and get a pooled connection from the queue
                while (queue.Queue.Count > 0)
                {
                    WeakReference          cnn = queue.Queue.Dequeue();
                    SqliteConnectionHandle hdl = cnn.Target as SqliteConnectionHandle;
                    if (hdl != null)
                    {
                        return(hdl);
                    }
                }
                return(null);
            }
        }
Пример #16
0
 public static int sqlite3_close(SqliteConnectionHandle db)
 {
     throw new System.NotImplementedException();
 }
Пример #17
0
        internal static void ResetConnection(SqliteConnectionHandle db) {
            lock (_lock) {
                SqliteStatementHandle stmt = null;
                do {
                    stmt = UnsafeNativeMethods.sqlite3_next_stmt(db, stmt);
                    if (stmt != null) {
                        UnsafeNativeMethods.sqlite3_reset(stmt);
                    }
                } while (stmt != null);

                // Not overly concerned with the return value from a rollback.
                string msg = null;
                UnsafeNativeMethods.sqlite3_exec(db, "ROLLBACK", out msg);
            }
        }
Пример #18
0
        // These statics are here for lack of a better place to put them.
        // They exist here because they are called during the finalization of
        // a SqliteStatementHandle, SqliteConnectionHandle, and SqliteFunctionCookieHandle.
        // Therefore these functions have to be static, and have to be low-level.

        internal static string SqliteLastError(SqliteConnectionHandle db) {
            return UTF8ToString(UnsafeNativeMethods.sqlite3_errmsg(db), -1);
        }
 public static int sqlite3_table_column_metadata(SqliteConnectionHandle db, string dbName, string tableName, string columnName, out string dataType, out string collSeq, out int notNull, out int primaryKey, out int autoInc) { throw new System.NotImplementedException(); }
 public static int sqlite3_prepare16(SqliteConnectionHandle db, string query, int length, out SqliteStatementHandle statement, out string strRemain) { throw new System.NotImplementedException(); }
 public static int sqlite3_open16(string filename, out SqliteConnectionHandle db) { throw new System.NotImplementedException(); }
 public static int sqlite3_close(SqliteConnectionHandle connection)
 {
     return Community.CsharpSqlite.Sqlite3.sqlite3_close(connection.Handle);
 }
        public static int sqlite3_table_column_metadata(
            SqliteConnectionHandle connection,
            string database, string table, string column,
            out string dataTypePtr, out string collSeqPtr,
            out int nnotNull, out int nprimaryKey, out int nautoInc)
        {
            string realdataTypePtr = null;
            string realcollSeqPtr = null;
            int realnnotNull = 0;
            int realnprimaryKey = 0;
            int realnautoInc = 0;

            var result = Community.CsharpSqlite.Sqlite3.sqlite3_table_column_metadata(
                connection.Handle,
                database, table, column,
                ref realdataTypePtr, ref realcollSeqPtr,
                ref realnnotNull, ref realnprimaryKey, ref realnautoInc);

            dataTypePtr = realdataTypePtr;
            collSeqPtr = realcollSeqPtr;
            nnotNull = realnnotNull;
            nprimaryKey = realnprimaryKey;
            nautoInc = realnautoInc;

            return result;
        }
 public static object sqlite3_update_hook(SqliteConnectionHandle connection, SqliteUpdateHookDelegate callback, object arg)
 {
     return Community.CsharpSqlite.Sqlite3.sqlite3_update_hook(connection.Handle, (a, b, c, d, e) => callback(a, b, c, d, e), arg);
 }
 public static object sqlite3_rollback_hook(SqliteConnectionHandle connection, SqliteRollbackHookDelegate callback, object arg)
 {
     return Community.CsharpSqlite.Sqlite3.sqlite3_rollback_hook(connection.Handle, (a) => callback(a), arg);
 }
 public static int sqlite3_open(string filename, out SqliteConnectionHandle connection)
 {
     Community.CsharpSqlite.Sqlite3.sqlite3 innerConn;
     var res = Community.CsharpSqlite.Sqlite3.sqlite3_open(filename, out innerConn);
     connection = new SqliteConnectionHandle(innerConn);
     return res;
 }
 public static int sqlite3_open16(string filename, out SqliteConnectionHandle connection)
 {
     return sqlite3_open(filename, out connection);
 }
 public static void sqlite3_exec(SqliteConnectionHandle connection, string query, out string msg)
 {
     string realMsg = null;
     Community.CsharpSqlite.Sqlite3.sqlite3_exec(connection.Handle, query, null, null, ref realMsg);
     msg = realMsg;
 }
 public static string sqlite3_errmsg(SqliteConnectionHandle connection)
 {
     return Community.CsharpSqlite.Sqlite3.sqlite3_errmsg(connection.Handle);
 }
Пример #30
0
 public static int sqlite3_exec(SqliteConnectionHandle db, string query, out string errmsg)
 {
     throw new System.NotImplementedException();
 }
Пример #31
0
 public static long sqlite3_last_insert_rowid(SqliteConnectionHandle db)
 {
     throw new System.NotImplementedException();
 }
 public static string sqlite3_errmsg(SqliteConnectionHandle connection)
 {
     return(Community.CsharpSqlite.Sqlite3.sqlite3_errmsg(connection.Handle));
 }
 public static int sqlite3_open_v2(string filename, out SqliteConnectionHandle db, int flags, string zVfs) { throw new System.NotImplementedException(); }
 public static int sqlite3_close(SqliteConnectionHandle connection)
 {
     return(Community.CsharpSqlite.Sqlite3.sqlite3_close(connection.Handle));
 }
 public static int sqlite3_prepare_v2(SqliteConnectionHandle db, string query, out SqliteStatementHandle statement) { throw new System.NotImplementedException(); }
Пример #36
0
 public static int sqlite3_open_v2(string filename, out SqliteConnectionHandle db, int flags, string zVfs)
 {
     throw new System.NotImplementedException();
 }
 public static int sqlite3_rekey(SqliteConnectionHandle db, string key, int length) { throw new System.NotImplementedException(); }
Пример #38
0
 public static int sqlite3_prepare_v2(SqliteConnectionHandle db, string query, out SqliteStatementHandle statement)
 {
     throw new System.NotImplementedException();
 }
 public static void sqlite3_update_hook(SqliteConnectionHandle db, SqliteUpdateHookDelegate callback, object userState) { throw new System.NotImplementedException(); }
Пример #40
0
 public static int sqlite3_rekey(SqliteConnectionHandle db, string key, int length)
 {
     throw new System.NotImplementedException();
 }
Пример #41
0
 internal static void CloseConnection(SqliteConnectionHandle db) {
     lock (_lock) {
         ResetConnection(db);
         int n = UnsafeNativeMethods.sqlite3_close(db);
         if (n > 0) throw new SqliteException(n, SqliteLastError(db));
     }
 }
Пример #42
0
 public static void sqlite3_update_hook(SqliteConnectionHandle db, SqliteUpdateHookDelegate callback, object userState)
 {
     throw new System.NotImplementedException();
 }
Пример #43
0
 public static int sqlite3_busy_timeout(SqliteConnectionHandle db, int miliseconds)
 {
     throw new System.NotImplementedException();
 }
 public static int sqlite3_prepare(
     SqliteConnectionHandle connection, string sql, int sqlLength,
     out SqliteStatementHandle statement, out string remainingSql)
 {
     Community.CsharpSqlite.Sqlite3.Vdbe stmt = null;
     string remSql = null;
     var result = Community.CsharpSqlite.Sqlite3.sqlite3_prepare(connection.Handle, sql, sqlLength, ref stmt, ref remSql);
     statement = new SqliteStatementHandle(stmt);
     remainingSql = remSql;
     return result;
 }
Пример #45
0
 public static string sqlite3_errmsg(SqliteConnectionHandle db)
 {
     throw new System.NotImplementedException();
 }
 public static long sqlite3_last_insert_rowid(SqliteConnectionHandle db) { throw new System.NotImplementedException(); }
Пример #47
0
 public static void sqlite3_interrupt(SqliteConnectionHandle db)
 {
     throw new System.NotImplementedException();
 }
 public static SqliteStatementHandle sqlite3_next_stmt(SqliteConnectionHandle db, SqliteStatementHandle statement) { throw new System.NotImplementedException(); }
Пример #49
0
 public static SqliteStatementHandle sqlite3_next_stmt(SqliteConnectionHandle db, SqliteStatementHandle statement)
 {
     throw new System.NotImplementedException();
 }
 public static SqliteStatementHandle sqlite3_next_stmt(SqliteConnectionHandle connection, SqliteStatementHandle statement)
 {
     var res = Community.CsharpSqlite.Sqlite3.sqlite3_next_stmt(connection.Handle, statement == null ? null : statement.Handle);
     if (res == null)
         return null;
     return new SqliteStatementHandle(res);
 }
Пример #51
0
 public static int sqlite3_open16(string filename, out SqliteConnectionHandle db)
 {
     throw new System.NotImplementedException();
 }
 public static int sqlite3_busy_timeout(SqliteConnectionHandle db, int miliseconds) { throw new System.NotImplementedException(); }
Пример #53
0
 public static int sqlite3_prepare16(SqliteConnectionHandle db, string query, int length, out SqliteStatementHandle statement, out string strRemain)
 {
     throw new System.NotImplementedException();
 }
 public static int sqlite3_close(SqliteConnectionHandle db) { throw new System.NotImplementedException(); }
Пример #55
0
 public static int sqlite3_table_column_metadata(SqliteConnectionHandle db, string dbName, string tableName, string columnName, out string dataType, out string collSeq, out int notNull, out int primaryKey, out int autoInc)
 {
     throw new System.NotImplementedException();
 }
 public static string sqlite3_errmsg(SqliteConnectionHandle db) { throw new System.NotImplementedException(); }
 /// <summary>
 /// Return a connection to the pool for someone else to use.
 /// </summary>
 /// <param name="fileName">The filename of the pool to use</param>
 /// <param name="hdl">The connection handle to pool</param>
 /// <param name="version">The pool version the handle was created under</param>
 /// <remarks>
 /// If the version numbers don't match between the connection and the pool, then the handle is discarded.
 /// </remarks>
 internal static void Add(string fileName, SqliteConnectionHandle hdl, int version)
 {
   lock (_connections)
   {
     // If the queue doesn't exist in the pool, then it must've been cleared sometime after the connection was created.
     Pool queue;
     if (_connections.TryGetValue(fileName, out queue) == true && version == queue.PoolVersion)
     {
       ResizePool(queue, true);
       queue.Queue.Enqueue(new WeakReference(hdl, false));
       GC.KeepAlive(hdl);
     }
     else
     {
       hdl.Dispose();
     }
   }
 }
 public static int sqlite3_exec(SqliteConnectionHandle db, string query, out string errmsg) { throw new System.NotImplementedException(); }
Пример #59
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);
        }
 public static void sqlite3_interrupt(SqliteConnectionHandle db) { throw new System.NotImplementedException(); }