I have a little reset.php script (code shown below) in my Drupal root that I use to reset my HEAD testing installs. Up until recently, it's worked just fine. Now I've started getting the following error: "Fatal error: Call to undefined function db_and() in /home/davereid/Projects/drupal-head/includes/database/mysql/schema.inc on line 35"

reset.php:


// Show a confirm message before wiping everything out.
if (!isset($_GET['sure'])) {
  echo '<a href="/reset.php?sure=yes">Are you sure?</a>';
  exit();
}

// Bootstrap Drupal.
define('DRUPAL_ROOT', dirname(realpath(__FILE__)));
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

// Get a listing of all modules and put the system module last.
$modules = drupal_system_listing('/\.module$/', 'modules', 'name', 0);
unset($modules['system']);
$modules = array_keys($modules);
$modules[] = 'system';

// Uninstall all module schemas.
foreach ($modules as $module) {
  drupal_uninstall_schema($module);
}

// Redirect to the install page.
header('Location: install.php');
exit();

The only way I could fix this was by adding require_once DRUPAL_ROOT . '/includes/database/query.inc'; right after drupal_bootstrap(). What is going on? Why isn't that file included?

CommentFileSizeAuthor
#3 360113-dbtng-conditions-D7.patch2.46 KBDave Reid
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Crell’s picture

query.inc is lazy-loaded. Functions don't lazy load without help. The code in schema.inc is not helping it. That's why. :-)

Although I'd say the real problem is that we're using db_and() inside the schema object to begin with; the utility functions should never be used internally. I think that was probably part of #342503: Schema function findTables fails on postgres - wrong SQL, as that did a lot of mucking about inside the schema classes. Bad on me for not catching that. :-(

Since the conditional objects are not driver-overridable and I can't think of a reason they would be, we should probably just switch the db_and() calls to direct $and = new DatabaseCondition('and') calls.

Dave Reid’s picture

Status: Active » Needs review

Ok here's a patch that removes any direct calls to db_and()/db_or() within /database/.* files.

Dave Reid’s picture

This time with the patch.

Crell’s picture

Status: Needs review » Reviewed & tested by the community

Passes visual inspection and the bot likes it. (I do love being able to say that...)

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.