Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-32113

question_numerical_units->multiplier uses length,decimals (40,20) which the XMLDB editor cannot cope with

XMLWordPrintable

    • MOODLE_22_STABLE, MOODLE_34_STABLE
    • MOODLE_35_STABLE
    • MDL-32113-master-xmldbnumeric
    • Hide

      Requirements

      Automatic tests to be run by cibot

      • Unit tests lib/ddl/tests/ddl_test.php must pass for all supported database engines

      Numerical question type upgrade

      On all supported databases:

      • Check the definition (most notably the precision and scale) of the field 'multiplier' in the 'question_numerical_units' table on current master before applying the patch.
      • Upgrade to the patched version - the upgrade must not fail.
      • Check the field definition again and make sure it is defined as a decimal number with precision 38 digits and scale (number of decimals) 19 digits.

      On all supported databases:

      • Perform a clean installation of the patched version
      • Check the field definition and make sure it is defined as a decimal number with precision 38 digits and scale (number of decimals) 19 digits.

      XMLDB editor tests

      When adding / editing a decimal number field, make sure that:

      • The displayed hint says that the length of the field can be 1...38
      • Check that attempting to define a field with bigger precision (more than 38 digits in total) raises an error and can't be saved.
      • Check that attempting to define a field with more than 20 digits in the whole number part of the decimal number (such as with length like "38,5") raises an error and can't be saved.
      Show
      Requirements It will be less painful if you are familiar with XMLDB and https://github.com/moodlehq/moodle-docker Automatic tests to be run by cibot Unit tests lib/ddl/tests/ddl_test.php must pass for all supported database engines Numerical question type upgrade On all supported databases: Check the definition (most notably the precision and scale) of the field 'multiplier' in the 'question_numerical_units' table on current master before applying the patch. Upgrade to the patched version - the upgrade must not fail. Check the field definition again and make sure it is defined as a decimal number with precision 38 digits and scale (number of decimals) 19 digits. On all supported databases: Perform a clean installation of the patched version Check the field definition and make sure it is defined as a decimal number with precision 38 digits and scale (number of decimals) 19 digits. XMLDB editor tests When adding / editing a decimal number field, make sure that: The displayed hint says that the length of the field can be 1...38 Check that attempting to define a field with bigger precision (more than 38 digits in total) raises an error and can't be saved. Check that attempting to define a field with more than 20 digits in the whole number part of the decimal number (such as with length like "38,5") raises an error and can't be saved.

          <TABLE NAME="question_numerical_units" COMMENT="Optional unit options for numerical questions. This table is also used by the calculated question type." PREVIOUS="question_numerical_options">
            <FIELDS>
              <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="question"/>
              <FIELD NAME="question" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Foreign key references question.id" PREVIOUS="id" NEXT="multiplier"/>
              <FIELD NAME="multiplier" TYPE="number" LENGTH="40" NOTNULL="true" DEFAULT="1.00000000000000000000" SEQUENCE="false" DECIMALS="20" COMMENT="The multiplier for this unit. For example, if the first unit is (1.0, 'cm'), another unit might be (0.1, 'mm') or (100.0, 'm')." PREVIOUS="question" NEXT="unit"/>
              <FIELD NAME="unit" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" COMMENT="The unit. For example 'm' or 'kg'." PREVIOUS="multiplier"/>
            </FIELDS>

      is against the XMLDB docs and XMLDB editor validation. This was discovered in MDL-32112, I have added an ugly workaround there.

      Looking at the code it seems that we could use VARCHAR(50) there without any problems because the column is not used in any SQL condition. Please note that all these high precision numbers must be passed to database as strings and they are also fetched from db as strings (PHP float limitation), so if you do not do any arithmetic operation on it directly in database the db field type should not matter.

      In any case number with 40 digit is NOT going to fit the float PHP type no matter how hard you try. (Grep for 'multiplier' in question/type/numerical/*, you will see PARAM_NUMBER input cleaning and "$xx * $multiplier".)

            mudrd8mz David Mudrák (@mudrd8mz)
            skodak Petr Skoda
            Damyon Wiese Damyon Wiese
            Jun Pataleta Jun Pataleta
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.