=== modified file 'includes/database/mysql/schema.inc'
--- includes/database/mysql/schema.inc	2008-08-21 19:36:35 +0000
+++ includes/database/mysql/schema.inc	2008-09-01 13:49:21 +0000
@@ -17,7 +17,7 @@ class DatabaseSchema_mysql extends Datab
   public function tableExists($table) {
     return (bool) $this->connection->query("SHOW TABLES LIKE '{" . $table . "}'", array(), array())->fetchField();
   }
-  
+
   public function columnExists($table, $column) {
     return (bool) $this->connection->query("SHOW COLUMNS FROM {" . $this->escapeTable($table) . "} LIKE '" . $this->escapeTable($column) . "'", array(), array())->fetchField();
   }
@@ -37,25 +37,25 @@ class DatabaseSchema_mysql extends Datab
     if (empty($table['mysql_suffix'])) {
       $table['mysql_suffix'] = "/*!40100 DEFAULT CHARACTER SET UTF8 */";
     }
-  
+
     $sql = "CREATE TABLE {" . $name . "} (\n";
-  
+
     // Add the SQL statement for each field.
     foreach ($table['fields'] as $field_name => $field) {
       $sql .= $this->createFieldSql($field_name, $this->processField($field)) . ", \n";
     }
-  
+
     // Process keys & indexes.
     $keys = $this->createKeysSql($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);
   }
 
@@ -72,40 +72,40 @@ class DatabaseSchema_mysql extends Datab
    */
   protected function createFieldSql($name, $spec) {
     $sql = "`" . $name . "` " . $spec['mysql_type'];
-  
+
     if (isset($spec['length'])) {
       $sql .= '(' . $spec['length'] . ')';
     }
     elseif (isset($spec['precision']) && isset($spec['scale'])) {
       $sql .= '(' . $spec['precision'] . ', ' . $spec['scale'] . ')';
     }
-  
+
     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;
   }
-  
+
   /**
    * Set database-engine specific properties for a field.
    *
@@ -113,21 +113,21 @@ class DatabaseSchema_mysql extends Datab
    *   A field description array, as specified in the schema documentation.
    */
   protected function processField($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;
   }
 
@@ -138,41 +138,41 @@ class DatabaseSchema_mysql extends Datab
     static $map = array(
       'varchar:normal'  => 'VARCHAR',
       'char:normal'     => 'CHAR',
-  
+
       'text:tiny'       => 'TINYTEXT',
       'text:small'      => 'TINYTEXT',
       '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;
   }
-  
+
 
 
 
@@ -195,7 +195,7 @@ class DatabaseSchema_mysql extends Datab
 
     return $keys;
   }
-  
+
   protected function createKeySql($fields) {
     $ret = array();
     foreach ($fields as $field) {
@@ -225,7 +225,7 @@ class DatabaseSchema_mysql extends Datab
   public function renameTable(&$ret, $table, $new_name) {
     $ret[] = update_sql('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}');
   }
-  
+
   public function dropTable(&$ret, $table) {
     $ret[] = update_sql('DROP TABLE {' . $table . '}');
   }
@@ -259,13 +259,13 @@ class DatabaseSchema_mysql extends Datab
   }
 
   public function fieldSetDefault(&$ret, $table, $field, $default) {
-    if ($default == NULL) {
+    if ($default === NULL) {
       $default = 'NULL';
     }
     else {
       $default = is_string($default) ? "'$default'" : $default;
     }
-  
+
     $ret[] = update_sql('ALTER TABLE {' . $table . '} ALTER COLUMN ' . $field . ' SET DEFAULT ' . $default);
   }
 
@@ -276,7 +276,7 @@ class DatabaseSchema_mysql extends Datab
   public function addPrimaryKey(&$ret, $table, $fields) {
     $ret[] = update_sql('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . $this->createKeySql($fields) . ')');
   }
-  
+
   public function dropPrimaryKey(&$ret, $table) {
     $ret[] = update_sql('ALTER TABLE {' . $table . '} DROP PRIMARY KEY');
   }
@@ -288,7 +288,7 @@ class DatabaseSchema_mysql extends Datab
   public function dropUniqueKey(&$ret, $table, $name) {
     $ret[] = update_sql('ALTER TABLE {' . $table . '} DROP KEY ' . $name);
   }
-  
+
   public function addIndex(&$ret, $table, $name, $fields) {
     $query = 'ALTER TABLE {' . $table . '} ADD INDEX ' . $name . ' (' . $this->createKeySql($fields) . ')';
     $ret[] = update_sql($query);
@@ -297,7 +297,7 @@ class DatabaseSchema_mysql extends Datab
   public function dropIndex(&$ret, $table, $name) {
     $ret[] = update_sql('ALTER TABLE {' . $table . '} DROP INDEX ' . $name);
   }
-  
+
   public function changeField(&$ret, $table, $field, $field_new, $spec, $keys_new = array()) {
     $sql = 'ALTER TABLE {' . $table . '} CHANGE ' . $field . ' ' . $this->createFieldSql($field_new, $this->processField($spec));
     if (count($keys_new)) {

=== added file 'modules/simpletest/tests/schema.test'
--- modules/simpletest/tests/schema.test	1970-01-01 00:00:00 +0000
+++ modules/simpletest/tests/schema.test	2008-09-01 17:07:40 +0000
@@ -0,0 +1,76 @@
+<?php
+// $Id$
+
+class SchemaTestCase extends DrupalWebTestCase {
+  /**
+   * Implementation of getInfo().
+   */
+  function getInfo() {
+    return array(
+      'name' => t('Schema API'),
+      'description' => t('Tests table creation and modification via the schema API.'),
+      'group' => t('System'),
+    );
+  }
+
+  /**
+   *
+   */
+  function testSchema() {
+    $table_name = 'test';
+    $table_specification = array(
+      'fields' => array(
+        'id'  => array(
+          'type' => 'int',
+          'not null' => TRUE,
+          'default' => NULL,
+        ),
+        'test'  => array(
+          'type' => 'int',
+          'not null' => TRUE,
+        ),
+      ),
+    );
+    $ret = array();
+    db_create_table($ret, $table_name, $table_specification);
+    $this->assertTrue(db_table_exists($table_name), t('The table exists.'));
+    $field_name = 'test';
+    $this->assertFalse($this->tryInsert(), t('Insert without a default failed.'));
+    db_field_set_default($ret, $table_name, $field_name, 0);
+    $this->assertTrue($this->tryInsert(), t('Insert with a default succeeded.'));
+    db_field_set_no_default($ret, $table_name, $field_name);
+    $this->assertFalse($this->tryInsert(), t('Insert without a default failed.'));
+    db_rename_table($ret, $table_name, $table_name . '_test');
+    // We need the default so that we can insert after the rename.
+    db_field_set_default($ret, $table_name . '_test', $field_name, 0);
+    $this->assertFalse($this->tryInsert(), t('Insert into the old table failed.'));
+    $this->assertTrue($this->tryInsert('_test'), t('Insert into the new table succeeded.'));
+    db_drop_table($ret, $table_name . '_test');
+    $this->assertFalse(db_table_exists($table_name . '_test'), t('The renamed table does not exist.'));
+    db_create_table($ret, $table_name, $table_specification);
+    db_field_set_default($ret, $table_name, $field_name, 0);
+    db_add_field($ret, $table_name, 'test2', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
+    db_change_field($ret, $table_name, 'test2', 'test2', array('type' => 'serial', 'not null' => TRUE), array('primary key' => array('test2')));
+    $this->assertTrue($this->tryInsert(), t('Insert with a serial succeeded.'));
+    $this->assertTrue($this->tryInsert(), t('Insert with a serial succeeded.'));
+    $max = 0;
+    $counter = 0;
+    foreach (db_query('SELECT test2 FROM {test} ORDER BY test2') as $row) {
+      $counter++;
+      $this->assertTrue(!$max || $row->test2 > $max, t('The serial is monotone.'));
+      $max = $row->test2;
+    }
+    $this->assertTrue($max, t('There was a non zero serial.'));
+    $this->assertEqual($counter, 2, t('There were two rows.'));
+  }
+
+  function tryInsert($tablepostfix = '') {
+    try {
+      db_query("INSERT INTO {test$tablepostfix} (id) VALUES (:id)", array(':id' => mt_rand(10,20)));
+      return TRUE;
+    }
+    catch (Exception $e) {
+      return FALSE;
+    }
+  }
+}
\ No newline at end of file

