Skip to content

Instantly share code, notes, and snippets.

@bgrainger
Created October 11, 2016 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgrainger/76b3125bd643801e11285851c62da730 to your computer and use it in GitHub Desktop.
Save bgrainger/76b3125bd643801e11285851c62da730 to your computer and use it in GitHub Desktop.
using System;
using MySql.Data.MySqlClient;
namespace MySqlCompressBlob
{
class Program
{
static void Main(string[] args)
{
var csb = new MySqlConnectionStringBuilder
{
Server = "localhost",
Database = "test",
UserID = "root",
Password = /* redacted */
UseCompression = true,
};
using (var connection = new MySqlConnection(csb.ConnectionString))
{
connection.Open();
using (var cmd = new MySqlCommand("drop table if exists test.blobs; create table test.blobs(data longblob)", connection))
cmd.ExecuteNonQuery();
var bytes = new byte[16519390]; // causes http://bugs.mysql.com/bug.php?id=83329 with new byte[16519389]
var random = new Random(1);
random.NextBytes(bytes);
using (var cmd = new MySqlCommand("insert into test.blobs(data) values(@data);", connection))
{
cmd.Parameters.AddWithValue("data", bytes);
cmd.ExecuteNonQuery();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment