1111using Xtensive . Sql . Dml ;
1212using Xtensive . Sql . Model ;
1313using Xtensive . Sql . Drivers . Oracle . Resources ;
14+ using System . Collections . Generic ;
1415
1516namespace Xtensive . Sql . Drivers . Oracle . v09
1617{
@@ -73,7 +74,7 @@ public override void Visit(SqlFunctionCall node)
7374 DateConstruct( node . Arguments [ 0 ] , node . Arguments [ 1 ] , node . Arguments [ 2 ] ) . AcceptVisitor ( this ) ;
7475 return ;
7576 case SqlFunctionType . TimeConstruct:
76- TimeConstruct( node . Arguments [ 0 ] , node . Arguments [ 1 ] , node . Arguments [ 2 ] , node . Arguments [ 3 ] ) . AcceptVisitor ( this ) ;
77+ TimeConstruct( node . Arguments ) . AcceptVisitor ( this ) ;
7778 return ;
7879 case SqlFunctionType . DateAddYears:
7980 DateTimeAddYMInterval( node . Arguments [ 0 ] , node . Arguments [ 1 ] , YearIntervalPart ) . AcceptVisitor( this ) ;
@@ -375,6 +376,31 @@ private static SqlExpression DateConstruct(SqlExpression years, SqlExpression mo
375376 SqlDml . FunctionCall ( ToCharFunctionName , ( ( years * 100 ) + months ) * 100 + days ) ,
376377 AnsiString ( "YYYYMMDD" ) ) ;
377378
379+ private static SqlExpression TimeConstruct ( IReadOnlyList < SqlExpression > arguments )
380+ {
381+ if ( arguments . Count == 4 ) {
382+ var hours = arguments [ 0 ] ;
383+ var minutes = arguments [ 1 ] ;
384+ var seconds = arguments [ 2 ] ;
385+ var milliseconds = arguments [ 3 ] ;
386+
387+ return SqlDml . FunctionCall ( NumToDSIntervalFunctionName ,
388+ seconds + ( minutes * 60 ) + ( hours * 3600 ) + ( milliseconds / 1000 ) ,
389+ AnsiString ( SecondIntervalPart ) ) ;
390+ }
391+ else if ( arguments . Count == 1 ) {
392+ var ticks = arguments [ 0 ] ;
393+ var zeroTime = SqlDml . Literal ( new TimeOnly ( 0 , 0 , 0 , 0 ) ) ;
394+ if ( ! SqlHelper . IsTimeSpanTicks ( ticks , out var sourceInterval ) ) {
395+ sourceInterval = SqlDml . FunctionCall ( NumToDSIntervalFunctionName , ticks / 10000000 , AnsiString ( SecondIntervalPart ) ) ;
396+ }
397+ return SqlDml . Cast ( TimeAddInterval ( zeroTime , sourceInterval ) , SqlType . Time ) ;
398+ }
399+ else {
400+ throw new InvalidOperationException ( "Unsupported count of parameters" ) ;
401+ }
402+ }
403+
378404 private static SqlExpression TimeAddHourOrMinute ( SqlExpression time , SqlExpression hourOrMinute , bool isHour )
379405 {
380406 var intervalLiteral = isHour ? "INTERVAL '1' HOUR" : "INTERVAL '1' MINUTE" ;
@@ -392,12 +418,6 @@ private static SqlExpression TimeAddInterval(SqlExpression time, SqlExpression i
392418 return castToCorrectInterval ;
393419 }
394420
395- private static SqlExpression TimeConstruct (
396- SqlExpression hours , SqlExpression minutes , SqlExpression seconds , SqlExpression milliseconds ) =>
397- SqlDml . FunctionCall ( NumToDSIntervalFunctionName ,
398- seconds + ( minutes * 60 ) + ( hours * 3600 ) + ( milliseconds / 1000 ) ,
399- AnsiString ( SecondIntervalPart ) ) ;
400-
401421 private static SqlExpression DateToString ( SqlExpression date ) =>
402422 SqlDml . FunctionCall ( ToCharFunctionName , date , "YYYY-MM-DD" ) ;
403423
0 commit comments