@@ -20,18 +20,19 @@ std::optional<std::string> processFunction(const StringView seq, Lexer & lex);
2020std::optional<std::string> processEscapeSequencesImpl (const StringView seq, Lexer & lex);
2121
2222const std::map<const std::string, const std::string> fn_convert_map {
23- {" SQL_TINYINT" , " toUInt8" },
24- {" SQL_SMALLINT" , " toUInt16" },
25- {" SQL_INTEGER" , " toInt32" },
26- {" SQL_BIGINT" , " toInt64" },
27- {" SQL_REAL" , " toFloat32" },
28- {" SQL_DOUBLE" , " toFloat64" },
29- {" SQL_CHAR" , " toString" },
30- {" SQL_VARCHAR" , " toString" },
31- {" SQL_DATE" , " toDate" },
32- {" SQL_TYPE_DATE" , " toDate" },
33- {" SQL_TIMESTAMP" , " toDateTime" },
34- {" SQL_TYPE_TIMESTAMP" , " toDateTime" },
23+ {" SQL_TINYINT" , " UInt8" },
24+ {" SQL_SMALLINT" , " UInt16" },
25+ {" SQL_INTEGER" , " Int32" },
26+ {" SQL_BIGINT" , " Int64" },
27+ {" SQL_REAL" , " Float32" },
28+ {" SQL_DOUBLE" , " Float64" },
29+ {" SQL_CHAR" , " String" },
30+ {" SQL_VARCHAR" , " String" },
31+ {" SQL_TIME" , " Time" },
32+ {" SQL_DATE" , " Date" },
33+ {" SQL_TYPE_DATE" , " Date" },
34+ {" SQL_TIMESTAMP" , " DateTime" },
35+ {" SQL_TYPE_TIMESTAMP" , " DateTime" },
3536};
3637
3738#define DECLARE2 (TOKEN, NAME ) \
@@ -204,7 +205,7 @@ std::optional<std::string> processFunction(const StringView seq, Lexer & lex) {
204205 }
205206 if (!lex.Match (Token::RPARENT))
206207 return std::nullopt ;
207- return func_it-> second + " ( " + result + " )" ;
208+ return " CAST( " + result + " AS " + func_it-> second + " )" ;
208209 } else if (fn.type == Token::FN_BIT_LENGTH) {
209210 if (!lex.Match (Token::LPARENT))
210211 return std::nullopt ;
@@ -406,6 +407,15 @@ std::optional<std::string> processFunction(const StringView seq, Lexer & lex) {
406407 return seq.to_string ();
407408}
408409
410+ std::optional<std::string> processTime (const StringView seq, Lexer & lex) {
411+ Token data = lex.Consume (Token::STRING);
412+ if (data.isInvalid ()) {
413+ return std::nullopt ;
414+ } else {
415+ return std::string (" cast(" ) + data.literal .to_string () + " as Time)" ;
416+ }
417+ }
418+
409419std::optional<std::string> processDate (const StringView seq, Lexer & lex) {
410420 Token data = lex.Consume (Token::STRING);
411421 if (data.isInvalid ()) {
@@ -462,6 +472,14 @@ std::optional<std::string> processEscapeSequencesImpl(const StringView seq, Lexe
462472 break ;
463473 }
464474
475+ case Token::T: {
476+ auto processed = processTime (seq, lex);
477+ if (!processed)
478+ return std::nullopt ;
479+ result += *processed;
480+ break ;
481+ }
482+
465483 case Token::D: {
466484 auto processed = processDate (seq, lex);
467485 if (!processed)
@@ -482,10 +500,6 @@ std::optional<std::string> processEscapeSequencesImpl(const StringView seq, Lexe
482500 // End of escape sequence
483501 return result;
484502
485- case Token::T:
486- // Unimplemented
487- return std::nullopt ;
488-
489503 default :
490504 // Positional query parameters, just like ODBC escape sequences, also wrapped in
491505 // curly braces. However they always have a fixed `{name : type}` format, with colon
0 commit comments