I have a simple query that checks to see if the external oracle database is accessible. It runs on the Status Report page. That page now gives WSOD.

I also have other queries that now fail when updating to 7.x-1.10. It complains of an unknown table, but it works fine with 7.x-1.9.

I'm running Drupal 7.12, and the Oracle database I'm connecting to is NOT my main Drupal database. It's an external data warehouse. That's why the rest of the site works fine until I try to run those queries.

I'm trying to step through the code with a debugger to find where it fails, but I haven't found it yet.

Comments

aaaristo’s picture

can you post the error please?

aaaristo’s picture

try 1.11

shawn dearmond’s picture

On 1.11, here's the error I get on the Status Report page:

PDOException: SELECT acad_term.acad_term_code AS acad_term_code, acad_term.acad_term_desc AS acad_term_desc FROM {acad_term} acad_term WHERE (acad_term_code > :db_condition_placeholder_0) (prepared: SELECT acad_term.acad_term_code AS acad_term_code, acad_term.acad_term_desc AS acad_term_desc FROM {acad_term} acad_term WHERE (acad_term_code > :db_condition_placeholder_0) ) e: SQLSTATE[HY000]: General error: 903 OCIStmtExecute: ORA-00903: invalid table name (/home/administrator/Downloads/php-5.3.6/ext/pdo_oci/oci_statement.c:148) args: Array ( [:db_condition_placeholder_0] => 200000 ) in ucd_cdw_requirements() (line 31 of /home/administrator/Sites/drupal7_oracle/sites/all/modules/ucd_cdw/ucd_cdw.module).
The website encountered an unexpected error. Please try again later.

Fatal error: Exception thrown without a stack frame in Unknown on line 0 Call Stack: 0.6844 28537908 1. _drupal_exception_handler() /home/administrator/Sites/drupal7_oracle/includes/bootstrap.inc:0 0.6846 28540000 2. _drupal_log_error() /home/administrator/Sites/drupal7_oracle/includes/bootstrap.inc:2222

And when I run my tests, I get this:

An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /batch?id=479&op=do StatusText: Service unavailable (with message) ResponseText: PDOException: SELECT t.acad_term_code AS acad_term_code, t.acad_term_desc AS acad_term_desc, t.acad_year_desc AS acad_year_desc, t.term_begin_date AS term_begin_date, t.term_end_date AS term_end_date, t.pass_1_begin_date AS pass_1_begin_date, t.pass_1_end_date AS pass_1_end_date, t.pass_2_begin_date AS pass_2_begin_date, t.pass_2_end_date AS pass_2_end_date, t.early_drop_date AS early_drop_date, t.term_type_code AS term_type_code, t.regular_drop_date AS regular_drop_date FROM {acad_term} t WHERE (acad_term_code NOT IN (:db_condition_placeholder_0, :db_condition_placeholder_1, :db_condition_placeholder_2)) AND (acad_term_code > :db_condition_placeholder_3) ORDER BY acad_term_code ASC (prepared: SELECT t.acad_term_code AS acad_term_code, t.acad_term_desc AS acad_term_desc, t.acad_year_desc AS acad_year_desc, t.term_begin_date AS term_begin_date, t.term_end_date AS term_end_date, t.pass_1_begin_date AS pass_1_begin_date, t.pass_1_end_date AS pass_1_end_date, t.pass_2_begin_date AS pass_2_begin_date, t.pass_2_end_date AS pass_2_end_date, t.early_drop_date AS early_drop_date, t.term_type_code AS term_type_code, t.regular_drop_date AS regular_drop_date FROM {acad_term} t WHERE (acad_term_code NOT IN (:db_condition_placeholder_0, :db_condition_placeholder_1, :db_condition_placeholder_2)) AND (acad_term_code > :db_condition_placeholder_3) ORDER BY acad_term_code ASC ) e: SQLSTATE[HY000]: General error: 903 OCIStmtExecute: ORA-00903: invalid table name (/home/administrator/Downloads/php-5.3.6/ext/pdo_oci/oci_statement.c:148) args: Array ( [:db_condition_placeholder_0] => 000000 [:db_condition_placeholder_1] => 000001 [:db_condition_placeholder_2] => 999999 [:db_condition_placeholder_3] => 197000 ) in cdw_term_import() (line 92 of /home/administrator/Sites/drupal7_oracle/sites/all/modules/ucd_cdw/modules/cdw_term/cdw_term.module).Uncaught exception thrown in shutdown function.PDOException: DELETE FROM {semaphore} WHERE (value = :db_condition_placeholder_0) (prepared: DELETE FROM {semaphore} WHERE (value = :db_condition_placeholder_0) ) e: SQLSTATE[HY000]: General error: 903 OCIStmtExecute: ORA-00903: invalid table name (/home/administrator/Downloads/php-5.3.6/ext/pdo_oci/oci_statement.c:148) args: Array ( [:db_condition_placeholder_0] => 7773168824f32eed49090b5.68379439 ) in lock_release_all() (line 269 of /home/administrator/Sites/drupal7_oracle/includes/lock.inc).Uncaught exception thrown in shutdown function.PDOException: DELETE FROM {cache_block} WHERE (expire <> :db_condition_placeholder_0) AND (expire < :db_condition_placeholder_1) (prepared: DELETE FROM {cache_block} WHERE (expire <> :db_condition_placeholder_0) AND (expire < :db_condition_placeholder_1) ) e: SQLSTATE[HY000]: General error: 903 OCIStmtExecute: ORA-00903: invalid table name (/home/administrator/Downloads/php-5.3.6/ext/pdo_oci/oci_statement.c:148) args: Array ( [:db_condition_placeholder_0] => 0 [:db_condition_placeholder_1] => 1328738000 ) in cache_clear_all() (line 176 of /home/administrator/Sites/drupal7_oracle/includes/cache.inc).Uncaught exception thrown in session handler.DatabaseTransactionNoActiveException: in DatabaseConnection->rollback() (line 1016 of /home/administrator/Sites/drupal7_oracle/includes/database/database.inc).

It works fine with 1.9.

aaaristo’s picture

Version: 7.x-1.10 » 7.x-1.11
Status: Active » Needs work

looks like {acad_term} is not transformed. This because from 1.10 external databases are no more treated as drupal backends. You probably don't need the {table} notation in the query right?

aaaristo’s picture

Status: Needs work » Postponed (maintainer needs more info)
shawn dearmond’s picture

Status: Postponed (maintainer needs more info) » Needs work

Aha! That would definitely make sense. Drupal habits are hard to break!

I'll mark it as resolved when I confirm that it's the issue.

Thanks!

shawn dearmond’s picture

Okay, so here's the problem: I'm using PDO to do the queries. For example, my hook_requirements query that's causing the first error is:

$connect = db_set_active('ucd_cdw');
$query = db_select('acad_term')
  ->fields('acad_term', array('acad_term_code', 'acad_term_desc'))
  ->condition('acad_term_code', '200000', '>');
$result = $query->execute();
$rows = $result->fetchAll();
db_set_active();

I'm not entering the transforming notation, Drupal is. Is there a way I tell Drupal that it's an external database so it won't wrap the table names in curly brackets?

aaaristo’s picture

Status: Needs work » Fixed

commited in -dev...

ps: it is not up to you how i manage my issue list...

shawn dearmond’s picture

Status: Fixed » Needs work

That fixed the first error on the status report page, but I'm still getting an error when I run my tests... which I fully admit could be bad code or bad tests on my part. I'm just curious as to why it's suddenly failing with version >= 1.10.

Here's the error I'm getting when I run my tests:

An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /batch?id=482&op=do StatusText: Service unavailable (with message) ResponseText: PDOException: SELECT * FROM {system} WHERE type = 'theme' OR (type = 'module' AND status = 1) ORDER BY weight ASC, name ASC (prepared: SELECT * FROM system WHERE type = 'theme' OR (type = 'module' AND status = 1) ORDER BY weight ASC, name ASC ) e: SQLSTATE[HY000]: General error: 942 OCIStmtExecute: ORA-00942: table or view does not exist (/home/administrator/Downloads/php-5.3.6/ext/pdo_oci/oci_statement.c:148) args: Array ( ) in system_list() (line 165 of /home/administrator/Sites/drupal7_oracle/includes/module.inc).Uncaught exception thrown in shutdown function.PDOException: DELETE FROM {semaphore} WHERE (value = :db_condition_placeholder_0) (prepared: DELETE FROM semaphore WHERE (value = :db_condition_placeholder_0) ) e: SQLSTATE[HY000]: General error: 942 OCIStmtExecute: ORA-00942: table or view does not exist (/home/administrator/Downloads/php-5.3.6/ext/pdo_oci/oci_statement.c:148) args: Array ( [:db_condition_placeholder_0] => 20726538964f342acd3bba80.07250610 ) in lock_release_all() (line 269 of /home/administrator/Sites/drupal7_oracle/includes/lock.inc).Uncaught exception thrown in shutdown function.PDOException: DELETE FROM {cache_page} WHERE (expire <> :db_condition_placeholder_0) AND (expire < :db_condition_placeholder_1) (prepared: DELETE FROM cache_page WHERE (expire <> :db_condition_placeholder_0) AND (expire < :db_condition_placeholder_1) ) e: SQLSTATE[HY000]: General error: 942 OCIStmtExecute: ORA-00942: table or view does not exist (/home/administrator/Downloads/php-5.3.6/ext/pdo_oci/oci_statement.c:148) args: Array ( [:db_condition_placeholder_0] => 0 [:db_condition_placeholder_1] => 1328818887 ) in cache_clear_all() (line 176 of /home/administrator/Sites/drupal7_oracle/includes/cache.inc).

ps. Sorry, I don't mean to step on anyone's toes. Just trying to be helpful.

Thank you for your attention to this issue, by the way, and for maintaining this module.

shawn dearmond’s picture

Status: Needs work » Needs review
StatusFileSize
new1.08 KB

I figured it out. It had to do with one more of those escaping methods and how they're not being run when $this->external. Specifically: $oquery= $this->escapeCompatibility($oquery);

Attached is a patch that fixes that one, and cleans up that section of the code a little, but now I'm wondering if maybe the rest of those escape*() methods should be run, even on external databases. My tests all pass now (with this patch) but it's likely I'm not using all aspects of PDO.

What is your reasoning for not running these escape*() methods on external databases?

<?php
                      $oquery= $this->escapeEmptyLiterals($oquery);
                      $oquery= $this->escapeAnsi($oquery);
                      $oquery= $this->lih->escapeLongIdentifiers($oquery);
                      $oquery= $this->escapeReserved($oquery);
                      $oquery= $this->escapeIfFunction($oquery);
?>
aaaristo’s picture

Status: Needs review » Needs work

Right, i've exclude the escape methods as a result of this bug: http://drupal.org/node/1167524,
thinking that if you ar going to access an external on oracle database you know it.. and so you'll write
oracle compliant sql. But probably i should have removed only the $oquery= $this->lih->escapeLongIdentifiers($oquery);,
because even if you are accessing an external oracle database you may want to use the dbtng framework
to access it (like you do with db_select). So yes i am going to fix it in -dev.

ps: sorry, yesterday was a bad day... thanks for the feedback

aaaristo’s picture

Status: Needs work » Fixed

committed in -dev

shawn dearmond’s picture

Works perfectly. Thanks!

If you could roll a release so I can implement it on my production site, I'd really appreciate it. Thanks again for being so attentive to your issue queue. It's a remarkably rare quality.

Status: Fixed » Closed (fixed)

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