Uploaded image for project: 'MariaDB Connector/C'
  1. MariaDB Connector/C
  2. CONC-739

mtr --ps does not print fractional digits for FROM_UNIXTIME('1922.1')

Details

    Description

      The problem is repeatable with all server versions between 10.5 and 11.7.

      I create this MTR test file:

      SELECT FROM_UNIXTIME('1922.1');
      

      If I run "mtr testname", it returns:

      SELECT FROM_UNIXTIME('1922.1');
      FROM_UNIXTIME('1922.1')
      1970-01-01 04:32:02.100000
      

      If I run "mtr --ps testname", it returns

      SELECT FROM_UNIXTIME('1922.1');
      FROM_UNIXTIME('1922.1')
      1970-01-01 04:32:02
      

      Notice there are no fractional digits.

      Attachments

        Activity

          bar Alexander Barkov added a comment - - edited

          The problem probably resides in the function ps_fetch_datetime in the client library, file libmariadb/ma_stmt_codec.c

                case MYSQL_TYPE_TIMESTAMP:
                  length= sprintf(dtbuffer, "%04u-%02u-%02u %02u:%02u:%02u", tm.year, tm.month, tm.day, tm.hour, tm.minute, tm.second);
                  if (field->decimals && field->decimals <= 6)
                  {
                    char ms[8];
                    sprintf(ms, ".%06lu", tm.second_part);
                    if (field->decimals < 6)
                      ms[field->decimals + 1]= 0;
                    length+= strlen(ms);
                    strcat(dtbuffer, ms);
                  }
                  break;
          

          Notice, it does not handle AUTO_SEC_PART_DIGITS (39), so the fractional part is not appended to the string buffer.

          In case field->decimals==AUTO_SEC_PART_DIGITS, the code should print six fractional digits but only if they are not equal to 000000.

          bar Alexander Barkov added a comment - - edited The problem probably resides in the function ps_fetch_datetime in the client library, file libmariadb/ma_stmt_codec.c case MYSQL_TYPE_TIMESTAMP: length= sprintf(dtbuffer, "%04u-%02u-%02u %02u:%02u:%02u" , tm. year , tm. month , tm. day , tm. hour , tm. minute , tm. second ); if (field->decimals && field->decimals <= 6) { char ms[8]; sprintf(ms, ".%06lu" , tm.second_part); if (field->decimals < 6) ms[field->decimals + 1]= 0; length+= strlen(ms); strcat(dtbuffer, ms); } break; Notice, it does not handle AUTO_SEC_PART_DIGITS (39), so the fractional part is not appended to the string buffer. In case field->decimals==AUTO_SEC_PART_DIGITS, the code should print six fractional digits but only if they are not equal to 000000.

          People

            georg Georg Richter
            bar Alexander Barkov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.