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

Different behaviour of databases when inserting into "not null text" field

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Minor Minor
    • None
    • 1.6.6, 1.7.4, 1.8.5, 1.9
    • Database SQL/XMLDB
    • None
    • MySQL, PostgreSQL
    • MOODLE_16_STABLE, MOODLE_17_STABLE, MOODLE_18_STABLE, MOODLE_19_STABLE

      I have discovered strange behaviour of MySQL server potentially causing a bug when inserting into the table.

      Steps to reproduce
      ============
      1. use a Moodle database at a postgres server
      2. look at the definition of the field "description" in the table "mdl_event". It is defined as "text not null" with no default value
      3. try to insert a row using query with missing "description", e.g.:

      INSERT INTO mdl_event ( NAME, COURSEID, GROUPID, USERID, MODULENAME, INSTANCE, TIMEMODIFIED ) VALUES ( 'Just a test', 2, 0, 0, 'certificate', 4, 1208986893 )

      4. PostgreSQL complains as expected:

      ERROR: null value in column "description" violates not-null constraint

      5. try steps #1 - #3 at a mysql installation

      What I expected
      ==========
      MySQL should throw an error as well.

      What actually happened
      ===============
      New row is inserted with no problem. There is an empty string in the field "description"

      This may lead to problems if developer uses MySQL server. Actually, the query mentioned above causes CONTRIB-387. Maybe we should review the code and look for places where data are inserted into tables with a "not null text" field defined.

      I am not able to test other database systems.

            stronk7 Eloy Lafuente (stronk7)
            mudrd8mz David Mudrák (@mudrd8mz)
            Nobody Nobody (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

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