@@ -92,6 +92,14 @@ INNER JOIN ( {Select}
9292SET {SetValue}
9393" ;
9494
95+ internal const string CommandTextTemplate_Hana = @"
96+ UPDATE {TableName}
97+ SET {SetValue}
98+ WHERE EXISTS ( SELECT 1 FROM ({Select}) B
99+ WHERE {PrimaryKeys}
100+ )
101+ " ;
102+
95103#if TODO
96104 /// <summary>The command text template with WHILE loop.</summary>
97105 internal const string CommandTextWhileTemplate = @"
@@ -399,6 +407,7 @@ internal DbCommand CreateCommand<T>(ObjectQuery query, SchemaEntityType<T> entit
399407 var isOracle = command . GetType ( ) . Namespace . Contains ( "Oracle" ) ;
400408 var isPostgreSQL = command . GetType ( ) . Name == "NpgsqlCommand" ;
401409 var isSQLite = command . GetType ( ) . Namespace . Contains ( "SQLite" ) ;
410+ var isHana = command . GetType ( ) . Namespace . Contains ( "Hana" ) ;
402411
403412 // Oracle BindByName
404413 if ( isOracle )
@@ -442,6 +451,12 @@ internal DbCommand CreateCommand<T>(ObjectQuery query, SchemaEntityType<T> entit
442451 {
443452 tableName = string . Concat ( "\" " , store . Table , "\" " ) ;
444453 }
454+ else if ( isHana )
455+ {
456+ tableName = string . IsNullOrEmpty ( store . Schema ) ?
457+ string . Concat ( "\" " , store . Table , "\" " ) :
458+ string . Concat ( "\" " , store . Schema , "\" .\" " , store . Table , "\" " ) ;
459+ }
445460 else
446461 {
447462 tableName = string . IsNullOrEmpty ( store . Schema ) ?
@@ -478,6 +493,7 @@ internal DbCommand CreateCommand<T>(ObjectQuery query, SchemaEntityType<T> entit
478493 isMySql ? CommandTextTemplate_MySQL :
479494 isSqlCe ? CommandTextTemplateSqlCe :
480495 isSQLite ? CommandTextTemplate_SQLite :
496+ isHana ? CommandTextTemplate_Hana :
481497 CommandTextTemplate ;
482498
483499 // GET inner query
@@ -496,38 +512,38 @@ internal DbCommand CreateCommand<T>(ObjectQuery query, SchemaEntityType<T> entit
496512
497513 if ( isSqlCe )
498514 {
499- primaryKeys = string . Join ( Environment . NewLine + "AND " , columnKeys . Select ( x => string . Concat ( tableName + "." , EscapeName ( x , isMySql , isOracle , isPostgreSQL ) , " = B." , EscapeName ( x , isMySql , isOracle , isPostgreSQL ) , "" ) ) ) ;
515+ primaryKeys = string . Join ( Environment . NewLine + "AND " , columnKeys . Select ( x => string . Concat ( tableName + "." , EscapeName ( x , isMySql , isOracle , isPostgreSQL , isHana ) , " = B." , EscapeName ( x , isMySql , isOracle , isPostgreSQL , isHana ) , "" ) ) ) ;
500516
501517 setValues = string . Join ( "," + Environment . NewLine , values . Select ( ( x , i ) => x . Item2 is ConstantExpression ?
502- string . Concat ( EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL ) , " = " , ( ( ConstantExpression ) x . Item2 ) . Value . ToString ( ) . Replace ( "B.[" , "[" ) ) :
503- string . Concat ( EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL ) , " = @zzz_BatchUpdate_" , i ) ) ) ;
518+ string . Concat ( EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL , isHana ) , " = " , ( ( ConstantExpression ) x . Item2 ) . Value . ToString ( ) . Replace ( "B.[" , "[" ) ) :
519+ string . Concat ( EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL , isHana ) , " = @zzz_BatchUpdate_" , i ) ) ) ;
504520 }
505- else if ( isOracle || isPostgreSQL )
521+ else if ( isOracle || isPostgreSQL || isHana )
506522 {
507- primaryKeys = string . Join ( Environment . NewLine + "AND " , columnKeys . Select ( x => string . Concat ( tableName + "." , EscapeName ( x , isMySql , isOracle , isPostgreSQL ) , " = B." , EscapeName ( x , isMySql , isOracle , isPostgreSQL ) , "" ) ) ) ;
523+ primaryKeys = string . Join ( Environment . NewLine + "AND " , columnKeys . Select ( x => string . Concat ( tableName + "." , EscapeName ( x , isMySql , isOracle , isPostgreSQL , isHana ) , " = B." , EscapeName ( x , isMySql , isOracle , isPostgreSQL , isHana ) , "" ) ) ) ;
508524
509525 // GET updateSetValues
510526 setValues = string . Join ( "," + Environment . NewLine , values . Select ( ( x , i ) => x . Item2 is ConstantExpression ?
511- string . Concat ( EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL ) , " = " , ( ( ConstantExpression ) x . Item2 ) . Value ) :
512- string . Concat ( EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL ) , " = :zzz_BatchUpdate_" , i ) ) ) ;
527+ string . Concat ( EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL , isHana ) , " = " , ( ( ConstantExpression ) x . Item2 ) . Value ) :
528+ string . Concat ( EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL , isHana ) , " = :zzz_BatchUpdate_" , i ) ) ) ;
513529 }
514530 else if ( isSQLite )
515531 {
516- primaryKeys = string . Join ( Environment . NewLine + "AND " , columnKeys . Select ( x => string . Concat ( tableName + "." , EscapeName ( x , isMySql , isOracle , isPostgreSQL ) , " = B." , EscapeName ( x , isMySql , isOracle , isPostgreSQL ) , "" ) ) ) ;
532+ primaryKeys = string . Join ( Environment . NewLine + "AND " , columnKeys . Select ( x => string . Concat ( tableName + "." , EscapeName ( x , isMySql , isOracle , isPostgreSQL , isHana ) , " = B." , EscapeName ( x , isMySql , isOracle , isPostgreSQL , isHana ) , "" ) ) ) ;
517533
518534 // GET updateSetValues
519535 setValues = string . Join ( "," + Environment . NewLine , values . Select ( ( x , i ) => x . Item2 is ConstantExpression ?
520- string . Concat ( EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL ) , " = " , ( ( ConstantExpression ) x . Item2 ) . Value ) :
521- string . Concat ( EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL ) , " = @zzz_BatchUpdate_" , i ) ) ) ;
536+ string . Concat ( EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL , isHana ) , " = " , ( ( ConstantExpression ) x . Item2 ) . Value ) :
537+ string . Concat ( EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL , isHana ) , " = @zzz_BatchUpdate_" , i ) ) ) ;
522538 }
523539 else
524540 {
525- primaryKeys = string . Join ( Environment . NewLine + "AND " , columnKeys . Select ( x => string . Concat ( "A." , EscapeName ( x , isMySql , isOracle , isPostgreSQL ) , " = B." , EscapeName ( x , isMySql , isOracle , isPostgreSQL ) , "" ) ) ) ;
541+ primaryKeys = string . Join ( Environment . NewLine + "AND " , columnKeys . Select ( x => string . Concat ( "A." , EscapeName ( x , isMySql , isOracle , isPostgreSQL , isHana ) , " = B." , EscapeName ( x , isMySql , isOracle , isPostgreSQL , isHana ) , "" ) ) ) ;
526542
527543 // GET updateSetValues
528544 setValues = string . Join ( "," + Environment . NewLine , values . Select ( ( x , i ) => x . Item2 is ConstantExpression ?
529- string . Concat ( "A." , EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL ) , " = " , ( ( ConstantExpression ) x . Item2 ) . Value ) :
530- string . Concat ( "A." , EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL ) , " = @zzz_BatchUpdate_" , i ) ) ) ;
545+ string . Concat ( "A." , EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL , isHana ) , " = " , ( ( ConstantExpression ) x . Item2 ) . Value ) :
546+ string . Concat ( "A." , EscapeName ( x . Item1 , isMySql , isOracle , isPostgreSQL , isHana ) , " = @zzz_BatchUpdate_" , i ) ) ) ;
531547 }
532548
533549 // REPLACE template
@@ -569,7 +585,7 @@ internal DbCommand CreateCommand<T>(ObjectQuery query, SchemaEntityType<T> entit
569585 continue ;
570586 }
571587
572- var parameterPrefix = isOracle ? ": " : "@";
588+ var parameterPrefix = isOracle ? ": " : isHana ? " " : "@";
573589
574590 var parameter = command.CreateParameter();
575591 parameter.ParameterName = parameterPrefix + " zzz_BatchUpdate_" + i;
@@ -1222,10 +1238,10 @@ public List<Tuple<string, object>> GetInnerValues<T>(IQueryable<T> query, Expres
12221238 return destinationValues;
12231239 }
12241240
1225- public string EscapeName( string name , bool isMySql , bool isOracle , bool isPostgreSQL )
1241+ public string EscapeName( string name , bool isMySql , bool isOracle , bool isPostgreSQL , bool isHana )
12261242 {
12271243 return isMySql ? string . Concat ( "`" , name , "`" ) :
1228- isOracle || isPostgreSQL ? string . Concat ( "\" " , name , "\" " ) :
1244+ isOracle || isPostgreSQL || isHana ? string . Concat ( "\" " , name , "\" " ) :
12291245 string . Concat ( "[" , name , "]" ) ;
12301246 }
12311247
0 commit comments