diff --git includes/database/mysql/schema.inc includes/database/mysql/schema.inc index af45b38..cacc097 100644 --- includes/database/mysql/schema.inc +++ includes/database/mysql/schema.inc @@ -210,7 +210,11 @@ class DatabaseSchema_mysql extends DatabaseSchema { 'blob:big' => 'LONGBLOB', 'blob:normal' => 'BLOB', + 'date:normal' => 'DATE', + 'datetime:normal' => 'DATETIME', + + 'time:normal' => 'TIME', ); return $map; } diff --git includes/database/pgsql/schema.inc includes/database/pgsql/schema.inc index ae21758..1d69f28 100644 --- includes/database/pgsql/schema.inc +++ includes/database/pgsql/schema.inc @@ -242,7 +242,10 @@ class DatabaseSchema_pgsql extends DatabaseSchema { 'blob:big' => 'bytea', 'blob:normal' => 'bytea', + 'date:normal' => 'date', + 'datetime:normal' => 'timestamp without time zone', + 'time:normal' => 'time without time zone', 'serial:tiny' => 'serial', 'serial:small' => 'serial', diff --git includes/database/sqlite/schema.inc includes/database/sqlite/schema.inc index 007a69b..5f78338 100644 --- includes/database/sqlite/schema.inc +++ includes/database/sqlite/schema.inc @@ -202,6 +202,10 @@ class DatabaseSchema_sqlite extends DatabaseSchema { 'blob:big' => 'BLOB', 'blob:normal' => 'BLOB', + 'date:normal' => 'DATE', + + 'time:nornaml' => 'TIME', + 'datetime:normal' => 'TIMESTAMP', ); return $map; diff --git modules/simpletest/tests/database_test.test modules/simpletest/tests/database_test.test index dd0d348..7458df4 100644 --- modules/simpletest/tests/database_test.test +++ modules/simpletest/tests/database_test.test @@ -2711,3 +2711,109 @@ class DatabaseTransactionTestCase extends DatabaseTestCase { } } } + + +/** + * Test proposed new data types for the schema API + * + */ +class DatabaseExtraTypesTestCase extends DrupalWebTestCase { + + public static function getInfo() { + return array( + 'name' => t('Extra Types tests'), + 'description' => t('Test the Extra Types.'), + 'group' => t('Database'), + ); + } + + + /** + * Test the date data type + * + */ + function testDateField() { + try { + $date_table = array('fields' => array( + 'date_field' => array( + 'description' => t('Test Date field'), + 'type' => 'date', + 'not null' => FALSE, + ) + ) + ); + $ret = array(); + db_create_table($ret, 'date_table', $date_table); + $this->assertEqual($ret[0]['success'], 1, t('created table with date field')); + + db_insert('date_table')->fields(array('date_field')) + ->values(array('date_field' => '2001-01-01')) + ->values(array('date_field' => '1856-12-31')) + ->values(array('date_field' => '2100-06-30')) + ->execute(); + + $num_records = (int) db_query('SELECT COUNT(*) FROM {date_table}')->fetchField(); + $this->assertEqual($num_records, 3, t('Inserted 3 records, and counted 3 records')); + $res = db_query("select date_field from {date_table} order by date_field"); + + $date = $res->fetch()->date_field; + $this->assertEqual($date, '1856-12-31', t('date retrieved in order ') . $date); + $date = $res->fetch()->date_field; + $this->assertEqual($date, '2001-01-01', t('date retrieved in order ') . $date); + $date = $res->fetch()->date_field; + $this->assertEqual($date, '2100-06-30', t('date retrieved in order ') . $date); + + + db_drop_table($ret, 'date_table'); + $this->assertEqual($ret[1]['success'], 1, t('Dropped table with date field')); + + } catch (Exception $e) { + $this->fail($e->getMessage()); + } + + } + + /** + * Test the time data type + */ + function testTimeField() { + try { + $time_table = array('fields' => array( + 'time_field' => array( + 'description' => t('Test Time field'), + 'type' => 'time', + 'not null' => FALSE, + ) + ) + ); + $ret = array(); + db_create_table($ret, 'time_table', $time_table); + $this->assertEqual($ret[0]['success'], 1, t('created table with time field')); + + db_insert('time_table')->fields(array('time_field')) + ->values(array('time_field' => '12:59:00')) + ->values(array('time_field' => '00:01:00')) + ->values(array('time_field' => '23:17:00')) + ->execute(); + + $num_records = (int) db_query('SELECT COUNT(*) FROM {time_table}')->fetchField(); + $this->assertEqual($num_records, 3, t('Inserted 3 records, and counted 3 records')); + $res = db_query("select time_field from {time_table} order by time_field"); + + $time = $res->fetch()->time_field; + $this->assertEqual($time, '00:01:00', t('time retrieved in order ' . $time)); + $time = $res->fetch()->time_field; + $this->assertEqual($time, '12:59:00', t('time retrieved in order ' . $time)); + $time = $res->fetch()->time_field; + $this->assertEqual($time, '23:17:00', t('time retrieved in order ' . $time)); + + db_drop_table($ret, 'time_table'); + $this->assertEqual($ret[1]['success'], 1, t('Dropped table with time field')); + } catch (Exception $e) { + $this->fail($e->getMessage()); + } + + } + +} +