Skip to content

Instantly share code, notes, and snippets.

@bgrainger
Created October 11, 2016 04:34
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/ef06cf4d784a0df414f1a9406c74ccd8 to your computer and use it in GitHub Desktop.
Save bgrainger/ef06cf4d784a0df414f1a9406c74ccd8 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[16519389]; // no exception with new byte[16519388]
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