|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
| 3 | +using System.IO; |
3 | 4 | using System.Text;
|
4 | 5 | using Dapper;
|
5 | 6 | #if BASELINE
|
@@ -129,11 +130,10 @@ public void InsertAndQuery(bool isPrepared, string dataType, object dataValue, M
|
129 | 130 |
|
130 | 131 | [Theory]
|
131 | 132 | [MemberData(nameof(GetInsertAndQueryData))]
|
132 |
| - public void InsertAndQueryInferrredType(bool isPrepared, string dataType, object dataValue, MySqlDbType dbType) |
| 133 | + public void InsertAndQueryInferredType(bool isPrepared, string dataType, object dataValue, MySqlDbType dbType) |
133 | 134 | {
|
134 | 135 | GC.KeepAlive(dbType); // ignore the parameter
|
135 |
| - var csb = new MySqlConnectionStringBuilder(AppConfig.ConnectionString); |
136 |
| - using var connection = new MySqlConnection(csb.ConnectionString); |
| 136 | + using var connection = new MySqlConnection(AppConfig.ConnectionString); |
137 | 137 | connection.Open();
|
138 | 138 | connection.Execute($@"DROP TABLE IF EXISTS prepared_command_test;
|
139 | 139 | CREATE TABLE prepared_command_test(rowid INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, data {dataType});");
|
@@ -167,6 +167,40 @@ public void InsertAndQueryInferrredType(bool isPrepared, string dataType, object
|
167 | 167 | }
|
168 | 168 | }
|
169 | 169 |
|
| 170 | +#if !NETCOREAPP1_1_2 |
| 171 | + [Theory] |
| 172 | + [MemberData(nameof(GetDifferentTypeInsertAndQueryData))] |
| 173 | + public void InsertAndQueryDifferentType(bool isPrepared, string dataType, object dataValue, object expectedValue) |
| 174 | + { |
| 175 | + using var connection = new MySqlConnection(AppConfig.ConnectionString); |
| 176 | + connection.Open(); |
| 177 | + connection.Execute($@"DROP TABLE IF EXISTS prepared_command_test; |
| 178 | +CREATE TABLE prepared_command_test(rowid INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, data {dataType});"); |
| 179 | + |
| 180 | + using (var command = new MySqlCommand("INSERT INTO prepared_command_test(data) VALUES(@param);", connection)) |
| 181 | + { |
| 182 | + command.Parameters.AddWithValue("@param", dataValue); |
| 183 | + if (isPrepared) |
| 184 | + command.Prepare(); |
| 185 | + command.ExecuteNonQuery(); |
| 186 | + } |
| 187 | + |
| 188 | + using (var command = new MySqlCommand("SELECT data FROM prepared_command_test ORDER BY rowid;", connection)) |
| 189 | + { |
| 190 | + if (isPrepared) |
| 191 | + command.Prepare(); |
| 192 | + |
| 193 | + using var reader = command.ExecuteReader(); |
| 194 | + Assert.True(reader.Read()); |
| 195 | + Assert.False(reader.IsDBNull(0)); |
| 196 | + Assert.Equal(expectedValue, reader.GetValue(0)); |
| 197 | + |
| 198 | + Assert.False(reader.Read()); |
| 199 | + Assert.False(reader.NextResult()); |
| 200 | + } |
| 201 | + } |
| 202 | +#endif |
| 203 | + |
170 | 204 | [SkippableTheory(Baseline = "https://bugs.mysql.com/bug.php?id=14115")]
|
171 | 205 | [MemberData(nameof(GetInsertAndQueryData))]
|
172 | 206 | public void InsertAndQueryMultipleStatements(bool isPrepared, string dataType, object dataValue, MySqlDbType dbType)
|
@@ -390,6 +424,28 @@ public static IEnumerable<object[]> GetInsertAndQueryData()
|
390 | 424 | }
|
391 | 425 | }
|
392 | 426 | }
|
| 427 | + public static IEnumerable<object[]> GetDifferentTypeInsertAndQueryData() |
| 428 | + { |
| 429 | + foreach (var isPrepared in new[] { false, true }) |
| 430 | + { |
| 431 | + yield return new object[] { isPrepared, "TINYINT", -123, (sbyte) -123 }; |
| 432 | + yield return new object[] { isPrepared, "TINYINT UNSIGNED", 123, (byte) 123 }; |
| 433 | + yield return new object[] { isPrepared, "SMALLINT", -12345, (short) -12345 }; |
| 434 | + yield return new object[] { isPrepared, "SMALLINT UNSIGNED", 12345, (ushort) 12345 }; |
| 435 | + yield return new object[] { isPrepared, "TINYINT", FileMode.Open, (sbyte) 3 }; |
| 436 | + yield return new object[] { isPrepared, "TINYINT", (int) FileMode.Open, (sbyte) 3 }; |
| 437 | + yield return new object[] { isPrepared, "INT", FileMode.Open, 3 }; |
| 438 | + yield return new object[] { isPrepared, "MEDIUMINT", -1234567, -1234567 }; |
| 439 | + yield return new object[] { isPrepared, "MEDIUMINT UNSIGNED", 1234567, 1234567u }; |
| 440 | + yield return new object[] { isPrepared, "INT", (sbyte) -123, -123 }; |
| 441 | + yield return new object[] { isPrepared, "INT", -123456789L, -123456789 }; |
| 442 | + yield return new object[] { isPrepared, "INT UNSIGNED", (sbyte) 123, 123u }; |
| 443 | + yield return new object[] { isPrepared, "INT UNSIGNED", (byte) 123, 123u }; |
| 444 | + yield return new object[] { isPrepared, "INT UNSIGNED", 123456789ul, 123456789u }; |
| 445 | + yield return new object[] { isPrepared, "BIGINT", -123456789, -123456789L }; |
| 446 | + yield return new object[] { isPrepared, "BIGINT UNSIGNED", 123456789U, 123456789UL }; |
| 447 | + } |
| 448 | + } |
393 | 449 |
|
394 | 450 | private static MySqlConnection CreateConnection()
|
395 | 451 | {
|
|
0 commit comments