Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-29516 DB layer improvements 2.3 META
  3. MDL-32029

Function get_tables of DML does not support empty prefix for external databases

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Fixed
    • Icon: Minor Minor
    • 2.3
    • 2.2
    • Database SQL/XMLDB
    • Any
    • MOODLE_22_STABLE
    • MOODLE_23_STABLE
    • w13_MDL-32029_m23_extdb
    • Hide

      //if (strpos($tablename, $this->prefix) !== 0) {
      // continue;
      //}

      for:

      if (!empty($this->prefix) && strpos($tablename, $this->prefix) !== 0) {
      [...]

      Show
      //if (strpos($tablename, $this->prefix) !== 0) { // continue; //} for: if (!empty($this->prefix) && strpos($tablename, $this->prefix) !== 0) { [...]
    • Hide

      For developers:
      1/ try functional DB tests for all 4 drivers (except mysqli)
      2/ try to connect to external database and fetch list tables:
      Try to connect to an external DB with empty prefix:

      $prefix = '';
       
      if (!$handler = moodle_database::get_driver_instance($type, $library, true)) {
        throw new dml_exception('dbdriverproblem', "Unknown driver $library/$db_record->type");
      }
      try {
        $handler->connect($host, $username, $password, $name, $prefix, $options);
      } catch (moodle_exception $e) {
        die();
      }
       
      print_r($handler->get_tables(false));

      Show
      For developers: 1/ try functional DB tests for all 4 drivers (except mysqli) 2/ try to connect to external database and fetch list tables: Try to connect to an external DB with empty prefix: $prefix = '';   if (!$handler = moodle_database::get_driver_instance($type, $library, true)) { throw new dml_exception('dbdriverproblem', "Unknown driver $library/$db_record->type"); } try { $handler->connect($host, $username, $password, $name, $prefix, $options); } catch (moodle_exception $e) { die(); }   print_r($handler->get_tables(false));

      In all the functions get_tables in lib/dml/*_database.php is a function named get_tables that returns the name of all the databases.

      If you want to connecto to an external table and want to know the name of the tables in the structure and this external database does not have a prefix, the function returns nothing but lots of warnings like this:

      Warning: strpos() [function.strpos]: Empty delimiter in /moodle/lib/dml/pgsql_native_moodle_database.php on line 294

            skodak Petr Skoda
            pferre22 Pau Ferrer
            Sam Hemelryk Sam Hemelryk
            Rajesh Taneja Rajesh Taneja
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

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