Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-14434

Wrong result for CHARSET(CONCAT(?,const))

    XMLWordPrintable

    Details

      Description

      This script correctly returns latin1:

      SET NAMES utf8;
      EXECUTE IMMEDIATE "SELECT CHARSET(CONCAT(5,_latin1'a'))";
      

      +-------------------------------+
      | CHARSET(CONCAT(5,_latin1'a')) |
      +-------------------------------+
      | latin1                        |
      +-------------------------------+
      

      If I use a similar query, but pass the number as a parameter, it erroneously returns binary:

      EXECUTE IMMEDIATE "SELECT CHARSET(CONCAT(?,_latin1'a'))" USING 5;
      

      +-------------------------------+
      | CHARSET(CONCAT(?,_latin1'a')) |
      +-------------------------------+
      | binary                        |
      +-------------------------------+
      

      The expected result is to return _latin1.

      The problem happens because Item_param does not set its DTCollation properly. These queries erroneously return 4 (DERIVATION_COERCIBLE), instead of 5 (DERIVATION_NUMERIC).

      EXECUTE IMMEDIATE "SELECT COERCIBILITY(?)" USING 5;
      EXECUTE IMMEDIATE "SELECT COERCIBILITY(?)" USING 5.5;
      EXECUTE IMMEDIATE "SELECT COERCIBILITY(?)" USING 5.5e0;
      EXECUTE IMMEDIATE "SELECT COERCIBILITY(?)" USING TIME'10:20:30';
      EXECUTE IMMEDIATE "SELECT COERCIBILITY(?)" USING TIMESTAMP'2001-01-01 10:20:30';
      

        Attachments

          Activity

            People

            Assignee:
            bar Alexander Barkov
            Reporter:
            bar Alexander Barkov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: