|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Data; |
| 4 | +using System.Data.Common; |
| 5 | +using AdoNet.Specification.Tests; |
| 6 | + |
| 7 | +namespace Conformance.Tests |
| 8 | +{ |
| 9 | + public class SelectValueFixture : ISelectValueFixture |
| 10 | + { |
| 11 | + public SelectValueFixture() |
| 12 | + { |
| 13 | + ConnectionString = new DbFactoryFixture().ConnectionString; |
| 14 | + ExecuteNonQuery(@"create schema if not exists mysqltest;"); |
| 15 | + |
| 16 | + ConnectionString += ";Database=mysqltest"; |
| 17 | + ExecuteNonQuery(@"drop table if exists select_value; |
| 18 | +create table select_value |
| 19 | +( |
| 20 | + Id int not null primary key, |
| 21 | + `Binary` blob, |
| 22 | + Boolean bool, |
| 23 | + Byte tinyint unsigned, |
| 24 | + SByte tinyint, |
| 25 | + Int16 smallint, |
| 26 | + UInt16 smallint unsigned, |
| 27 | + Int32 int, |
| 28 | + UInt32 int unsigned, |
| 29 | + Int64 bigint, |
| 30 | + UInt64 bigint unsigned, |
| 31 | + Single float, |
| 32 | + `Double` double, |
| 33 | + `Decimal` decimal(57,28), |
| 34 | + String text, |
| 35 | + Guid char(36), |
| 36 | + `Date` date, |
| 37 | + `DateTime` datetime(3), |
| 38 | + `Time` time(3) |
| 39 | +); |
| 40 | +insert into select_value values |
| 41 | +(0, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null), |
| 42 | +(1, X'', null, null, null, null, null, null, null, null, null, null, null, null, '', '', null, null, null), |
| 43 | +(2, X'00', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '0', '00000000-0000-0000-0000-000000000000', null, null, '00:00:00'), |
| 44 | +(3, X'11', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, '1', '11111111-1111-1111-1111-111111111111', '1111-11-11', '1111-11-11 11:11:11.111', '11:11:11.111'), |
| 45 | +(4, null, false, 0, -128, -32768, 0, -2147483648, 0, -9223372036854775808, 0, 1.18e-38, 2.23e-308, 0.000000000000001, null, '33221100-5544-7766-9988-aabbccddeeff', '1000-01-01', '1000-01-01 00:00:00', '-838:59:59'), |
| 46 | +(5, null, true, 255, 127, 32767, 65535, 2147483647, 4294967295, 9223372036854775807, 18446744073709551615, 3.40e38, 1.79e308, 99999999999999999999.999999999999999, null, 'ccddeeff-aabb-8899-7766-554433221100', '9999-12-31', '9999-12-31 23:59:59.999', '838:59:59'); |
| 47 | +"); |
| 48 | + } |
| 49 | + |
| 50 | + public string ConnectionString { get; } |
| 51 | + |
| 52 | + public DbProviderFactory Factory => MySql.Data.MySqlClient.MySqlClientFactory.Instance; |
| 53 | + |
| 54 | + public void DropSelectValueTable(IDbFactoryFixture factoryFixture) => ExecuteNonQuery("drop table if exists select_value;"); |
| 55 | + |
| 56 | + public string CreateSelectSql(DbType dbType, ValueKind kind) => $"SELECT `{dbType.ToString()}` from select_value WHERE Id = {(int) kind};"; |
| 57 | + |
| 58 | + public string CreateSelectSql(byte[] value) => $"SELECT X'{BitConverter.ToString(value).Replace("-", "")}'"; |
| 59 | + |
| 60 | + public string SelectNoRows => "SELECT * FROM mysql.user WHERE 0 = 1;"; |
| 61 | + |
| 62 | + public IReadOnlyCollection<DbType> SupportedDbTypes { get; } = new[] |
| 63 | + { |
| 64 | + DbType.Binary, |
| 65 | + DbType.Boolean, |
| 66 | + DbType.Byte, |
| 67 | + DbType.Date, |
| 68 | + DbType.DateTime, |
| 69 | + DbType.Decimal, |
| 70 | + DbType.Double, |
| 71 | + DbType.Guid, |
| 72 | + DbType.Int16, |
| 73 | + DbType.Int32, |
| 74 | + DbType.Int64, |
| 75 | + DbType.SByte, |
| 76 | + DbType.Single, |
| 77 | + DbType.String, |
| 78 | + DbType.Time, |
| 79 | + DbType.UInt16, |
| 80 | + DbType.UInt32, |
| 81 | + DbType.UInt64, |
| 82 | + }; |
| 83 | + |
| 84 | + private void ExecuteNonQuery(string sql) |
| 85 | + { |
| 86 | + using (var connection = Factory.CreateConnection()) |
| 87 | + { |
| 88 | + connection.ConnectionString = ConnectionString; |
| 89 | + connection.Open(); |
| 90 | + |
| 91 | + using (var command = connection.CreateCommand()) |
| 92 | + { |
| 93 | + command.CommandText = sql; |
| 94 | + command.ExecuteNonQuery(); |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + } |
| 99 | +} |
0 commit comments