Skip to content

Commit f8a0a40

Browse files
committed
Use C# 11 UTF-8 string literals.
1 parent 5d59444 commit f8a0a40

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,7 @@ protected override void OnStatementBegin(int index)
19191919
private readonly string m_sql;
19201920
}
19211921

1922-
private static ReadOnlySpan<byte> BeginCertificateBytes => new byte[] { 45, 45, 45, 45, 45, 66, 69, 71, 73, 78, 32, 67, 69, 82, 84, 73, 70, 73, 67, 65, 84, 69, 45, 45, 45, 45, 45 }; // -----BEGIN CERTIFICATE-----
1922+
private static ReadOnlySpan<byte> BeginCertificateBytes => "-----BEGIN CERTIFICATE-----";
19231923
private static readonly IMySqlConnectorLogger Log = MySqlConnectorLogManager.CreateLogger(nameof(ServerSession));
19241924
private static readonly PayloadData s_setNamesUtf8NoAttributesPayload = QueryPayload.Create(false, "SET NAMES utf8;");
19251925
private static readonly PayloadData s_setNamesUtf8mb4NoAttributesPayload = QueryPayload.Create(false, "SET NAMES utf8mb4;");

src/MySqlConnector/Core/ServerVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public ServerVersion(ReadOnlySpan<byte> versionString)
3939
if (versionString.Length != 0 && versionString[0] == 0x2D)
4040
{
4141
versionString = versionString.Slice(1);
42-
ReadOnlySpan<byte> mariaDb = new byte[] { 0x2D, 0x4D, 0x61, 0x72, 0x69, 0x61, 0x44, 0x42 }; // -MariaDB
42+
ReadOnlySpan<byte> mariaDb = "-MariaDB";
4343
var mariaDbIndex = versionString.IndexOf(mariaDb);
4444
if (mariaDbIndex != -1)
4545
{

src/MySqlConnector/Core/SingleCommandPayloadCreator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,19 @@ private static bool WriteCommand(IMySqlCommand command, ByteBufferWriter writer,
249249
var isSingleRow = (command.CommandBehavior & CommandBehavior.SingleRow) != 0;
250250
if (isSchemaOnly)
251251
{
252-
ReadOnlySpan<byte> setSqlSelectLimit0 = new byte[] { 83, 69, 84, 32, 115, 113, 108, 95, 115, 101, 108, 101, 99, 116, 95, 108, 105, 109, 105, 116, 61, 48, 59, 10 }; // SET sql_select_limit=0;\n
252+
ReadOnlySpan<byte> setSqlSelectLimit0 = "SET sql_select_limit=0;\n";
253253
writer.Write(setSqlSelectLimit0);
254254
}
255255
else if (isSingleRow)
256256
{
257-
ReadOnlySpan<byte> setSqlSelectLimit1 = new byte[] { 83, 69, 84, 32, 115, 113, 108, 95, 115, 101, 108, 101, 99, 116, 95, 108, 105, 109, 105, 116, 61, 49, 59, 10 }; // SET sql_select_limit=1;\n
257+
ReadOnlySpan<byte> setSqlSelectLimit1 = "SET sql_select_limit=1;\n";
258258
writer.Write(setSqlSelectLimit1);
259259
}
260260
var preparer = new StatementPreparer(command.CommandText!, command.RawParameters, command.CreateStatementPreparerOptions() | ((appendSemicolon || isSchemaOnly || isSingleRow) ? StatementPreparerOptions.AppendSemicolon : StatementPreparerOptions.None));
261261
var isComplete = preparer.ParseAndBindParameters(writer);
262262
if (isComplete && (isSchemaOnly || isSingleRow))
263263
{
264-
ReadOnlySpan<byte> clearSqlSelectLimit = new byte[] { 10, 83, 69, 84, 32, 115, 113, 108, 95, 115, 101, 108, 101, 99, 116, 95, 108, 105, 109, 105, 116, 61, 100, 101, 102, 97, 117, 108, 116, 59 }; // \nSET sql_select_limit=default;
264+
ReadOnlySpan<byte> clearSqlSelectLimit = "\nSET sql_select_limit=default;";
265265
writer.Write(clearSqlSelectLimit);
266266
}
267267
return isComplete;

src/MySqlConnector/MySqlBulkCopy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ static bool WriteValue(MySqlConnection connection, object value, ref int inputIn
448448

449449
if (value is null || value == DBNull.Value)
450450
{
451-
ReadOnlySpan<byte> escapedNull = new byte[] { 0x5C, 0x4E };
451+
ReadOnlySpan<byte> escapedNull = @"\N"; // a field value of \N is read as NULL for input
452452
if (output.Length < escapedNull.Length)
453453
{
454454
bytesWritten = 0;
@@ -672,7 +672,7 @@ static bool WriteSubstring(string value, ref int inputIndex, ref Encoder? utf8En
672672

673673
static bool WriteBytes(ReadOnlySpan<byte> value, ref int inputIndex, Span<byte> output, out int bytesWritten)
674674
{
675-
ReadOnlySpan<byte> hex = new byte[] { (byte) '0', (byte) '1', (byte) '2', (byte) '3', (byte) '4', (byte) '5', (byte) '6', (byte) '7', (byte) '8', (byte) '9', (byte) 'A', (byte) 'B', (byte) 'C', (byte) 'D', (byte) 'E', (byte) 'F' };
675+
ReadOnlySpan<byte> hex = "0123456789ABCDEF";
676676
bytesWritten = 0;
677677
for (; inputIndex < value.Length && output.Length > 2; inputIndex++)
678678
{

src/MySqlConnector/MySqlParameter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ internal void AppendSqlString(ByteBufferWriter writer, StatementPreparerOptions
199199

200200
if (Value is null || Value == DBNull.Value)
201201
{
202-
ReadOnlySpan<byte> nullBytes = new byte[] { 0x4E, 0x55, 0x4C, 0x4C }; // NULL
202+
ReadOnlySpan<byte> nullBytes = "NULL";
203203
writer.Write(nullBytes);
204204
}
205205
#if NET45
@@ -316,8 +316,8 @@ internal void AppendSqlString(ByteBufferWriter writer, StatementPreparerOptions
316316
}
317317
else if (Value is bool boolValue)
318318
{
319-
ReadOnlySpan<byte> trueBytes = new byte[] { 0x74, 0x72, 0x75, 0x65 }; // true
320-
ReadOnlySpan<byte> falseBytes = new byte[] { 0x66, 0x61, 0x6C, 0x73, 0x65 }; // false
319+
ReadOnlySpan<byte> trueBytes = "true";
320+
ReadOnlySpan<byte> falseBytes = "false";
321321
writer.Write(boolValue ? trueBytes : falseBytes);
322322
}
323323
else if (Value is float or double)
@@ -825,7 +825,7 @@ private static void WriteTime(ByteBufferWriter writer, TimeSpan timeSpan)
825825
}
826826
}
827827

828-
private static ReadOnlySpan<byte> BinaryBytes => new byte[] { 0x5F, 0x62, 0x69, 0x6E, 0x61, 0x72, 0x79, 0x27 }; // _binary'
828+
private static ReadOnlySpan<byte> BinaryBytes => "_binary'";
829829

830830
private DbType m_dbType;
831831
private MySqlDbType m_mySqlDbType;

0 commit comments

Comments
 (0)