-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStoredProcedureParameterDefinitionList.cs
69 lines (66 loc) · 2.42 KB
/
StoredProcedureParameterDefinitionList.cs
1
2
3
4
5
6
7
8
9
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
64
65
66
67
68
69
//------------------------------------------------------------------------------
// <copyright file="CSSqlClassFile.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace SqlCLRParallel
{
internal class StoredProcedureParameterDefinitionList : List<StoredProcedureParameterDefinition>
{
public new void Add(StoredProcedureParameterDefinition item)
{
foreach (StoredProcedureParameterDefinition definition in this)
{
if (definition.ParameterName == item.ParameterName) throw new Exception("can not have parameter with same name as "+item.ParameterName);
}
base.Add(item);
}
private List<int> index = null;
public List<SqlParameter> GetNext()
{
if (index == null)
{
index = new List<int>();
for (int idx = 0; idx < this.Count; idx++) index.Add(0);
}
else
{
int increment = 0;
bool finished = false;
while (!finished)
{
index[increment]++;
if (index[increment] < this[increment].Values.Count)
{
finished = true;
}
else
{
index[increment] = 0;
increment++;
if (increment >= index.Count) return null;
}
}
}
return GetByIndex();
}
private List<SqlParameter> GetByIndex()
{
List<SqlParameter> sqlparams = new List<SqlParameter>();
for (int idx =0;idx<Count;idx++)
{
StoredProcedureParameterDefinition def = this[idx];
SqlParameter sqlparam = new SqlParameter(def.ParameterName, def.SqlDbType);
sqlparam.SqlValue = def.Values[index[idx]];//convert?
sqlparam.Direction = def.IsOutput ? ParameterDirection.InputOutput : ParameterDirection.Input;
sqlparams.Add(sqlparam);
}
return sqlparams;
}
}
}