Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
305
Merge Requests
305
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
d71ffc5a
Commit
d71ffc5a
authored
Aug 22, 2009
by
webchick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#200953
by seanburlington: Added basic support for 'time' and 'date' types to schema API.
parent
2ee24205
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
0 deletions
+118
-0
includes/database/mysql/schema.inc
includes/database/mysql/schema.inc
+4
-0
includes/database/pgsql/schema.inc
includes/database/pgsql/schema.inc
+4
-0
includes/database/sqlite/schema.inc
includes/database/sqlite/schema.inc
+4
-0
modules/simpletest/tests/database_test.test
modules/simpletest/tests/database_test.test
+106
-0
No files found.
includes/database/mysql/schema.inc
View file @
d71ffc5a
...
...
@@ -210,7 +210,11 @@ public function getFieldTypeMap() {
'blob:big'
=>
'LONGBLOB'
,
'blob:normal'
=>
'BLOB'
,
'date:normal'
=>
'DATE'
,
'datetime:normal'
=>
'DATETIME'
,
'time:normal'
=>
'TIME'
,
);
return
$map
;
}
...
...
includes/database/pgsql/schema.inc
View file @
d71ffc5a
...
...
@@ -242,7 +242,11 @@ function getFieldTypeMap() {
'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'
,
...
...
includes/database/sqlite/schema.inc
View file @
d71ffc5a
...
...
@@ -202,6 +202,10 @@ public function getFieldTypeMap() {
'blob:big'
=>
'BLOB'
,
'blob:normal'
=>
'BLOB'
,
'date:normal'
=>
'DATE'
,
'time:normal'
=>
'TIME'
,
'datetime:normal'
=>
'TIMESTAMP'
,
);
return
$map
;
...
...
modules/simpletest/tests/database_test.test
View file @
d71ffc5a
...
...
@@ -2777,3 +2777,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'
=>
'Extra Types tests'
,
'description'
=>
'Test the Extra Types.'
,
'group'
=>
'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'
,
array
(
'@date'
=>
$date
)));
$date
=
$res
->
fetch
()
->
date_field
;
$this
->
assertEqual
(
$date
,
'2001-01-01'
,
t
(
'Date retrieved in order @date'
,
array
(
'@date'
=>
$date
)));
$date
=
$res
->
fetch
()
->
date_field
;
$this
->
assertEqual
(
$date
,
'2100-06-30'
,
t
(
'Date retrieved in order @date'
,
array
(
'@date'
=>
$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'
,
array
(
'@time'
=>
$time
)));
$time
=
$res
->
fetch
()
->
time_field
;
$this
->
assertEqual
(
$time
,
'12:59:00'
,
t
(
'Time retrieved in order @time'
,
array
(
'@time'
=>
$time
)));
$time
=
$res
->
fetch
()
->
time_field
;
$this
->
assertEqual
(
$time
,
'23:17:00'
,
t
(
'Time retrieved in order @time'
,
array
(
'@time'
=>
$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
());
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment