? sites/default/files
Index: includes/database.pgsql.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/database.pgsql.inc,v
retrieving revision 1.68
diff -u -p -r1.68 database.pgsql.inc
--- includes/database.pgsql.inc	4 Jan 2008 09:31:48 -0000	1.68
+++ includes/database.pgsql.inc	4 Jan 2008 18:59:43 -0000
@@ -46,8 +46,8 @@ function db_version() {
  */
 function db_connect($url) {
   // Check if PostgreSQL support is present in PHP
-  if (!function_exists('pg_connect')) {
-    _db_error_page('Unable to use the PostgreSQL database because the PostgreSQL extension for PHP is not installed. Check your <code>php.ini</code> to see how you can enable it.');
+  if (!(function_exists('pg_connect') && extension_loaded('pgsql'))) {
+    _db_error_page('Unable to use the PostgreSQL database because the PostgreSQL extension for PHP is not installed. Check your php.ini to see how you can enable it.');
   }
 
   $url = parse_url($url);
@@ -138,12 +138,17 @@ function _db_query($query, $debug = 0) {
   $last_result = pg_query($active_db, $query);
 
   if (variable_get('dev_query', 0)) {
-    $bt = debug_backtrace();
-    $query = $bt[2]['function'] ."\n". $query;
     list($usec, $sec) = explode(' ', microtime());
-    $stop = (float)$usec + (float)$sec;
-    $diff = $stop - $timer;
-    $queries[] = array($query, $diff);
+    $timer = (float)$usec + (float)$sec;
+    // If devel.module query logging is enabled, prepend a comment with the username and calling function
+    // to the SQL string. This is useful when running mysql's SHOW PROCESSLIST to learn what exact
+    // code is issueing the slow query.
+    $bt = debug_backtrace();
+    // t() may not be available yet so we don't wrap 'Anonymous'
+    $name = $user->uid ? $user->name : variable_get('anonymous', 'Anonymous');
+    // str_replace() to prevent SQL injection via username or anonymous name.
+    $name = str_replace(array('*', '/'), '', $name);
+    $query = '/* '. $name .' : '. $bt[2]['function'] .' */ '. $query;
   }
 
   if ($debug) {
@@ -274,14 +279,11 @@ function db_query_range($query) {
   $from = array_pop($args);
   array_shift($args);
 
-  $query = db_prefix_tables($query);
+  $query .= ' LIMIT '. (int) $count .' OFFSET '. (int) $from;
   if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax
     $args = $args[0];
   }
-  _db_query_callback($args, TRUE);
-  $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
-  $query .= ' LIMIT '. (int)$count .' OFFSET '. (int)$from;
-  return _db_query($query);
+  return db_query($query, $args)
 }
 
 /**
@@ -320,14 +322,20 @@ function db_query_temporary($query) {
   $args = func_get_args();
   $tablename = array_pop($args);
   array_shift($args);
-
-  $query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE '. $tablename .' AS SELECT', db_prefix_tables($query));
+  
+  $query = preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE '. $tablename .' AS SELECT', $query);
   if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax
     $args = $args[0];
   }
-  _db_query_callback($args, TRUE);
-  $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
-  return _db_query($query);
+  return db_query($query, $args);;
+}
+
+/**
+ * Prepare user input for use in a database query, preventing SQL injection attacks.
+ * Note: This function requires PostgreSQL 7.2 or later.
+ */
+function db_escape_string($data) {
+  return pg_escape_string($data);
 }
 
 /**
@@ -357,14 +365,6 @@ function db_decode_blob($data) {
 }
 
 /**
- * Prepare user input for use in a database query, preventing SQL injection attacks.
- * Note: This function requires PostgreSQL 7.2 or later.
- */
-function db_escape_string($text) {
-  return pg_escape_string($text);
-}
-
-/**
  * Lock a table.
  * This function automatically starts a transaction.
  */
@@ -443,39 +443,37 @@ function db_type_map() {
   // it much easier for modules (such as schema.module) to map
   // database types back into schema types.
   $map = array(
-    'varchar:normal' => 'varchar',
-    'char:normal' => 'character',
+    'varchar:normal'  => 'VARCHAR',
+    'char:normal'     => 'CHARACTER',
+
+    'text:tiny'       => 'TEXT',
+    'text:small'      => 'TEXT',
+    'text:medium'     => 'TEXT',
+    'text:big'        => 'TEXT',
+    'text:normal'     => 'TEXT',
+
+    'serial:tiny'     => 'SERIAL',
+    'serial:small'    => 'SERIAL',
+    'serial:medium'   => 'SERIAL',
+    'serial:big'      => 'BIGSERIAL',
+    'serial:normal'   => 'SERIAL',
+
+    'int:tiny'        => 'SMALLINT',
+    'int:small'       => 'SMALLINT',
+    'int:medium'      => 'INT',
+    'int:big'         => 'BIGINT',
+    'int:normal'      => 'INT',
+
+    'float:tiny'      => 'REAL',
+    'float:small'     => 'REAL',
+    'float:medium'    => 'REAL',
+    'float:big'       => 'DOUBLE PRECISION',
+    'float:normal'    => 'REAL',
 
-    'text:tiny' => 'text',
-    'text:small' => 'text',
-    'text:medium' => 'text',
-    'text:big' => 'text',
-    'text:normal' => 'text',
-
-    'int:tiny' => 'smallint',
-    'int:small' => 'smallint',
-    'int:medium' => 'int',
-    'int:big' => 'bigint',
-    'int:normal' => 'int',
-
-    'float:tiny' => 'real',
-    'float:small' => 'real',
-    'float:medium' => 'real',
-    'float:big' => 'double precision',
-    'float:normal' => 'real',
-
-    'numeric:normal' => 'numeric',
-
-    'blob:big' => 'bytea',
-    'blob:normal' => 'bytea',
-
-    'datetime:normal' => 'timestamp',
-
-    'serial:tiny' => 'serial',
-    'serial:small' => 'serial',
-    'serial:medium' => 'serial',
-    'serial:big' => 'bigserial',
-    'serial:normal' => 'serial',
+    'numeric:normal'  => 'NUMERIC',
+
+    'blob:big'        => 'BYTEA',
+    'blob:normal'     => 'BYTEA',
   );
   return $map;
 }
@@ -543,17 +541,17 @@ function _db_create_key_sql($fields) {
   return implode(', ', $ret);
 }
 
-function _db_create_keys(&$ret, $table, $new_keys) {
-  if (isset($new_keys['primary key'])) {
-    db_add_primary_key($ret, $table, $new_keys['primary key']);
+function _db_create_keys(&$ret, $table, $keys_new) {
+  if (isset($keys_new['primary key'])) {
+    db_add_primary_key($ret, $table, $keys_new['primary key']);
   }
-  if (isset($new_keys['unique keys'])) {
-    foreach ($new_keys['unique keys'] as $name => $fields) {
+  if (isset($keys_new['unique keys'])) {
+    foreach ($keys_new['unique keys'] as $name => $fields) {
       db_add_unique_key($ret, $table, $name, $fields);
     }
   }
-  if (isset($new_keys['indexes'])) {
-    foreach ($new_keys['indexes'] as $name => $fields) {
+  if (isset($keys_new['indexes'])) {
+    foreach ($keys_new['indexes'] as $name => $fields) {
       db_add_index($ret, $table, $name, $fields);
     }
   }
@@ -618,7 +616,7 @@ function _db_create_field_sql($name, $sp
   }
   if (isset($spec['default'])) {
     $default = is_string($spec['default']) ? "'". $spec['default'] ."'" : $spec['default'];
-    $sql .= " default $default";
+    $sql .= " DEFAULT $default";
   }
 
   return $sql;
@@ -673,7 +671,7 @@ function db_drop_table(&$ret, $table) {
  *   or index including it in this array. @see db_change_field for more
  *   explanation why.
  */
-function db_add_field(&$ret, $table, $field, $spec, $new_keys = array()) {
+function db_add_field(&$ret, $table, $field, $spec, $keys_new = array()) {
   $fixnull = FALSE;
   if (!empty($spec['not null']) && !isset($spec['default'])) {
     $fixnull = TRUE;
@@ -691,8 +689,8 @@ function db_add_field(&$ret, $table, $fi
   if ($fixnull) {
     $ret[] = update_sql("ALTER TABLE {". $table ."} ALTER $field SET NOT NULL");
   }
-  if (isset($new_keys)) {
-    _db_create_keys($ret, $table, $new_keys);
+  if (isset($keys_new)) {
+    _db_create_keys($ret, $table, $keys_new);
   }
 }
 
@@ -847,7 +845,7 @@ function db_drop_index(&$ret, $table, $n
  * That means that you have to drop all affected keys and indexes with
  * db_drop_{primary_key,unique_key,index}() before calling db_change_field().
  * To recreate the keys and indices, pass the key definitions as the
- * optional $new_keys argument directly to db_change_field().
+ * optional $keys_new argument directly to db_change_field().
  *
  * For example, suppose you have:
  * @code
@@ -878,12 +876,12 @@ function db_drop_index(&$ret, $table, $n
  * db_add_{primary_key,unique_key,index}() for this purpose because
  * the ALTER TABLE command will fail to add the column without a key
  * or index specification.  The solution is to use the optional
- * $new_keys argument to create the key or index at the same time as
+ * $keys_new argument to create the key or index at the same time as
  * field.
  *
  * You could use db_add_{primary_key,unique_key,index}() in all cases
  * unless you are converting a field to be type serial. You can use
- * the $new_keys argument in all cases.
+ * the $keys_new argument in all cases.
  *
  * @param $ret
  *   Array to which query results will be added.
@@ -895,12 +893,12 @@ function db_drop_index(&$ret, $table, $n
  *   New name for the field (set to the same as $field if you don't want to change the name).
  * @param $spec
  *   The field specification for the new field.
- * @param $new_keys
+ * @param $keys_new
  *   Optional keys and indexes specification to be created on the
  *   table along with changing the field. The format is the same as a
  *   table specification but without the 'fields' element.
  */
-function db_change_field(&$ret, $table, $field, $field_new, $spec, $new_keys = array()) {
+function db_change_field(&$ret, $table, $field, $field_new, $spec, $keys_new = array()) {
   $ret[] = update_sql("ALTER TABLE {". $table ."} RENAME $field TO ". $field ."_old");
   $not_null = isset($spec['not null']) ? $spec['not null'] : FALSE;
   unset($spec['not null']);
@@ -915,12 +913,11 @@ function db_change_field(&$ret, $table, 
 
   db_drop_field($ret, $table, $field .'_old');
 
-  if (isset($new_keys)) {
-    _db_create_keys($ret, $table, $new_keys);
+  if (isset($keys_new)) {
+    _db_create_keys($ret, $table, $keys_new);
   }
 }
 
 /**
  * @} End of "ingroup schemaapi".
  */
-
Index: includes/install.pgsql.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/install.pgsql.inc,v
retrieving revision 1.6
diff -u -p -r1.6 install.pgsql.inc
--- includes/install.pgsql.inc	22 Oct 2007 15:22:39 -0000	1.6
+++ includes/install.pgsql.inc	4 Jan 2008 18:59:43 -0000
@@ -10,7 +10,7 @@
  *  TRUE/FALSE
  */
 function pgsql_is_available() {
-  return function_exists('pg_connect');
+  return function_exists('pg_connect') && extension_loaded('pgsql');
 }
 
 /**
@@ -137,4 +137,4 @@ function drupal_test_pgsql($url, &$succe
 
   pg_close($connection);
   return TRUE;
-}
\ No newline at end of file
+}
