Skip to content

Instantly share code, notes, and snippets.

View bgrainger's full-sized avatar

Bradley Grainger bgrainger

View GitHub Profile
void Main()
{
using (var writer = new StreamWriter(@"GetValueConversionTestBase.g.cs"))
{
writer.WriteLine("using System;");
writer.WriteLine("using System.CodeDom.Compiler;");
writer.WriteLine("using System.Data;");
writer.WriteLine("using System.Threading.Tasks;");
writer.WriteLine("using Xunit;");
writer.WriteLine("");
@bgrainger
bgrainger / mysql.cs
Created September 15, 2017 18:43
MySQL UPDATE with OUT parameter
// Make sure to set AllowUserVariables=true in connection string
private string SqlLogUpdate => _sqlLogUpdate ?? (_sqlLogUpdate = $@"
Update {_tableName}
Set DuplicateCount = DuplicateCount + @DuplicateCount,
GUID = (@newGUID := GUID) -- set the variable here
Where ErrorHash = @ErrorHash; -- AND ...
Select @newGUID; -- still have to select it to get it back";
protected override bool LogError(Error error)
@bgrainger
bgrainger / FormattableSql.cs
Last active August 14, 2017 23:07
Formattable SQL
void Main()
{
var name = "test";
var state = "WA";
var cmd = new MySqlConnection().CreateCommand($"SELECT * FROM Customers WHERE Name = {name} AND State = {state};");
// cmd.CommandText == "SELECT * FROM Customers WHERE Name = @p0 AND State = @p1;"
}
public static class DbExtensions
{
async Task Main()
{
var httpClient = new HttpClient();
var html57 = await (await httpClient.GetAsync("https://dev.mysql.com/doc/mysql-errors/5.7/en/server-error-reference.html")).Content.ReadAsStringAsync();
var html8 = await (await httpClient.GetAsync("https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html")).Content.ReadAsStringAsync();
var valueNames = new Dictionary<int, string>();
foreach (MySqlErrorCode value in Enum.GetValues(typeof(MySqlErrorCode)))
{
var intValue = (int)value;
@bgrainger
bgrainger / BenchmarkResults.md
Last active February 13, 2023 05:34
Benchmark async/await options in C# 7
BenchmarkDotNet=v0.10.3.0, OS=Microsoft Windows 10.0.14393
Processor=Intel(R) Xeon(R) CPU E5-1650 v3 3.50GHz, ProcessorCount=12
Frequency=3410069 Hz, Resolution=293.2492 ns, Timer=TSC
dotnet cli version=1.0.1
  [Host]     : .NET Core 4.6.25009.03, 64bit RyuJIT
  DefaultJob : .NET Core 4.6.25009.03, 64bit RyuJIT

Method | Mean | StdDev | Gen 0 | Allocated

public class CpuTimer
{
public void Start()
{
m_sw = Stopwatch.StartNew();
using (var process = Process.GetCurrentProcess())
{
m_total = process.TotalProcessorTime;
m_user = process.UserProcessorTime;
m_kernel = process.PrivilegedProcessorTime;
using System;
using MySql.Data.MySqlClient;
namespace MySqlCompressBlob
{
class Program
{
static void Main(string[] args)
{
var csb = new MySqlConnectionStringBuilder
using System;
using MySql.Data.MySqlClient;
namespace MySqlCompressBlob
{
class Program
{
static void Main(string[] args)
{
var csb = new MySqlConnectionStringBuilder
@bgrainger
bgrainger / DeleteWithReverseUnorderedSelects.md
Last active April 9, 2016 05:59
SQLite: DELETE can fail with reverse_unordered_selects = true

DELETE can fail with reverse_unordered_selects = true

Under very specific circumstances DELETE FROM x WHERE col = val may fail to delete all rows if PRAGMA reverse_unordered_selects = true; has been executed.

Steps to repro:

Open the test DB (40KB) with SQLite 3.12.1

Run:

Keybase proof

I hereby claim:

  • I am bgrainger on github.
  • I am bgrainger (https://keybase.io/bgrainger) on keybase.
  • I have a public key ASC7V4yXHiiwteOw05YmgR1XRHmYGCzhVFPn4hz4lAm5KQo

To claim this, I am signing this object: