You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
6.8 KiB

2 years ago
  1. using System;
  2. namespace SqlSugar
  3. {
  4. public partial class OracleExpressionContext : ExpressionContext, ILambdaExpressions
  5. {
  6. public SqlSugarClient Context { get; set; }
  7. public OracleExpressionContext()
  8. {
  9. base.DbMehtods = new OracleMethod();
  10. }
  11. public override string SqlParameterKeyWord
  12. {
  13. get
  14. {
  15. return ":";
  16. }
  17. }
  18. public override string SqlTranslationLeft { get { return "\""; } }
  19. public override string SqlTranslationRight { get { return "\""; } }
  20. public override string GetTranslationTableName(string entityName, bool isMapping = true)
  21. {
  22. return base.GetTranslationTableName(entityName, isMapping).ToUpper();
  23. }
  24. public override string GetTranslationColumnName(string columnName)
  25. {
  26. return base.GetTranslationColumnName(columnName).ToUpper();
  27. }
  28. public override string GetDbColumnName(string entityName, string propertyName)
  29. {
  30. return base.GetDbColumnName(entityName,propertyName).ToUpper();
  31. }
  32. }
  33. public partial class OracleMethod : DefaultDbMethod, IDbMethods
  34. {
  35. public override string ToTime(MethodCallExpressionModel model)
  36. {
  37. var parameter = model.Args[0];
  38. return string.Format(" to_timestamp({0},'0000-01-01 hh24:mi:ss') ", parameter.MemberName);
  39. }
  40. public override string DateValue(MethodCallExpressionModel model)
  41. {
  42. var parameter = model.Args[0];
  43. var parameter2 = model.Args[1];
  44. var type = (DateType)Enum.Parse(typeof(DateType), parameter2.MemberValue.ObjToString(), false);
  45. switch (type)
  46. {
  47. case DateType.Year:
  48. return string.Format("(CAST(TO_CHAR({0},'yyyy') AS NUMBER)",parameter.MemberName);
  49. case DateType.Month:
  50. return string.Format("(CAST(TO_CHAR({0},'mm') AS NUMBER)", parameter.MemberName);
  51. case DateType.Hour:
  52. return string.Format("(CAST(TO_CHAR({0},'hh24') AS NUMBER)", parameter.MemberName);
  53. case DateType.Second:
  54. return string.Format("(CAST(TO_CHAR({0},'ss') AS NUMBER)", parameter.MemberName);
  55. case DateType.Minute:
  56. return string.Format("(CAST(TO_CHAR({0},'mi') AS NUMBER)", parameter.MemberName);
  57. case DateType.Millisecond:
  58. return string.Format("(CAST(TO_CHAR({0},'ff3') AS NUMBER)", parameter.MemberName);
  59. case DateType.Day:
  60. default:
  61. return string.Format("(CAST(TO_CHAR({0},'dd') AS NUMBER)", parameter.MemberName);
  62. }
  63. }
  64. public override string DateAddByType(MethodCallExpressionModel model)
  65. {
  66. var parameter = model.Args[0];
  67. var parameter2 = model.Args[1];
  68. var parameter3 = model.Args[2];
  69. var type = (DateType)Enum.Parse(typeof(DateType), parameter3.MemberValue.ObjToString(), false);
  70. double time = 1;
  71. switch (type)
  72. {
  73. case DateType.Year:
  74. time = 1 * 365;
  75. break;
  76. case DateType.Month:
  77. time = 1 *30;
  78. break;
  79. case DateType.Day:
  80. break;
  81. case DateType.Hour:
  82. time = 1 / 24.0;
  83. break;
  84. case DateType.Second:
  85. time = 1 / 24.0/60.0/60.0;
  86. break;
  87. case DateType.Minute:
  88. time = 1 / 24.0/60.0;
  89. break;
  90. case DateType.Millisecond:
  91. time = 1 / 24.0 / 60.0 / 60.0/1000;
  92. break;
  93. }
  94. return string.Format("({0}+({1}*{2})) ", parameter.MemberName, time,parameter2.MemberName);
  95. }
  96. public override string DateAddDay(MethodCallExpressionModel model)
  97. {
  98. var parameter = model.Args[0];
  99. var parameter2 = model.Args[1];
  100. return string.Format("({0}+(1*{1})) ", parameter.MemberName, parameter2.MemberName);
  101. }
  102. public override string ToString(MethodCallExpressionModel model)
  103. {
  104. var parameter = model.Args[0];
  105. return string.Format(" CAST({0} AS VARCHAR2(4000))", parameter.MemberName);
  106. }
  107. public override string ToDate(MethodCallExpressionModel model)
  108. {
  109. var parameter = model.Args[0];
  110. return string.Format(" to_date({0},'yyyy-mm-dd hh24:mi:ss')", parameter.MemberName);
  111. }
  112. public override string Contains(MethodCallExpressionModel model)
  113. {
  114. var parameter = model.Args[0];
  115. var parameter2 = model.Args[1];
  116. return string.Format(" ({0} like '%'||{1}||'%') ", parameter.MemberName, parameter2.MemberName);
  117. }
  118. public override string StartsWith(MethodCallExpressionModel model)
  119. {
  120. var parameter = model.Args[0];
  121. var parameter2 = model.Args[1];
  122. return string.Format(" ({0} like {1}||'%') ", parameter.MemberName, parameter2.MemberName);
  123. }
  124. public override string EndsWith(MethodCallExpressionModel model)
  125. {
  126. var parameter = model.Args[0];
  127. var parameter2 = model.Args[1];
  128. return string.Format(" ({0} like '%'||{1}) ", parameter.MemberName, parameter2.MemberName);
  129. }
  130. public override string Trim(MethodCallExpressionModel model)
  131. {
  132. var parameter = model.Args[0];
  133. return string.Format(" trim({0}) ", parameter.MemberName);
  134. }
  135. public override string DateIsSameDay(MethodCallExpressionModel model)
  136. {
  137. throw new NotSupportedException("Oracle NotSupportedException DateIsSameDay");
  138. }
  139. public override string DateIsSameByType(MethodCallExpressionModel model)
  140. {
  141. throw new NotSupportedException("Oracle NotSupportedException DateIsSameDay");
  142. }
  143. public override string Length(MethodCallExpressionModel model)
  144. {
  145. var parameter = model.Args[0];
  146. return string.Format(" LENGTH({0}) ", parameter.MemberName);
  147. }
  148. public override string IsNull(MethodCallExpressionModel model)
  149. {
  150. var parameter = model.Args[0];
  151. var parameter1 = model.Args[1];
  152. return string.Format("NVL({0},{1})", parameter.MemberName, parameter1.MemberName);
  153. }
  154. public override string MergeString(params string[] strings)
  155. {
  156. return string.Join("||", strings).Replace("+", "");
  157. }
  158. public override string GetDate()
  159. {
  160. return "sysdate";
  161. }
  162. }
  163. }