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

Allow DEFAULT NULL clause in CHAR columns

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Waiting for peer review
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.9.2
    • Fix Version/s: None
    • Component/s: Database SQL/XMLDB
    • Testing Instructions:
      Hide
      • Define a database table with a CHAR column allowing null values and no default in your db/install.xml file. In the top XMLDB element, add the ALLOWDEFAULTNULLCHAR="true" attribute.
      • Install the database using a fresh install (upgrades don't read this file).
      • Insert a row without providing a value for this column. It should work creating a row where this column's value is NULL, before this patch it would be initialized with an empty string.
      Show
      Define a database table with a CHAR column allowing null values and no default in your db/install.xml file. In the top XMLDB element, add the ALLOWDEFAULTNULLCHAR="true" attribute. Install the database using a fresh install (upgrades don't read this file). Insert a row without providing a value for this column. It should work creating a row where this column's value is NULL, before this patch it would be initialized with an empty string.
    • Affected Branches:
      MOODLE_39_STABLE
    • Pull Master Branch:
      MDL-69821-master

      Description

      As described in MDL-9658, the way databases are created at the moment it's not possible to create a CHAR column that uses the DEFAULT NULL clause. Instead, those columns are declared as DEFAULT '', which is misleading when those columns are defined using NOTNULL="false".

      The ideal situation would be to allow declarations such as the following to work as expected:

      <FIELD NAME="name" TYPE="char" LENGTH="100" NOTNULL="false" SEQUENCE="false"/>

      And use the following if the desired outcome is the DEFAULT '' clause:

      <FIELD NAME="name" TYPE="char" LENGTH="100" NOTNULL="true" DEFAULT="" SEQUENCE="false"/>

      However, doing this change now would break a lot of existing code, so this must be implemented as an opt-in first. Later on, this can be changed to opt-out. Eventually, this behavior could be deprecated entirely.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              noeldemartin Noel De Martin
              Reporter:
              noeldemartin Noel De Martin
              Participants:
              Component watchers:
              Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 30 minutes
                  30m