Bug #82292 GetFieldType mis-reports / changes mid-query for nullable booleans
Submitted: 20 Jul 2016 13:40 Modified: 10 Aug 2022 17:35
Reporter: Marc Gravell Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.9.9 OS:Any
Assigned to: CPU Architecture:Any

[20 Jul 2016 13:40] Marc Gravell
Description:
When querying nullable boolean fields, the declared field type (reader.GetFieldType(n)) changes **mid-query**. This is terribad. If you want to return boolean: fine, return boolean. If you want to return sbyte: fine, return sbyte. But you **cannot** change your mind mid query. See https://github.com/StackExchange/dapper-dot-net/issues/552#issuecomment-233943190 for context etc.

How to repeat:
demo setup:

CREATE TEMPORARY TABLE IF NOT EXISTS `bar` (
  `id` INT NOT NULL,
  `bool_val` BOOL NULL,
  PRIMARY KEY (`id`));
  
  truncate table bar;
  insert bar (id, bool_val) values (1, null);
  insert bar (id, bool_val) values (2, 0);
  insert bar (id, bool_val) values (3, 1);
  insert bar (id, bool_val) values (4, null);
  insert bar (id, bool_val) values (5, 1);
  insert bar (id, bool_val) values (6, 0);
  insert bar (id, bool_val) values (7, null);
  insert bar (id, bool_val) values (8, 1);

with query:

    select * from bar;

now look at reader.GetFieldType(1) initially (before the first Read()), after the first Read(), and after the second Read(). It changes from `Boolean` to `SByte` between two rows.

Suggested fix:
Decide what data type you want to return. Return that data type (or null/dbnull), and **only** that. Don't change your mind.
[20 Jul 2016 20:14] Bradley Grainger
This may be a duplicate of https://bugs.mysql.com/bug.php?id=78917.
[20 Jul 2016 22:12] Gabriela Martinez Sanchez
Thanks Marc for the bug report and feedback. We'll try to include it in the next maintenance release of MySQL Connector/Net.

Duplicated also from 
http://bugs.mysql.com/bug.php?id=79196
[10 Aug 2022 17:35] Daniel Valdez
This issue is no longer happening. Please use our latest release, Connector/NET 8.0.30.