Moodle
  1. Moodle
  2. MDL-28193

Cannot use external postgres database without table prefix

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1, 2.2
    • Fix Version/s: 2.1.1
    • Component/s: Libraries
    • Labels:
    • Database:
      PostgreSQL
    • Testing Instructions:
      Hide

      calling the following code snippet currently throws an error:


      <?php

      define('CLI_SCRIPT', true);

      require('config.php');

      $authdb = moodle_database::get_driver_instance('pgsql', 'native');

      $authdb->connect('localhost', 'moodle', 'moodle', 'example_external_database', false);


      Expected result: It works!
      Actual result:


      www-data@moodle:/home/nicols/git/software/moodle$ php example.php
      Default exception handler: <p>Error: database table prefix cannot be empty (postgres)</p>
      <p>The site administrator must fix this problem.</p> Debug:

      • line 125 of /lib/dml/pgsql_native_moodle_database.php: dml_exception thrown
      • line 9 of /example.php: call to pgsql_native_moodle_database->connect()

      !!! <p>Error: database table prefix cannot be empty (postgres)</p>
      <p>The site administrator must fix this problem.</p> !!!
      !! Stack trace: * line 125 of /lib/dml/pgsql_native_moodle_database.php: dml_exception thrown

      • line 9 of /example.php: call to pgsql_native_moodle_database->connect()
        !!
      Show
      calling the following code snippet currently throws an error: <?php define('CLI_SCRIPT', true); require('config.php'); $authdb = moodle_database::get_driver_instance('pgsql', 'native'); $authdb->connect('localhost', 'moodle', 'moodle', 'example_external_database', false); Expected result: It works! Actual result: www-data@moodle:/home/nicols/git/software/moodle$ php example.php Default exception handler: <p>Error: database table prefix cannot be empty (postgres)</p> <p>The site administrator must fix this problem.</p> Debug: line 125 of /lib/dml/pgsql_native_moodle_database.php: dml_exception thrown line 9 of /example.php: call to pgsql_native_moodle_database->connect() !!! <p>Error: database table prefix cannot be empty (postgres)</p> <p>The site administrator must fix this problem.</p> !!! !! Stack trace: * line 125 of /lib/dml/pgsql_native_moodle_database.php: dml_exception thrown line 9 of /example.php: call to pgsql_native_moodle_database->connect() !!
    • Affected Branches:
      MOODLE_21_STABLE, MOODLE_22_STABLE
    • Fixed Branches:
      MOODLE_21_STABLE
    • Pull from Repository:
    • Pull Master Branch:
    • Rank:
      17908

      Description

      To create a handle to an external postgres database, you must call

      $foo = moodle_database::get_driver_instance('pgsql', 'native')

      This in turn determines the relevant class, and returns a new instance of that class.

      Moodle requires that you define a table prefix if you're using postgres for the Moodle database, but the postgres driver drops this requirement if $this->external is true.

      The only way of setting the external flag is through the constructor, but since the instance is instantiated via the get_driver_instance, this is not possible.

        Activity

        Hide
        Andrew Nicols added a comment -
        Show
        Andrew Nicols added a comment - Bug fix available from git at https://git.luns.net.uk/?p=moodle.git;a=shortlog;h=refs/heads/MDL-28193
        Hide
        Dan Poltawski added a comment -

        I've reviewed this and it makes sense I think, an oversight from the fact nothing else is connecting to external dbs.

        Submitting for integration!

        Show
        Dan Poltawski added a comment - I've reviewed this and it makes sense I think, an oversight from the fact nothing else is connecting to external dbs. Submitting for integration!
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Integrated into 21_STABLE and master, thanks!

        Show
        Eloy Lafuente (stronk7) added a comment - Integrated into 21_STABLE and master, thanks!
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Passing, it enables the use of external from get_driver_instance() via optional param (BC) and all the DB unit tests continue working ok.

        Show
        Eloy Lafuente (stronk7) added a comment - Passing, it enables the use of external from get_driver_instance() via optional param (BC) and all the DB unit tests continue working ok.
        Hide
        Eloy Lafuente (stronk7) added a comment -

        All this cool stuff is now part of Moodle, thanks!

        Show
        Eloy Lafuente (stronk7) added a comment - All this cool stuff is now part of Moodle, thanks!

          People

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

            Dates

            • Created:
              Updated:
              Resolved: