Bug #100159 SQL with DateTime parameter returns String value
Submitted: 8 Jul 15:11 Modified: 24 Jul 16:46
Reporter: Andrey Belykh Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:8.0.20 OS:Microsoft Windows
Assigned to: CPU Architecture:x86

[8 Jul 15:11] Andrey Belykh
Description:
SQL with DateTime parameter returns String value

How to repeat:
using System;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using MySql.Data.MySqlClient;
namespace ConsoleApp44
{
    class Program
    {
        static void Main(string[] args)
        {
            string connectionString = "Data Source=DBTEST;Database=sakila;SslMode=None;User ID=root;Password=Dundas123;";
            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                connection.Open();
                string sql = "SELECT ?p0 as datevalue";
                using (MySqlCommand command = new MySqlCommand(sql, connection))
                {
                    command.Parameters.AddWithValue("?p0", DateTime.UtcNow);
                    using (MySqlDataReader reader = command.ExecuteReader())
                    {
                        using (DataTable schema = reader.GetSchemaTable())
                        {
                            MySqlDbType providerType = (MySqlDbType)schema.Rows[0].Field<int>(SchemaTableColumn.ProviderType);
                            Debug.WriteLine(providerType);
                        }
                    }
                }
            }
        }
    }
}
[8 Jul 20:37] Andrey Belykh
Current (incorrect) output: VarChar

Expected output: DateTime
[9 Jul 7:05] MySQL Verification Team
Hello Andrey,

Thank you for the report and test case.

regards,
Umesh
[24 Jul 16:46] Christine Cole
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/NET 8.0.22 release, and here's the proposed changelog entry from the documentation team:

A valid query parameter of type DateTime was misinterpreted as a string
value.

Thank you for the bug report.