- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
public class IterateSQL
{
private int _start = 0;
private int _end = 0;
private int number = 0;
private string TOP_100_PERCENT = "100 percent ";
private string SELECT_FROM = " SELECT*FROM (";
private string SELECT_TOP_I = "SELECT TOP $I * FROM(";
private string SELECT_TOP_F = "SELECT TOP $F * FROM(";
private string JOINTURE = @" WHERE maTable.id NOT IN (SELECT maTable.id FROM(";
private string CLOSE = ") maTable)";
private string SELECT_COUNT = "SELECT COUNT(*) FROM ( XYZ ) maTable";
private string _sql;
private string _where;
private string _parameter = string.Empty;
private List<string> _tempParameterList = new List<string>();
private Dictionary<string, object> _finalParameterList = new Dictionary<string, object>();
public IterateSQL(string sql, string where, string parameter)
{
_sql = sql;
_where = where;
_parameter = parameter;
}
public string TransformAndReturnSQL(int start, int end)
{
_start = start;
_end = end;
if (_parameter == null)
_parameter = string.Empty;
string[] split = Utils.Splitter(_parameter);
number = split.Length;
StringBuilder sb = new StringBuilder(" XYZ ");
StringBuilder st = new StringBuilder();
for (int i = 0; i < number; i++)
{
if (split[i].ToString() != string.Empty)
sb.Insert(0, SELECT_FROM);
}
for (int i = 0; i < number; i++)
{
if (split[i].ToString() != string.Empty)
{
sb.Insert(sb.Length, _where);
sb.Replace("@param", split[i].ToString());
}
}
sb.Replace("XYZ", _sql);
st.Append(sb.ToString());
sb.Insert(0, SELECT_TOP_I);
sb.Append(JOINTURE);
sb.Append(SELECT_TOP_F);
sb.Append(st.ToString());
sb.Append(CLOSE);
sb.Replace("$I", _start.ToString());
sb.Replace("$F", _end.ToString());
return sb.ToString();
}
}