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

Add a new $DB api allowing access to sql field name metadata


    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • Future Dev
    • Database SQL/XMLDB

      There are a bunch of use cases where you are working with arbitrary sql and you need access to the field names. Generally this is straight forward except in the case where no rows are returned.

      For most of the DB api methods there isn't an obvious way to grab the metadata, perhaps we could introduce a new methods which grabs the metadata for the most recent call but that seems slightly ugly and we'd have to process and store a bunch of data that in most cases is never used.

      So I'm thinking a good compromise is adding a new method just for recordsets which returns an ordered array of the field names (and maybe types too?), eg:

      $rs = $DB->get_recordset_sql($sql);
      $rs->get_fields(); <<<--------- THIS
      foreach ($rs as $record) {
        // ...



            Unassigned Unassigned
            brendanheywood Brendan Heywood
            0 Vote for this issue
            2 Start watching this issue


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