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

sql_order_by_text() definition wrong for MSSQL/sqlsrv

    Details

      Description

      The arguments used in the MSSQL version of sql_order_by_text() appear to be incorrect. In current master:

          public function sql_order_by_text($fieldname, $numchars=32) {
              return ' CONVERT(varchar, ' . $fieldname . ', ' . $numchars . ')';
          }
      

      But according to these docs: http://msdn.microsoft.com/en-us/library/ms187928.aspx

      The CONVERT function accepts length as part of the 1st argument and the 3rd argument is used for date and time styles.

      The result that this function is always converting text fields using the MSSQL default length of 30 characters.

      Steps to reproduce

      1. Install a new site on MSSQL.
      2. Add the test.php file (attached to this bug) to the root code folder.
      3. Visit [site-url]/test.php in a web browser.

      Expected behaviour

      The script would output:

      Without using sql_order_by_text():         123456789a123456789b123456789c123456789d
      With sql_order_by_text() default length:   123456789a123456789b123456789c12
      With sql_order_by_text() 35 char length:   123456789a123456789b123456789c12345
      

      Actual behaviour
      The script outputs:

      Without using sql_order_by_text():         123456789a123456789b123456789c123456789d
      With sql_order_by_text() default length:   123456789a123456789b123456789c
      With sql_order_by_text() 35 char length:   123456789a123456789b123456789c
      

      e.g. the default length is incorrect (30 instead of 32 characters) and changing the length has no effect.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Votes:
                  1 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    9/Sep/13