Encountered a very odd bug where the tableExists() was returning TRUE even though the table didn't actually exist. Not exactly sure if it points to a problem higher up with queryRange() not throwing exceptions but the fact is that there could be some better handling inside the tableExists() function itself. What it currently does is perform the SQL inside a try/catch. If it hits the catch statement, return FALSE. If it stays inside the try block, return TRUE no matter what. This should be changed to actually check the result of the SQL statement as well. Possibly we should throw our own exception inside the try block.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Status: Active » Needs review
FileSize
1.3 KB

Here's the additional checking added to both tableExists() and fieldExists(). I added a ->fetchField() to actually get the result of the queryRange() call and check if it is not identical to FALSE, which if it did would indicate a failure, so table or field does not exist.

Crell’s picture

SQL--

If we're going to do that, we should see if indexExists() needs similar treatment.

Although, aren't there unit tests already for this? Why aren't they failing? (Or did we forget those?)

Dave Reid’s picture

I'm wondering if it was an environment problem, although it is unfortunate because the host on which this occurred does not have cURL enabled, so I cannot run the regression tests that include tests for db_table_exists() and db_field_exists().

indexExists() won't need this same treatment since it already uses something similar:

    $row = $this->connection->query('SHOW INDEX FROM {' . $table . "} WHERE key_name = '$name'")->fetchAssoc();
    return isset($row['key_name']);
Damien Tournoud’s picture

-1 here. This is probably a different issue.

By any chance, are you sure that this host is running the real PDO module from 5.2, and not the PDO module from PECL (which doesn't support exceptions)?

Dave Reid’s picture

Title: Exceptions not being thrown when checking if table or field exists » Add a requirements check error
Status: Needs review » Needs work

Ugh, that was it. We need a good requirements check for this.

Dave Reid’s picture

Title: Add a requirements check error » Add a requirements check error if PECL PDO is being used
Damien Tournoud’s picture

Status: Needs work » Needs review
FileSize
1.56 KB

Let's try this.

Damien Tournoud’s picture

FileSize
3.19 KB

Adding additional checks in install.core.inc and system.install. This is a mess.

Crell’s picture

Is it possible to move that check into a utility function, so that we're not documenting the same weird thing in 3 places?

Someone with PECL PDO needs to test this, too, to confirm that it gets rejected.

Gah.

Crell’s picture

Status: Needs review » Needs work
Everett Zufelt’s picture

Priority: Normal » Major

#937714: Receiving database exception: DatabaseSchemaObjectExistsException: cache_path does show that using PECL PDO this patch does do proper detection.

I think also that this bug should be Major, since without the patch users receive an error without any direction at all about what might be causing the error.

Everett Zufelt’s picture

The Drupal requirements page http://drupal.org/requirements also appears to be in need of an update, since it refers to PECL PDO.

Damien Tournoud’s picture

Priority: Major » Critical

We definitely need to fix that. We saw a few users crashing into this already.

Promoting to critical.

shelleyp’s picture

The patch was only partially successful. Following is the reject file contents:

***************
*** 147,153 ****
);

// Test for at least one suitable PDO extension, if PDO is available.
- $database_ok = extension_loaded('pdo');
if ($database_ok) {
$drivers = drupal_detect_database_types();
$database_ok = !empty($drivers);
--- 147,157 ----
);

// Test for at least one suitable PDO extension, if PDO is available.
+ // PDO has been moved to PHP core in 5.2.0, but the old extension (targetting
+ // 5.0 and 5.1) is still available from PECL, and can still be built without
+ // errors. Checking the PDO::ATTR_DEFAULT_FETCH_MODE constant, only available
+ // starting PDO 5.2.0 allow us to verify if the correct version is used.
+ $database_ok = extension_loaded('pdo') && defined('PDO::ATTR_DEFAULT_FETCH_MODE');
if ($database_ok) {
$drivers = drupal_detect_database_types();
$database_ok = !empty($drivers);
~

The reject file was in system.install.rej.

However, when I did try the upgrade following, I did get the appropriate error message.

If you want me to test anything on this, on my system, send me an email. Will be glad to help however I can.

Dave Reid’s picture

Removed the instructions about pecl pdo on drupal.org/requirements.

ksenzee’s picture

Status: Needs work » Needs review
FileSize
2.65 KB

Looks like there was an indent problem with the hunk that didn't apply. I fixed that and trimmed down the comments so we're not documenting the same thing so often.

shelleyp’s picture

I have restored the original D7 installation, and tested your patch on my PECL PDO system, and it worked without an error, and Drupal is now providing the correct error message.

I'm not sure if I'm supposed to change the status of this bug, to signify tested by community, so will leave as is.

webchick’s picture

Status: Needs review » Needs work
+    $message = '<h2>PDO is not the correct version!</h2><p>Drupal 7 requires the PHP Data Objects (PDO) extension from PHP core to be enabled. The version installed on this system is from PECL.</p>';

This is definitely preferable to giving an error that completely makes no sense and moreover is just WRONG, but there is no recourse for the user on how to redress this problem. We should point them at a handbook page (perhaps http://drupal.org/node/549702?) or at the very least let them know this is something their web host needs to deal with (preferably, along with some keywords so that the host goes "oh, I get it." instead of asking a non-technical end user to elaborate on what they mean).

ksenzee’s picture

Status: Needs work » Needs review
FileSize
5.33 KB

This adds a link to http://drupal.org/requirements/pdo#pecl to the error message for both update and install, and splits up the check on install to provide more specific, relevant errors to people who are installing.

Damien Tournoud’s picture

Status: Needs review » Reviewed & tested by the community

Perfect!

Crell’s picture

This looks OK to me as well on quick visual inspection. For the most part, though, I defer to Damien on this one as he's been following it more closely than I have.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Looks great. Committed to CVS HEAD. Thanks.

montesq’s picture

Priority: Critical » Minor
Status: Fixed » Needs work

Dear All,

I've just tested the new D7beta2 on a shared web hosting and I've got the error: "Your web server seems to have the wrong version of PDO installed..."
According to the phpinfo(), the current PHP version is 5.2.5. I also see a reference to pecl but only in the sections PDF and SQLite (and not in the PDO section).
Is there any means to know whether PDO comes from the core or from pecl?
Thks in advance.

Damien Tournoud’s picture

Priority: Minor » Critical
Status: Needs work » Fixed

Is there any means to know whether PDO comes from the core or from pecl?

Yes, if you get the message, PDO comes from PECL.

Restoring statuses.

Damien Tournoud’s picture

Component: mysql database » database system

Status: Fixed » Closed (fixed)

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

joemoraca’s picture

Version: 7.x-dev » 7.0-beta3
Assigned: Dave Reid » Unassigned
Status: Closed (fixed) » Active

I have have the same database error as here and http://drupal.org/node/937714. I don't get the PDO version check error message. I am using a multi site setup with 7.0 beta3. First site is a new site it works fine. Second site is converted (started in drupal 5.0) it works fine no problem with the conversion to V6 or V7. Third site is also started from Drupal 5 - converted with no problem to Drupal 6 now I get the database error about index already existing trying to upgrade to D7 - I remove that index and get stuck in a loop of database issues.

I am running PHP 5.2.10-2ubuntu6.5 with apache2.2.12 - pdo_mysql shows 5.1.37 ...

If I do pecl list the only package that shows up is uploadprogress ...

DatabaseSchemaObjectExistsException: Cannot add index system_list to table system: index already exists. in DatabaseSchema_mysql->addIndex() (line 433 of /home/drupal-7.0-beta3/includes/database/mysql/schema.inc).

webchick’s picture

Status: Active » Fixed

Hm. Joe, could you maybe make a separate issue with details and cross-link it here? This issue was about adding a requirements check during installation for the proper version of PDO, which is effectively done now. What you're describing might be related, but it doesn't sound like quite the same thing.

joemoraca’s picture

I just created http://drupal.org/node/982748 with my issue.

Status: Fixed » Closed (fixed)

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