Skip to content

Commit d5cfb1d

Browse files
committed
supprot and tests for fractional seconds precision on time types
1 parent e8db894 commit d5cfb1d

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

src/SQLParser.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,6 @@ function parse_field($tokens){
550550

551551
# DATE
552552
case 'DATE':
553-
case 'TIME':
554-
case 'TIMESTAMP':
555-
case 'DATETIME':
556553
case 'YEAR':
557554
case 'TINYBLOB':
558555
case 'BLOB':
@@ -563,6 +560,23 @@ function parse_field($tokens){
563560
break;
564561

565562

563+
# TIME[(fsp)]
564+
case 'TIME':
565+
case 'TIMESTAMP':
566+
case 'DATETIME':
567+
568+
# optional fractional seconds precision
569+
if (count($tokens) >= 3){
570+
if ($tokens[0] == '(' && $tokens[2] == ')'){
571+
$f['fsp'] = $tokens[1];
572+
array_shift($tokens);
573+
array_shift($tokens);
574+
array_shift($tokens);
575+
}
576+
}
577+
break;
578+
579+
566580
# TINYINT[(length)] [UNSIGNED] [ZEROFILL]
567581
case 'TINYINT':
568582
case 'SMALLINT':

tests/FieldTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,23 @@ function testTimes(){
165165
# TIME[(fsp)]
166166
# TIMESTAMP[(fsp)]
167167
# DATETIME[(fsp)]
168+
169+
$tbl = $this->get_first_table("CREATE TABLE foo (bar TIME)");
170+
$this->assertEquals($tbl['fields'], [
171+
[
172+
'name' => "bar",
173+
'type' => "TIME",
174+
]
175+
]);
176+
177+
$tbl = $this->get_first_table("CREATE TABLE foo (bar TIMESTAMP(6))");
178+
$this->assertEquals($tbl['fields'], [
179+
[
180+
'name' => "bar",
181+
'type' => "TIMESTAMP",
182+
'fsp' => 6,
183+
]
184+
]);
168185
}
169186

170187
function testBits(){

0 commit comments

Comments
 (0)