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.

81 lines
1.9 KiB

2 years ago
  1. using System.Collections.Generic;
  2. using System.Text;
  3. using System.Text.RegularExpressions;
  4. namespace SqlSugar
  5. {
  6. public class SqlQueryBuilder : IDMLBuilder
  7. {
  8. #region Fields
  9. private string _Fields;
  10. private StringBuilder _Sql;
  11. private List<SugarParameter> _Parameters;
  12. #endregion
  13. #region Properties
  14. public SqlSugarClient Context { get; set; }
  15. public string Fields
  16. {
  17. get
  18. {
  19. if (this._Fields.IsNullOrEmpty())
  20. {
  21. this._Fields = Regex.Match(this.sql.ObjToString().Replace("\n", string.Empty).Replace("\r", string.Empty).Trim(), @"select(.*?)from", RegexOptions.IgnoreCase).Groups[1].Value;
  22. if (this._Fields.IsNullOrEmpty())
  23. {
  24. this._Fields = "*";
  25. }
  26. }
  27. return this._Fields;
  28. }
  29. set
  30. {
  31. _Fields = value;
  32. }
  33. }
  34. public StringBuilder sql
  35. {
  36. get
  37. {
  38. _Sql = UtilMethods.IsNullReturnNew(_Sql);
  39. return _Sql;
  40. }
  41. set
  42. {
  43. _Sql = value;
  44. }
  45. }
  46. public string SqlTemplate
  47. {
  48. get
  49. {
  50. return null;
  51. }
  52. }
  53. public List<SugarParameter> Parameters
  54. {
  55. get
  56. {
  57. _Parameters = UtilMethods.IsNullReturnNew(_Parameters);
  58. return _Parameters;
  59. }
  60. set
  61. {
  62. _Parameters = value;
  63. }
  64. }
  65. #endregion
  66. #region Methods
  67. public string ToSqlString()
  68. {
  69. return sql.ToString();
  70. }
  71. public void Clear()
  72. {
  73. this.sql = null;
  74. }
  75. #endregion
  76. }
  77. }