Moodle
  1. Moodle
  2. MDL-43884

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

    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 2.6 Branch:
    • Pull Master Branch:
      MDL-43884-master
    • Story Points (Obsolete):
      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.

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            Ankit Agarwal added a comment - - edited

            I have left the $this->prefix !== '' check for backward compatibility.

            Show
            Ankit Agarwal added a comment - - edited I have left the $this->prefix !== '' check for backward compatibility.
            Hide
            CiBoT added a comment -
            Show
            CiBoT added a comment - Results for MDL-43884 Remote repository: git://github.com/ankitagarwal/moodle.git Remote branch MDL-43884 -24 to be integrated into upstream MOODLE_24_STABLE Executed job http://integration.moodle.org/job/Precheck%20remote%20branch/881 Details: http://integration.moodle.org/job/Precheck%20remote%20branch/881/artifact/work/smurf.html Remote branch MDL-43884 -25 to be integrated into upstream MOODLE_25_STABLE Executed job http://integration.moodle.org/job/Precheck%20remote%20branch/882 Details: http://integration.moodle.org/job/Precheck%20remote%20branch/882/artifact/work/smurf.html Remote branch MDL-43884 -26 to be integrated into upstream MOODLE_26_STABLE Executed job http://integration.moodle.org/job/Precheck%20remote%20branch/883 Details: http://integration.moodle.org/job/Precheck%20remote%20branch/883/artifact/work/smurf.html Remote branch MDL-43884 -master to be integrated into upstream master Executed job http://integration.moodle.org/job/Precheck%20remote%20branch/884 Details: http://integration.moodle.org/job/Precheck%20remote%20branch/884/artifact/work/smurf.html
            Hide
            Petr Skoda added a comment -

            +1, sending to integration, thanks!

            Show
            Petr Skoda added a comment - +1, sending to integration, thanks!
            Hide
            Paul Holden added a comment -

            This fixes the mssql_native driver for external databases

            Show
            Paul Holden added a comment - This fixes the mssql_native driver for external databases
            Hide
            CiBoT added a comment -

            Moving this issue to current integration cycle, will be reviewed soon. Thanks for the hard work!

            Show
            CiBoT added a comment - Moving this issue to current integration cycle, will be reviewed soon. Thanks for the hard work!
            Hide
            Sam Hemelryk added a comment -

            Thanks Ankit, this has been integrated now.

            Noting it did not land to 2.4 as that branch is now only receiving security fixes.

            Show
            Sam Hemelryk added a comment - Thanks Ankit, this has been integrated now. Noting it did not land to 2.4 as that branch is now only receiving security fixes.
            Hide
            Michael de Raadt added a comment -

            Test result: Success!

            Tested in 2.5, 2.6 and master on mssql (FreeTDS), sqlsvr (native), MySQL, PostgreSQL and Oracle.

            Show
            Michael de Raadt added a comment - Test result: Success! Tested in 2.5, 2.6 and master on mssql (FreeTDS), sqlsvr (native), MySQL, PostgreSQL and Oracle.
            Hide
            Sam Hemelryk added a comment -

            This weeks weekly release is now available and includes your code.
            A big pat on the back to you again for once more being a cog in the Moodle machine.

            Best wishes, the Moodle integration team.

            Show
            Sam Hemelryk added a comment - This weeks weekly release is now available and includes your code. A big pat on the back to you again for once more being a cog in the Moodle machine. Best wishes, the Moodle integration team.

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Agile