Пример #1
0
 public StatementBuilder(DBConnection c, string tableName)
 {
     Database = c;
     Data = new ParameterList(c);
     Parameters = new ParameterList(c);
     TableName = tableName;
     SkipTableHeader = string.Format("{0}.", TableName);
 }
Пример #2
0
 public UpdateStatement(DBConnection database, string tableName, string whereClause)
     : base(database, tableName)
 {
     WhereClause = whereClause;
 }
Пример #3
0
        /// <summary>
        /// If configured, this function reads from a SQLite database caching previously known hashes.
        /// The motivation for this is that the most expensive operation would be the MD5 hash calculation;
        /// That means that on a second run of DetectDuplicates, we may want to reuse existing known MD5 hashes.
        /// </summary>
        public bool Initialize(string database_filename, Dictionary<long, Dictionary<string, string>> cache)
        {
            if (string.IsNullOrEmpty(database_filename))
                return false;

            Filename = database_filename;

            try
            {
                // connect to database
                Trace.TraceInformation("About to read cache from \"{0}\"", Filename);
                Database = new Database("Data Source=" + Filename);

                // make sure lookup table exists
                Database.ExecuteNonQuery(@"CREATE TABLE IF NOT EXISTS hashes (hash TEXT, filename TEXT);");

                DateTime cacheStartTime = DateTime.Now;

                // read known hashes from lookup table
                int CachedHashesRead = 0;
                using (SelectStatement ss = new SelectStatement(Database, "SELECT hash, filename FROM hashes", null))
                {
                    while (ss.Next())
                    {
                        string hash = ss.AsText(0);
                        string filename = ss.AsText(1);
                        CacheValues[filename.ToLower()] = hash;
                        ++CachedHashesRead;
                    }
                }
                if (CachedHashesRead == 0)
                {
                    Console.WriteLine("Cache is empty as of yet...");
                }
                else
                {
                    TimeSpan elapsed = DateTime.Now - cacheStartTime;
                    Console.WriteLine("Read {0} hashes from the cache in {1}...", CachedHashesRead, elapsed);
                }
                return true;
            }
            catch (Exception e)
            {
                Tools.DumpException(e, "ReadCache() caught an exception while reading \"{0}\"", Filename);
                return false;
            }
        }
Пример #4
0
 public InsertStatement(DBConnection database, string tableName)
     : base(database, tableName)
 {
 }