예제 #1
0
        private static int[] ExecuteIntegerArrayQueryImpl(SQLiteConnection connection, string query, int queryIndex, object[] keys)
        {
            try
            {
                if (CacheManager.Connection != connection.GetDbPointer()) // don't cache this
                {
                    return ExecuteIntegerArrayQuerySots(connection, query, keys);
                }

                if (!_queryCaches.ContainsKey(queryIndex))
                {
                    _queryCaches[queryIndex] = new ColumnCache<int[]>(query);
                }
                ColumnCache<int[]> cache = (ColumnCache<int[]>)_queryCaches[queryIndex];

                if (cache.Ignore)
                {
                    return ExecuteIntegerArrayQuerySots(connection, query, keys);
                }

                var ts = cache.GetTS(keys);
                var key = BuildKey(keys);

                if (CacheManager.Invalidations.IsInvalidated(ts, cache.Tables))
                {
                    cache.Clear();
                }

                int[] foundItem = new int[0];

                var found = cache.TryGetItem(key, out foundItem);

                if (!found)
                {
                    foundItem = ExecuteIntegerArrayQuerySots(connection, query, keys);
                    cache.SetItem(key, foundItem);
                }
                return foundItem;
            }
            catch (Exception ex)
            {
                Sotsos_DebugHelper.SotsosLog("Error in ExecuteIntegerArrayQuery while trying to run query {0}, idx {1}", query, queryIndex);
                throw;
            }
        }
예제 #2
0
        //SELECT * FROM government_actions  ORDER BY id DESC LIMIT 50;
        private static Table ExecuteTableQueryImpl(SQLiteConnection connection, bool splitQuery, string query, object[] keys, int queryIndex)
        {
            try
            {
                if (CacheManager.Connection != connection.GetDbPointer()) // don't cache this
                {
                    return ExecuteTableQuerySots(connection, splitQuery, query, keys);
                }

                if (!_queryCaches.ContainsKey(queryIndex))
                {
                    _queryCaches[queryIndex] = new FullQueryCache(query);
                }
                FullQueryCache cache = (FullQueryCache)_queryCaches[queryIndex];

                if (cache.Ignore)
                {
                    return ExecuteTableQuerySots(connection, splitQuery, query, keys);
                }

                var ts = cache.GetTS(keys);
                var key = BuildKey(keys);

                if (CacheManager.Invalidations.IsInvalidated(ts, cache.Tables))
                {
                    cache.Clear();
                }

                var foundTable = cache.GetItem(key);

                if (foundTable == null)
                {
                    foundTable = ExecuteTableQuerySots(connection, splitQuery, query, keys);
                    foundTable.Rows = foundTable.Rows.Select(r => new SotsosRow(r)).ToArray<Row>(); //Use SotsosRow wrapper so we can cache parsed values
                    cache.SetItem(key, foundTable);
                }
                return foundTable;
            }
            catch(Exception ex)
            {
                Sotsos_DebugHelper.SotsosLog("Error in ExecuteTableQueryImpl while trying to run query {0}, idx {1}", query, queryIndex);
                throw;
            }
        }