Пример #1
0
            public BlobSizesConnection(BlobSizes blobSizes, string connectionString)
            {
                this.BlobSizesDatabase = blobSizes;
                this.connectionString  = connectionString;
                this.shaBuffer         = new byte[20];

                try
                {
                    this.connection = new SqliteConnection(this.connectionString);
                    this.connection.Open();

                    using (SqliteCommand pragmaReadUncommittedCommand = this.connection.CreateCommand())
                    {
                        // A database connection in read-uncommitted mode does not attempt to obtain read-locks
                        // before reading from database tables as described above. This can lead to inconsistent
                        // query results if another database connection modifies a table while it is being read,
                        // but it also means that a read-transaction opened by a connection in read-uncommitted
                        // mode can neither block nor be blocked by any other connection
                        // http://www.sqlite.org/pragma.html#pragma_read_uncommitted
                        pragmaReadUncommittedCommand.CommandText = $"PRAGMA read_uncommitted=1;";
                        pragmaReadUncommittedCommand.ExecuteNonQuery();
                    }

                    this.querySizeCommand = this.connection.CreateCommand();

                    this.shaParam = this.querySizeCommand.CreateParameter();
                    this.shaParam.ParameterName = "@sha";

                    this.querySizeCommand.CommandText = "SELECT size FROM BlobSizes WHERE sha = (@sha);";
                    this.querySizeCommand.Parameters.Add(this.shaParam);
                    this.querySizeCommand.Prepare();
                }
                catch (Exception e)
                {
                    if (this.querySizeCommand != null)
                    {
                        this.querySizeCommand.Dispose();
                        this.querySizeCommand = null;
                    }

                    if (this.connection != null)
                    {
                        this.connection.Dispose();
                        this.connection = null;
                    }

                    throw new BlobSizesException(e);
                }
            }
Пример #2
0
 public BlobSizesConnection(BlobSizes blobSizes)
 {
     // For unit testing
     this.BlobSizesDatabase = blobSizes;
 }