This patch try to cleanup and synchronize coding style for /includes/database.*.inc, include (P.S. none of logical change to existing implementation):

database.inc
Reorder DB_QUERY_REGEXP and _db_query_callback().
database.mysql.inc and database.mysqli.inc
Move common codes to database.mysql-common.inc.
database.mysql-common.inc
  1. Reorder code order in db_query_range() and db_query_temporary(). Tested with mysqli and all functioning.
  2. Rename internal function _db_create_keys_sql() => _db_create_keys() (synchronize with pgsql version).
database.pgsql.inc
  1. Reorder code order in db_query_range() and db_query_temporary().
  2. Update db_table_exists() and db_column_exists() (synchronize with mysql version).
  3. Coding style cleanup in db_type_map().

Comments

hswong3i’s picture

Assigned: Unassigned » hswong3i
StatusFileSize
new32.01 KB

some more minor update to:

  1. database.mysql-common.inc => _db_create_field_sql(): change SQL words case
  2. all => db_escape_string(): sync input variable name with db_decode_blob()

no logical change but only code clean up and sync style

hswong3i’s picture

Category: feature » task
StatusFileSize
new31.06 KB

patch updated via latest CVS HEAD, plus minor update to db_query_temporary() and db_query_range(). i change this 2 function as a simple query rewriter, and pass result to db_query() directly for execution (but not _db_query()). e.g. in case of mysql/mysqli:

function db_query_range($query) {
  $args = func_get_args();
  $count = array_pop($args);
  $from = array_pop($args);
  array_shift($args);

  $query .= ' LIMIT '. (int) $from .', '. (int) $count;
  if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax
    $args = $args[0];
  }
  return db_query($query, $args);
}

it seems may have performance degrade (as one more layer of function call), but a benchmarking show out a positive result (reuse all setup as http://drupal.org/node/172541#comment-298711):

                  +-------------+---------------+----------------+
                  | c1, n500    | c5, n500      | c10, n500      |
+-----------------+-------------+---------------+----------------+
| D6 HEAD         | 289 +- 11.5 | 1429 +- 342.4 | 2888 +- 721.0  |
+                 +-------------+---------------+----------------+
|                 | 294 +- 16.1 | 1436 +- 162.3 | 2955 +- 2123.6 |
+                 +-------------+---------------+----------------+
|                 | 294 +- 15.7 | 1424 +- 413.6 | 2826 +- 774.5  |
+-----------------+-------------+---------------+----------------+
| D6 HEAD + patch | 290 +- 13.8 | 1450 +- 402.0 | 2815 +- 770.2  |
+                 +-------------+---------------+----------------+
|                 | 290 +- 12.6 | 1416 +- 215.8 | 2855 +- 666.5  |
+                 +-------------+---------------+----------------+
|                 | 290 +- 17.0 | 1464 +- 441.9 | 2912 +- 884.8  |
+-----------------+-------------+---------------+----------------+

this change should able to decrease the workload of database driver maintenance, without losing any performance. hope someone may help about its commit :)

hswong3i’s picture

patch still apply to CVS HEAD.

hswong3i’s picture

Title: coding style cleanup: database.*.inc » database.*.inc: coding style cleanup + minor internal enhancement

patch still apply to CVS HEAD. rename issue title.

hswong3i’s picture

Category: task » bug
Priority: Normal » Minor
StatusFileSize
new31.27 KB

patch updated via CVS HEAD. seems this should be a minor bug report but not feature request :)

chx’s picture

Version: 6.x-dev » 7.x-dev
Category: bug » feature

And what exactly is the bug you are fixing here? What functionality is broken?

hswong3i’s picture

Version: 7.x-dev » 6.x-dev
Category: feature » bug

I guess this is a bug fix, since it improve usability of code, decrease the difficulty of maintenance and standardize the coding standard for developers. This is not a "hard" bug but "soft".

It is not functionality fix, as we will not died without this patch, so it is minor.

We are able to cleanup these lossy coding style in D6, without affect any existing code related nor performance; it don't add/drop any API functions; it is transparency to all contribute developers. It should be suitable for D6 as an enhancement. I guess coding style cleanup is always welcome even after beta1, isn't it?

hswong3i’s picture

Category: bug » task
Priority: Minor » Normal
Status: Needs review » Closed (duplicate)

This issue will make as duplicated, as its handling is already split into numbers of small patches, for a easy review and commit. Please refer to the following issues:
http://drupal.org/node/183892 (Group up database.mysql-common.inc)
http://drupal.org/node/183896 (Tidy up database.pgsql.inc)
http://drupal.org/node/183902 (Tidy up database.inc)
http://drupal.org/node/183910 (Simplify db_query_range() and db_query_temporary())