File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -677,6 +677,29 @@ public function getBasetype(): string
677677
678678 public static function getTypeByBasetype (string $ basetype ): string
679679 {
680- throw new LogicException ('Method is not implemented yet. ' );
680+ $ basetype = strtoupper ($ basetype );
681+
682+ if (!BaseType::isValid ($ basetype )) {
683+ throw new InvalidTypeException (sprintf ('Base type "%s" is not valid. ' , $ basetype ));
684+ }
685+
686+ switch ($ basetype ) {
687+ case BaseType::BOOLEAN :
688+ return self ::TYPE_BYTEINT ;
689+ case BaseType::DATE :
690+ return self ::TYPE_DATE ;
691+ case BaseType::FLOAT :
692+ return self ::TYPE_FLOAT ;
693+ case BaseType::INTEGER :
694+ return self ::TYPE_INTEGER ;
695+ case BaseType::NUMERIC :
696+ return self ::TYPE_NUMBER ;
697+ case BaseType::STRING :
698+ return self ::TYPE_VARCHAR ;
699+ case BaseType::TIMESTAMP :
700+ return self ::TYPE_TIMESTAMP ;
701+ }
702+
703+ throw new LogicException (sprintf ('Definition for base type "%s" is missing. ' , $ basetype ));
681704 }
682705}
Original file line number Diff line number Diff line change @@ -347,4 +347,18 @@ public function invalidLengths(): array
347347 ['INTERVAL YEAR TO MONTH ' , '5 ' ],
348348 ];
349349 }
350+
351+ public function testGetTypeByBasetype (): void
352+ {
353+ $ this ->assertSame ('DATE ' , Teradata::getTypeByBasetype ('DATE ' ));
354+
355+ $ this ->assertSame ('VARCHAR ' , Teradata::getTypeByBasetype ('STRING ' ));
356+
357+ // not only upper case
358+ $ this ->assertSame ('DATE ' , Teradata::getTypeByBasetype ('Date ' ));
359+
360+ $ this ->expectException (InvalidTypeException::class);
361+ $ this ->expectExceptionMessage ('Base type "FOO" is not valid. ' );
362+ Teradata::getTypeByBasetype ('foo ' );
363+ }
350364}
You can’t perform that action at this time.
0 commit comments