TileCook.MBTilesCache.Put C# (CSharp) Method

Put() public method

public Put ( Coord coord, string Format, byte image ) : void
coord Coord
Format string
image byte
return void
        public void Put(Coord coord, string Format, byte[] image)
        {
            int z = coord.Z;
            int x = coord.X;
            int y = coord.Y;

            if (Format.Equals(this._format, StringComparison.OrdinalIgnoreCase))
            {
                if (this._isCompressed)
                {
                    string uuid = Guid.NewGuid().ToString();
                    using (SQLiteConnection con = new SQLiteConnection((string.Format("Data Source={0}", this.Database))))
                    {
                        con.Open();
                        using (SQLiteCommand cmd = new SQLiteCommand(con))
                        {
                            using (SQLiteTransaction tran = con.BeginTransaction())
                            {
                                //insert into map table
                                cmd.CommandText = "REPLACE INTO map (zoom_level, tile_column, tile_row, tile_id) VALUES (@z,@x,@y,@uuid)";
                                cmd.Parameters.AddWithValue("@z", z);
                                cmd.Parameters.AddWithValue("@x", x);
                                cmd.Parameters.AddWithValue("@y", y);
                                cmd.Parameters.AddWithValue("@uuid", uuid);
                                cmd.ExecuteNonQuery();

                                //clear paramaters
                                cmd.Parameters.Clear();

                                //insert into images table
                                cmd.CommandText = "REPLACE INTO images (tile_id, tile_data) VALUES (@uuid, @img)";
                                cmd.Parameters.AddWithValue("@uuid", uuid);
                                cmd.Parameters.AddWithValue("@img", image);
                                cmd.ExecuteNonQuery();

                                tran.Commit();
                            }
                        }
                    }
                }
                else
                {
                    using (SQLiteConnection con = new SQLiteConnection((string.Format("Data Source={0}", this.Database))))
                    {
                        con.Open();
                        string query = "REPLACE INTO tiles (zoom_level, tile_column, tile_row, tile_data) VALUES (@z,@x,@y,@img)";
                        using (SQLiteCommand cmd = new SQLiteCommand(query, con))
                        {
                            cmd.Parameters.AddWithValue("@z", z);
                            cmd.Parameters.AddWithValue("@x", x);
                            cmd.Parameters.AddWithValue("@y", y);
                            cmd.Parameters.AddWithValue("@img", image);
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
            }
        }