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

$DB->get_tables() returns empty array for external databases.

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide
      1. This needs to be tested on all databases including both native/freetds MSSQL (your Moodle can be on any single DB, but all supported DBs should be tested using the script below)
      2. Create a script with code below and put it in your Moodle root:-

        <?php
        require_once('config.php');
        $dbtype = 'mysqli';
        $dblibrary = 'native';
        $targetdb = moodle_database::get_driver_instance($dbtype, $dblibrary, true);
        $targetdb->connect($data->dbhost, $data->dbuser, $data->dbpass, $data->dbname, false, $dboptions);
        $tables = $targetdb->get_tables();
        print_object($tables);
        

        (Replace all database properties with the details of the DB you are connecting to)

      3. Make sure you get a proper list printed of tables in your DB printed and not an empty array.
      Show
      This needs to be tested on all databases including both native/freetds MSSQL (your Moodle can be on any single DB, but all supported DBs should be tested using the script below) Create a script with code below and put it in your Moodle root:- <?php require_once('config.php'); $dbtype = 'mysqli'; $dblibrary = 'native'; $targetdb = moodle_database::get_driver_instance($dbtype, $dblibrary, true); $targetdb->connect($data->dbhost, $data->dbuser, $data->dbpass, $data->dbname, false, $dboptions); $tables = $targetdb->get_tables(); print_object($tables); (Replace all database properties with the details of the DB you are connecting to) Make sure you get a proper list printed of tables in your DB printed and not an empty array.
    • Affected Branches:
      MOODLE_26_STABLE
    • Fixed Branches:
      MOODLE_25_STABLE, MOODLE_26_STABLE
    • Pull Master Branch:
      MDL-43884-master
    • Story Points:
      5
    • Sprint:
      BACKEND Sprint 10

      Description

      For external databases we pass $db->prefix as false while connecting, where as in get_tables() we have the following check:-

      if ($this->prefix !== '')
      

      This results in empty result as the above condition is never met and the driver considers $prefix to be a valid prefix.

      I have noticed this in PGSQL, but this could be a bug with other drivers too.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  10/Mar/14