SqlFunc.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Reflection;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace SqlSugar
  9. {
  10. public partial class SqlFunc
  11. {
  12. public static bool FullTextContains(string [] columnNames, string keyword)
  13. {
  14. throw new NotSupportedException("Can only be used in expressions");
  15. }
  16. public static bool FullTextContains(string columnName,string keyword)
  17. {
  18. throw new NotSupportedException("Can only be used in expressions");
  19. }
  20. public static int Floor(object value)
  21. {
  22. throw new NotSupportedException("Can only be used in expressions");
  23. }
  24. public static int Ceil(object value)
  25. {
  26. throw new NotSupportedException("Can only be used in expressions");
  27. }
  28. public static int WeekOfYear(DateTime fieldName)
  29. {
  30. throw new NotSupportedException("Can only be used in expressions");
  31. }
  32. public static string Left(string value,int number)
  33. {
  34. throw new NotSupportedException("Can only be used in expressions");
  35. }
  36. public static string Right(string value,int number)
  37. {
  38. throw new NotSupportedException("Can only be used in expressions");
  39. }
  40. public static string PadLeft(string value,int number, char padChar)
  41. {
  42. throw new NotSupportedException("Can only be used in expressions");
  43. }
  44. public static bool Like(string fieldName, string likeValue)
  45. {
  46. throw new NotSupportedException("Can only be used in expressions");
  47. }
  48. public static int Modulo(decimal numA, decimal numB)
  49. {
  50. throw new NotSupportedException("Can only be used in expressions");
  51. }
  52. public static int CompareTo(decimal numA, decimal numB)
  53. {
  54. throw new NotSupportedException("Can only be used in expressions");
  55. }
  56. public static int CompareTo(int numA, int numB)
  57. {
  58. throw new NotSupportedException("Can only be used in expressions");
  59. }
  60. public static int CompareTo(string strA, string strB)
  61. {
  62. throw new NotSupportedException("Can only be used in expressions");
  63. }
  64. public static int RowNumber(object orderByField, object partitionBy)
  65. {
  66. throw new NotSupportedException("Can only be used in expressions");
  67. }
  68. public static int RowNumber(object orderByField)
  69. {
  70. throw new NotSupportedException("Can only be used in expressions");
  71. }
  72. public static int RowCount(object countFiledName,object orderByField, object partitionBy)
  73. {
  74. throw new NotSupportedException("Can only be used in expressions");
  75. }
  76. public static int RowCount()
  77. {
  78. throw new NotSupportedException("Can only be used in expressions");
  79. }
  80. public static TRestult RowSum<TRestult>(TRestult filedName)
  81. {
  82. throw new NotSupportedException("Can only be used in expressions");
  83. }
  84. public static TRestult RowSum<TRestult>(TRestult filedName, object orderByField, object partitionBy)
  85. {
  86. throw new NotSupportedException("Can only be used in expressions");
  87. }
  88. public static TRestult RowMax<TRestult>(TRestult filedName)
  89. {
  90. throw new NotSupportedException("Can only be used in expressions");
  91. }
  92. public static TRestult RowMax<TRestult>(TRestult filedNameobject,object orderByField, object partitionBy)
  93. {
  94. throw new NotSupportedException("Can only be used in expressions");
  95. }
  96. public static TRestult RowMin<TRestult>(TRestult filedName)
  97. {
  98. throw new NotSupportedException("Can only be used in expressions");
  99. }
  100. public static TRestult RowMin<TRestult>(TRestult filedName, object orderByField, object partitionBy)
  101. {
  102. throw new NotSupportedException("Can only be used in expressions");
  103. }
  104. public static TRestult RowAvg<TRestult>(TRestult filedName)
  105. {
  106. throw new NotSupportedException("Can only be used in expressions");
  107. }
  108. public static TRestult RowAvg<TRestult>(TRestult filedName, object orderByField, object partitionBy)
  109. {
  110. throw new NotSupportedException("Can only be used in expressions");
  111. }
  112. public static string JsonField(object json,string fieldName)
  113. {
  114. throw new NotSupportedException("Can only be used in expressions");
  115. }
  116. public static string JsonIndex(object json, int jsonIndex)
  117. {
  118. throw new NotSupportedException("Can only be used in expressions");
  119. }
  120. public static string JsonField(object json, string fieldName,string includeFieldName)
  121. {
  122. throw new NotSupportedException("Can only be used in expressions");
  123. }
  124. public static string JsonField(object json, string fieldName, string includeFieldName, string ThenIncludeFieldName)
  125. {
  126. throw new NotSupportedException("Can only be used in expressions");
  127. }
  128. public static string JsonField(object json, string fieldName, string includeFieldName, string ThenIncludeFieldName, string ThenIncludeFieldName2)
  129. {
  130. throw new NotSupportedException("Can only be used in expressions");
  131. }
  132. public static string JsonField(object json, string fieldName, string includeFieldName, string ThenIncludeFieldName, string ThenIncludeFieldName2, string ThenIncludeFieldName3)
  133. {
  134. throw new NotSupportedException("Can only be used in expressions");
  135. }
  136. public static bool JsonContainsFieldName(object json, string fieldName)
  137. {
  138. throw new NotSupportedException("Can only be used in expressions");
  139. }
  140. public static int JsonArrayLength(object json)
  141. {
  142. throw new NotSupportedException("Can only be used in expressions");
  143. }
  144. public static string JsonParse(object json)
  145. {
  146. throw new NotSupportedException("Can only be used in expressions");
  147. }
  148. public static bool JsonLike(object json,string likeStr)
  149. {
  150. throw new NotSupportedException("Can only be used in expressions");
  151. }
  152. public static T Desc<T>(T value)
  153. {
  154. throw new NotSupportedException("Can only be used in expressions");
  155. }
  156. public static T Asc<T>(T value)
  157. {
  158. throw new NotSupportedException("Can only be used in expressions");
  159. }
  160. public static int DateDiff(DateType dateType,DateTime littleTime, DateTime bigTime)
  161. {
  162. throw new NotSupportedException("Can only be used in expressions");
  163. }
  164. public static bool GreaterThan(object thisValue,object gtValue)
  165. {
  166. throw new NotSupportedException("Can only be used in expressions");
  167. }
  168. public static string Stuff(string sourceString, int start, int length, string AddString)
  169. {
  170. throw new NotSupportedException("Can only be used in expressions");
  171. }
  172. public static bool GreaterThanOrEqual(object thisValue, object gtValue)
  173. {
  174. throw new NotSupportedException("Can only be used in expressions");
  175. }
  176. public static bool LessThan(object thisValue, object ltValue)
  177. {
  178. throw new NotSupportedException("Can only be used in expressions");
  179. }
  180. public static bool LessThanOrEqual(object thisValue, object ltValue)
  181. {
  182. throw new NotSupportedException("Can only be used in expressions");
  183. }
  184. public static bool HasNumber(object thisValue)
  185. {
  186. return thisValue.ObjToInt() > 0;
  187. }
  188. public static bool HasValue(object thisValue)
  189. {
  190. return thisValue.HasValue();
  191. }
  192. public static bool IsNullOrEmpty(object thisValue)
  193. {
  194. return thisValue.IsNullOrEmpty();
  195. }
  196. public static string ToLower(object thisValue)
  197. {
  198. return thisValue == null ? null : thisValue.ToString().ToLower();
  199. }
  200. public static string ToUpper(object thisValue)
  201. {
  202. return thisValue == null ? null : thisValue.ToString().ToUpper();
  203. }
  204. public static string Trim(object thisValue)
  205. {
  206. return thisValue == null ? null : thisValue.ToString().Trim();
  207. }
  208. public static string TrimEnd(object thisValue,string trimChar)
  209. {
  210. throw new NotSupportedException("Can only be used in expressions");
  211. }
  212. public static string TrimStart(object thisValue, string trimChar)
  213. {
  214. throw new NotSupportedException("Can only be used in expressions");
  215. }
  216. public static bool Contains(string thisValue, string parameterValue)
  217. {
  218. return thisValue.Contains(parameterValue);
  219. }
  220. public static bool ContainsArray<T>(T[] thisValue, object InField)
  221. {
  222. return thisValue.Contains((T)InField);
  223. }
  224. public static bool ContainsArray<T>(List<T> thisValue, object InField)
  225. {
  226. return thisValue.Contains((T)InField);
  227. }
  228. public static bool ContainsArrayUseSqlParameters<T>(List<T> thisValue, object InField)
  229. {
  230. return thisValue.Contains((T)InField);
  231. }
  232. public static bool ContainsArrayUseSqlParameters<T>(T[] thisValue, object InField)
  233. {
  234. return thisValue.Contains((T)InField);
  235. }
  236. public static bool StartsWith(string thisValue, string parameterValue)
  237. {
  238. return thisValue.StartsWith(parameterValue);
  239. }
  240. public static bool EndsWith(string thisValue, string parameterValue)
  241. {
  242. return thisValue.EndsWith(parameterValue);
  243. }
  244. public new static bool Equals(object thisValue, object parameterValue)
  245. {
  246. return thisValue.Equals(parameterValue);
  247. }
  248. public static bool EqualsNull(object thisValue, object parameterValue)
  249. {
  250. return thisValue.Equals(parameterValue);
  251. }
  252. public static bool Exists(string subQueryableName_Or_OneToOnePropertyName)
  253. {
  254. throw new NotSupportedException("Can only be used in expressions");
  255. }
  256. public static bool Exists<valueType>(valueType subQueryableName_Or_OneToOnePropertyName) where valueType : struct
  257. {
  258. throw new NotSupportedException("Can only be used in expressions");
  259. }
  260. public static bool Exists(string subQueryableName_Or_OneToOnePropertyName, List<IConditionalModel> conditionalModels)
  261. {
  262. throw new NotSupportedException("Can only be used in expressions");
  263. }
  264. public static bool Exists<valueType>(valueType subQueryableName_Or_OneToOnePropertyName, List<IConditionalModel> conditionalModels) where valueType : struct
  265. {
  266. throw new NotSupportedException("Can only be used in expressions");
  267. }
  268. public static bool DateIsSame(DateTime date1, DateTime date2)
  269. {
  270. return date1.ToString("yyyy-MM-dd") == date2.ToString("yyyy-MM-dd");
  271. }
  272. public static bool DateIsSame(DateTime? date1, DateTime? date2)
  273. {
  274. return ((DateTime)date1).ToString("yyyy-MM-dd") == ((DateTime)date2).ToString("yyyy-MM-dd");
  275. }
  276. public static bool DateIsSame(DateTime date1, DateTime date2, DateType dataType) { throw new NotSupportedException("Can only be used in expressions"); }
  277. public static DateTime DateAdd(DateTime date, int addValue, DateType dataType) { throw new NotSupportedException("Can only be used in expressions"); }
  278. public static DateTimeOffset DateAdd(DateTimeOffset date, int addValue, DateType dataType) { throw new NotSupportedException("Can only be used in expressions"); }
  279. public static DateTime DateAdd(DateTime date, int addValue) { throw new NotSupportedException("Can only be used in expressions"); }
  280. public static DateTimeOffset DateAdd(DateTimeOffset date, int addValue) { throw new NotSupportedException("Can only be used in expressions"); }
  281. public static int DateValue(DateTime date, DateType dataType) { throw new NotSupportedException("Can only be used in expressions"); }
  282. public static int DateValue(DateTimeOffset date, DateTimeOffset dataType) { throw new NotSupportedException("Can only be used in expressions"); }
  283. public static bool Between(object value, object start, object end) { throw new NotSupportedException("Can only be used in expressions"); }
  284. public static TResult IIF<TResult>(bool isTrue, TResult thenValue, TResult elseValue) { return isTrue ? thenValue : elseValue; }
  285. public static TResult IsNull<TResult>(TResult thisValue, TResult ifNullValue) { throw new NotSupportedException("Can only be used in expressions"); }
  286. public static string MergeString(string value1,string value2) { throw new NotSupportedException("Can only be used in expressions"); }
  287. public static string MergeString(string value1, string value2,string value3) { throw new NotSupportedException("Can only be used in expressions"); }
  288. public static string MergeString(string value1, string value2,string value3,string value4) { throw new NotSupportedException("Can only be used in expressions"); }
  289. public static string MergeString(string value1, string value2, string value3, string value4,string value5) { throw new NotSupportedException("Can only be used in expressions"); }
  290. public static string MergeString(string value1, string value2, string value3, string value4, string value5,string value6) { throw new NotSupportedException("Can only be used in expressions"); }
  291. public static string MergeString(string value1, string value2, string value3, string value4, string value5, string value6,string value7) { throw new NotSupportedException("Can only be used in expressions"); }
  292. public static int ToInt32(object value) { return value.ObjToInt(); }
  293. public static float ToSingle(object value) { return Convert.ToSingle(value); }
  294. public static long ToInt64(object value) { return Convert.ToInt64(value); }
  295. /// <summary>
  296. /// yyyy-MM-dd HH:mm:ss.fff
  297. /// </summary>
  298. /// <param name="value"></param>
  299. /// <returns></returns>
  300. public static DateTime ToDate(object value) { return value.ObjToDate(); }
  301. public static DateTime ToDateShort(object value) { return value.ObjToDate(); }
  302. /// <summary>
  303. ///HH:mm:ss
  304. /// </summary>
  305. /// <param name="value"></param>
  306. /// <returns></returns>
  307. public static TimeSpan ToTime(object value) { throw new NotSupportedException("Can only be used in expressions"); }
  308. public static string ToString(object value) { return value.ObjToString(); }
  309. public static string ToVarchar(object value) { return value.ObjToString(); }
  310. public static decimal ToDecimal(object value) { return value.ObjToDecimal(); }
  311. public static Guid ToGuid(object value) { return Guid.Parse(value.ObjToString()); }
  312. public static Guid NewUid() { throw new NotSupportedException("Can only be used in expressions"); }
  313. public static double ToDouble(object value) { return value.ObjToMoney(); }
  314. public static bool ToBool(object value) { return value.ObjToBool(); }
  315. public static string Substring(object value, int index, int length) { return value.ObjToString().Substring(index, length); }
  316. public static string Replace(object value, string oldChar, string newChar) { return value.ObjToString().Replace(oldChar, newChar); }
  317. public static int Length(object value) { return value.ObjToString().Length; }
  318. public static TResult AggregateSum<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
  319. public static TResult AggregateSumNoNull<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
  320. public static string Collate(string thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
  321. public static TResult AggregateAvg<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
  322. public static TResult AggregateAvgNoNull<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
  323. public static TResult AggregateMin<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
  324. public static TResult AggregateMax<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
  325. public static int AggregateCount<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
  326. public static int AggregateDistinctCount<TResult>(TResult thisValue) { throw new NotSupportedException("Can only be used in expressions"); }
  327. public static TResult MappingColumn<TResult>(TResult type,string newColumnName) { throw new NotSupportedException("Can only be used in expressions"); }
  328. public static TResult MappingColumn<TResult>(string newColumnName) { throw new NotSupportedException("Can only be used in expressions"); }
  329. /// <summary>
  330. ///Example: new NewT(){name=SqlFunc.GetSelfAndAutoFill(it)} Generated SQL it.*
  331. /// </summary>
  332. /// <typeparam name="TResult"></typeparam>
  333. /// <param name="value"></param>
  334. /// <returns></returns>
  335. public static TResult GetSelfAndAutoFill<TResult>(TResult value) { throw new NotSupportedException("Can only be used in expressions"); }
  336. public static DateTime GetDate() { throw new NotSupportedException("Can only be used in expressions"); }
  337. public static string GetRandom() { throw new NotSupportedException("Can only be used in expressions"); }
  338. public static T Abs<T>( T value) { throw new NotSupportedException("Can only be used in expressions"); }
  339. public static T Round<T>(T value,int precision) { throw new NotSupportedException("Can only be used in expressions"); }
  340. /// <summary>
  341. /// Subquery
  342. /// </summary>
  343. /// <typeparam name="T"></typeparam>
  344. /// <returns></returns>
  345. public static Subqueryable<T> Subqueryable<T>() where T:class,new(){ throw new NotSupportedException("Can only be used in expressions");}
  346. public static CaseThen IF(bool condition) { throw new NotSupportedException("Can only be used in expressions"); }
  347. [Obsolete("多库下参数顺序不一至,为了保证多库下更好体验请使用 SqlFunc.CharIndexNew")]
  348. public static int CharIndex(string findChar,string searchValue) { throw new NotSupportedException("Can only be used in expressions"); }
  349. public static int CharIndexNew(string stringValue, string charValue) { throw new NotSupportedException("Can only be used in expressions"); }
  350. public static int BitwiseAnd(int left, int right) { throw new NotSupportedException("Can only be used in expressions"); }
  351. public static int BitwiseInclusiveOR(int left, int right) { throw new NotSupportedException("Can only be used in expressions"); }
  352. public static int BitwiseAnd(long left, long right) { throw new NotSupportedException("Can only be used in expressions"); }
  353. public static int BitwiseInclusiveOR(long left, long right) { throw new NotSupportedException("Can only be used in expressions"); }
  354. public static DateTime Oracle_ToDate(string date,string format) { throw new NotSupportedException("Can only be used in expressions"); }
  355. public static string Oracle_ToChar(DateTime date, string format) { throw new NotSupportedException("Can only be used in expressions"); }
  356. public static string Oracle_ToChar(object objValue, string format) { throw new NotSupportedException("Can only be used in expressions"); }
  357. public static int SqlServer_DateDiff(string dateType,DateTime date1,DateTime date2) { throw new NotSupportedException("Can only be used in expressions"); }
  358. public static bool JsonListObjectAny(object jsonListObject, string fieldName, object value)
  359. {
  360. throw new NotSupportedException("Can only be used in expressions");
  361. }
  362. public static bool JsonArrayAny(object jsonArray,object arrayValue)
  363. {
  364. throw new NotSupportedException("Can only be used in expressions");
  365. }
  366. public static bool SplitIn(string CommaSegmentationString, string inValue)
  367. {
  368. throw new NotSupportedException("Can only be used in expressions");
  369. }
  370. public static bool SplitIn(string CommaSegmentationString, string inValue,char splitChar)
  371. {
  372. throw new NotSupportedException("Can only be used in expressions");
  373. }
  374. public static bool ListAny<T>(List<T> listConstant, Expression<Func<T,bool>> expression)
  375. {
  376. throw new NotSupportedException("Can only be used in expressions");
  377. }
  378. public static bool ListAll<T>(List<T> listConstant, Expression<Func<T, bool>> expression)
  379. {
  380. throw new NotSupportedException("Can only be used in expressions");
  381. }
  382. public static string OnlyInSelectConvertToString(string stringValue, MethodInfo methodInfo)
  383. {
  384. throw new NotSupportedException("Can only be used in expressions");
  385. }
  386. }
  387. }