--- C:\Users\Edward\Webs\drupal\includes\database.mysql-common.inc 2008-01-15 23:26:00.375000000 -0500 +++ C:\Users\Edward\Webs\drupal\includes\database.mysql-common.inc.formatted 2008-01-16 17:45:46.461357100 -0500 @@ -1,6 +1,7 @@ $field) { $sql .= _db_create_field_sql($field_name, _db_process_field($field)) .", \n"; } - + // Process keys & indexes. $keys = _db_create_keys_sql($table); if (count($keys)) { $sql .= implode(", \n", $keys) .", \n"; } - + // Remove the last comma and space. $sql = substr($sql, 0, -3) ."\n) "; - + $sql .= $table['mysql_suffix']; - + return array($sql); } function _db_create_keys_sql($spec) { $keys = array(); - + if (!empty($spec['primary key'])) { $keys[] = 'PRIMARY KEY ('. _db_create_key_sql($spec['primary key']) .')'; } @@ -100,7 +103,7 @@ $keys[] = 'INDEX '. $index .' ('. _db_create_key_sql($fields) .')'; } } - + return $keys; } @@ -124,21 +127,21 @@ * A field description array, as specified in the schema documentation. */ function _db_process_field($field) { - + if (!isset($field['size'])) { $field['size'] = 'normal'; } - + // Set the correct database-engine specific datatype. if (!isset($field['mysql_type'])) { $map = db_type_map(); $field['mysql_type'] = $map[$field['type'] .':'. $field['size']]; } - + if ($field['type'] == 'serial') { $field['auto_increment'] = TRUE; } - + return $field; } @@ -155,37 +158,37 @@ */ function _db_create_field_sql($name, $spec) { $sql = "`". $name ."` ". $spec['mysql_type']; - + if (isset($spec['length'])) { $sql .= '('. $spec['length'] .')'; } elseif (isset($spec['precision']) && isset($spec['scale'])) { $sql .= '('. $spec['scale'] .', '. $spec['precision'] .')'; } - + if (!empty($spec['unsigned'])) { $sql .= ' unsigned'; } - + if (!empty($spec['not null'])) { $sql .= ' NOT NULL'; } - + if (!empty($spec['auto_increment'])) { $sql .= ' auto_increment'; } - + if (isset($spec['default'])) { if (is_string($spec['default'])) { $spec['default'] = "'". $spec['default'] ."'"; } $sql .= ' DEFAULT '. $spec['default']; } - + if (empty($spec['not null']) && !isset($spec['default'])) { $sql .= ' DEFAULT NULL'; } - + return $sql; } @@ -198,38 +201,31 @@ // it much easier for modules (such as schema.module) to map // database types back into schema types. $map = array( - 'varchar:normal' => 'VARCHAR', - 'char:normal' => 'CHAR', - - 'text:tiny' => 'SMALLTEXT', - 'text:small' => 'SMALLTEXT', - 'text:medium' => 'MEDIUMTEXT', - 'text:big' => 'LONGTEXT', - 'text:normal' => 'TEXT', - - 'serial:tiny' => 'TINYINT', - 'serial:small' => 'SMALLINT', - 'serial:medium' => 'MEDIUMINT', - 'serial:big' => 'BIGINT', - 'serial:normal' => 'INT', - - 'int:tiny' => 'TINYINT', - 'int:small' => 'SMALLINT', - 'int:medium' => 'MEDIUMINT', - 'int:big' => 'BIGINT', - 'int:normal' => 'INT', - - 'float:tiny' => 'FLOAT', - 'float:small' => 'FLOAT', - 'float:medium' => 'FLOAT', - 'float:big' => 'DOUBLE', - 'float:normal' => 'FLOAT', - - 'numeric:normal' => 'DECIMAL', - - 'blob:big' => 'LONGBLOB', - 'blob:normal' => 'BLOB', - + 'varchar:normal' => 'VARCHAR', + 'char:normal' => 'CHAR', + 'text:tiny' => 'SMALLTEXT', + 'text:small' => 'SMALLTEXT', + 'text:medium' => 'MEDIUMTEXT', + 'text:big' => 'LONGTEXT', + 'text:normal' => 'TEXT', + 'serial:tiny' => 'TINYINT', + 'serial:small' => 'SMALLINT', + 'serial:medium' => 'MEDIUMINT', + 'serial:big' => 'BIGINT', + 'serial:normal' => 'INT', + 'int:tiny' => 'TINYINT', + 'int:small' => 'SMALLINT', + 'int:medium' => 'MEDIUMINT', + 'int:big' => 'BIGINT', + 'int:normal' => 'INT', + 'float:tiny' => 'FLOAT', + 'float:small' => 'FLOAT', + 'float:medium' => 'FLOAT', + 'float:big' => 'DOUBLE', + 'float:normal' => 'FLOAT', + 'numeric:normal' => 'DECIMAL', + 'blob:big' => 'LONGBLOB', + 'blob:normal' => 'BLOB', 'datetime:normal' => 'DATETIME', ); return $map; @@ -298,9 +294,9 @@ $ret[] = update_sql($query); if (isset($spec['initial'])) { // All this because update_sql does not support %-placeholders. - $sql = 'UPDATE {'. $table .'} SET '. $field .' = '. db_type_placeholder($spec['type']); + $sql = 'UPDATE {'. $table .'} SET '. $field .' = '. db_type_placeholder($spec['type']); $result = db_query($sql, $spec['initial']); - $ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql .' ('. $spec['initial'] .')')); + $ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql .' ('. $spec['initial'] .')')); } if ($fixnull) { $spec['not null'] = TRUE; @@ -341,7 +337,7 @@ else { $default = is_string($default) ? "'$default'" : $default; } - + $ret[] = update_sql('ALTER TABLE {'. $table .'} ALTER COLUMN '. $field .' SET DEFAULT '. $default); } @@ -510,10 +506,8 @@ * 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, $keys_new = array()) { - $sql = 'ALTER TABLE {'. $table .'} CHANGE '. $field .' '. - _db_create_field_sql($field_new, _db_process_field($spec)); + $sql = 'ALTER TABLE {'. $table .'} CHANGE '. $field .' '. _db_create_field_sql($field_new, _db_process_field($spec)); if (count($keys_new)) { $sql .= ', ADD '. implode(', ADD ', _db_create_keys_sql($keys_new)); } @@ -531,3 +525,4 @@ function db_last_insert_id($table, $field) { return db_result(db_query('SELECT LAST_INSERT_ID()')); } +