this hook - _db_optimize_sql($query) is target to optimize SQL statement before doing any _db_query_callback(), so all arguments will still keep in %d, %s, %%, %f and %b format. it will be useful if DB backend driver trying to optimize SQL statement for better compatibility, functionality and performance.

it current status, oracle DB driver will try to use this hook for rewrite and caching SQL. this hook is useful because oracle driver can use it for overcoming the limitation of maximum 30 characters, in naming of table, column, index, trigger, etc, by re-mapping the long name into its short form from a mapping table. on the other hand, we can also cache up the mapped result, and reuse it afterward for performance boost. for example, in database.oracle.inc:

/**
 * Optimize SQL query according to different database backend
 *
 * @param $query
 *   A string containing an SQL query.
 *
 * @return
 *   A string containing an optimized SQL query.
 */
function _db_optimize_sql($query) {
  // Find out optimized SQL query in cache, return it if exists
  if ($mapped = _db_get_cached_sql($query)) {
    return $mapped;
  }

  // Clean target SQL query according to Oracle limitation
  $mapped = _db_oracle_clean_sql($query);

  // Cache the optimized SQL query
  _db_set_cached_sql($query, $mapped);

  return $mapped;
}
CommentFileSizeAuthor
database.inc_.diff451 byteshswong3i

Comments

moshe weitzman’s picture

Status: Needs review » Needs work

seems ok to me. i think db_alter_sql() is a bit more descriptive.I thought this was about optimizing tables ... i don't think the leading _ is needed though.

one alternative would be to move db_query() into the DB specific backends.

hswong3i’s picture

it is naming is totally fine for me, as i just need a simple hook right now... i plan to use that name just because other DB backend may also take benefit from it, which may not only about alter but target to optimize SQL. the leading _ is used to figure out this is only a private function hook for backend DB driver, but not target for public ;)

on the other hand, i think your 2nd suggestion is much more better! it will give more flexibility to other DB driver, too. this change seems more positive, and there is not much change among mysql/mysqli/pgsql driver too: just move the public function into private section. do you think i should submit another patch about this?

hswong3i’s picture

Assigned: Unassigned » hswong3i
Status: Needs work » Closed (duplicate)

this patch is a subset of other patch (http://drupal.org/node/147692), and so this thread will close