It appears we are experiencing the same issue that someone had in the 6.x version of the Oracle driver (http://drupal.org/node/928796) where the following fails:

Select * FROM table AS alias

Removing the 'AS alias' fixes the issue, but would have to do that with each and every occurrence (which is a lot for the Ubercart modules that I'm using).

Is there a way this can be fixed within the Oracle driver?

Thanks!

CommentFileSizeAuthor
#1 database.inc_.patch1.81 KBcmurph

Comments

cmurph’s picture

Status: Active » Needs review
StatusFileSize
new1.81 KB

I've created a patch which adds a preg_replace to take out the AS.
Tests that I performed looked to be working.

See attached patch.

aaaristo’s picture

Status: Needs review » Fixed

releasing it in 1.10

aaaristo’s picture

Status: Fixed » Needs work

this code fails:


  function escapeTableAlias($query)
  {
      $search = array ('/(FROM|JOIN|from|join) ({\w+})( AS | as )/e', // Replaces all FROM table AS alias to FROM table alias
                       '/(FROM|JOIN|from|join) (\(.+\)?)( AS )/e' // Replaces all FROM (SELECT table) AS alias to FROM (SELECT table) alias
                      );

      $replace = array ("'\\1'.' '.'\\2'.' '.'\\4'",
                        "'\\1'.' '.'\\2'.' '.'\\4'"
                       );

      return preg_replace($search, $replace, $query);
  }

  function escapeReserved($query)
  {
        $ddl= !((boolean)preg_match('/^(select|insert|update|delete)/i',$query));
        $search = array ("/({)(\w+)(})/e", // escapes all table names
                         "/({L#)([0-9]+)(})/e", // escapes long id
                         "/(\:)(uid|session|file|access|mode|comment|desc|size|start|end)/e",
                         "/(<uid>|<session>|<file>|<access>|<mode>|<comment>|<desc>|<size>".($ddl?'':'|<date>').")/e",
                         '/([\(\.\s,\=])(uid|session|file|access|mode|comment|desc|size'.($ddl?'':'|date').')([,\s\=)])/e',
                         '/([\(\.\s,])(uid|session|file|access|mode|comment|desc|size'.($ddl?'':'|date').')$/e');

        $replace = array ("'\"\\1'.strtoupper('\\2').'\\3\"'",
                          "'\"\\1'.strtoupper('\\2').'\\3\"'",
                          "'\\1'.'db_'.'\\2'.'\\3'",
                          "strtoupper('\"\\1\"')",
                          "'\\1'.strtoupper('\"\\2\"').'\\3'",
                          "'\\1'.strtoupper('\"\\2\"')");

        return preg_replace($search, $replace, $query);


  }


   echo escapeTableAlias(escapeReserved('SELECT * FROM (SELECT TAB.*, ROWNUM RWN_TO_REMOVE FROM (SELECT u.uid, u.name, MAX(s.timestamp) AS max_timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= :interval AND s.uid > 0 GROUP BY u.uid, u.name ORDER BY max_timestamp DESC) TAB) WHERE RWN_TO_REMOVE BETWEEN :oracle_rwn_start AND :oracle_rwn_end'));

it gives SELECT u.\"UID\"... the regex must be reviewed....

aaaristo’s picture

Version: 7.x-1.9 » 7.x-1.10
bohart’s picture

Version: 7.x-1.10 » 7.x-1.x-dev
Issue summary: View changes
Status: Needs work » Closed (outdated)

D7 reached its EOL back in January 2025, and there is no active release for D7 for this module anymore.
Development or support is not planned for D7. All D7-related issues are marked as outdated in a bunch.

Everyone can apply the patches/suggestions above (not tested by the maintainers, tested by the community) to their D7 projects.
If the issue remains relevant for D10+ versions, merge requests with proposed solutions for a new module version (D10+) are welcome in a new follow-up issue.

Thanks!

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.