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

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

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: Future Dev
    • Fix Version/s: None
    • Component/s: Database SQL/XMLDB
    • Labels:

      Description

      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) {
        // ...
      }
      $rs->close();

       

       

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            brendanheywood Brendan Heywood
            Participants:
            Component watchers:
            Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: