annotate Source/Data/DataProvider/OracleHelper.cs @ 9:1e85f66cf767 default tip

update bltoolkit
author nickolay
date Thu, 05 Apr 2018 20:53:26 +0300
parents f990fcb411a9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
1 using System;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
2 using System.Data;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
3 using System.Diagnostics;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
4 using System.Globalization;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
5 using System.Text.RegularExpressions;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
6
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
7 namespace BLToolkit.Data.DataProvider
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
8 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
9 public static class OracleHelper
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
10 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
11 #region Text
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
12
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
13 /// <summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
14 /// If value is null or empty, return NULL or the value converted for Oracle SQL query
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
15 /// </summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
16 /// <param name="value">Text</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
17 /// <returns>Text converted for oracle query</returns>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
18 public static string SqlConvertString(string value)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
19 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
20 if (!string.IsNullOrEmpty(value))
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
21 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
22 value = value.Replace("'", "''");
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
23 value = value.Replace("&", "' || '&' || '");
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
24
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
25 return "'" + value + "'";
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
26 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
27
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
28 return string.IsNullOrWhiteSpace(value) ? "NULL" : value;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
29 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
30
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
31 #endregion
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
32
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
33 #region Date & Time
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
34
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
35 /// <summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
36 /// Convert DateTime to TO_DATE('value','YYYYMMDD')
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
37 /// </summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
38 /// <param name="value">Date</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
39 /// <returns>Date converted for oracle query</returns>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
40 public static string SqlConvertDate(DateTime value)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
41 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
42 return string.Format("TO_DATE('{0}','YYYYMMDD')", value.ToString("yyyyMMdd"));
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
43 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
44
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
45 /// <summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
46 /// Convert DateTime to TO_DATE('value','YYYYMMDDHH24MISS')
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
47 /// </summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
48 /// <param name="value">DateTime</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
49 /// <returns>DateTime converted for oracle query</returns>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
50 public static string SqlConvertDateTime(DateTime value)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
51 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
52 return string.Format("TO_DATE('{0}','YYYYMMDDHH24MISS')", value.ToString("yyyyMMddHHmmss"));
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
53 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
54
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
55 /// <summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
56 /// Convert DateTime to TO_TIMESTAMP('value','YYYYMMDDHH24MISSFF3')
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
57 /// </summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
58 /// <param name="value">DateTime</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
59 /// <returns>DateTime converted for oracle query</returns>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
60 public static string SqlConvertTimeStamp(DateTime value)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
61 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
62 return string.Format("TO_TIMESTAMP('{0}','YYYYMMDDHH24MISSFF3')", value.ToString("yyyyMMddHHmmssfff"));
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
63 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
64
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
65 /// <summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
66 /// Convert DateTime to TO_CHAR(TO_DATE('value','YYYYMMDD')))
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
67 /// </summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
68 /// <param name="value">DateTime</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
69 /// <returns>DateTime converted for oracle query</returns>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
70 public static string SqlConvertDateToChar(DateTime value)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
71 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
72 return string.Format("TO_CHAR(TO_DATE('{0}','YYYYMMDD'))", value.ToString("yyyyMMdd"));
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
73 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
74
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
75 #endregion
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
76
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
77 #region Connection string
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
78
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
79 /// <summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
80 /// Generate the minimum connection string. The connection string looks like
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
81 /// Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = server)(PORT = port)))(CONNECT_DATA = (SID = sid)));User Id=username;Password=password;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
82 /// </summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
83 /// <param name="userName">Username</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
84 /// <param name="password">Password</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
85 /// <param name="server">Server name</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
86 /// <param name="sid">Database SID</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
87 /// <param name="port">Port of the server. Default value is 1521</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
88 /// <returns>Default connection string</returns>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
89 public static string GetFullConnectionString(string userName, string password, string server, string sid, int port = 1521)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
90 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
91 return
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
92 string.Format(
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
93 "Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = {0})(PORT = {1})))(CONNECT_DATA = (SID = {2})));User Id={3};Password={4};",
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
94 server, port, sid, userName, password);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
95 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
96
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
97 /// <summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
98 /// Generate the minimum connection string. The connection string looks like
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
99 /// Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = server)(PORT = port)))(CONNECT_DATA = (SID = sid)));User Id=username;Password=password;Pooling=False;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
100 /// </summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
101 /// <param name="userName">Username</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
102 /// <param name="password">Password</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
103 /// <param name="server">Server name</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
104 /// <param name="sid">Database SID</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
105 /// <param name="port">Port of the server. Default value is 1521</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
106 /// <returns>Default connection string</returns>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
107 public static string GetFullConnectionStringWithoutPooling(string userName, string password, string server, string sid, int port = 1521)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
108 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
109 return
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
110 string.Format(
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
111 "Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = {0})(PORT = {1})))(CONNECT_DATA = (SID = {2})));User Id={3};Password={4};Pooling=False;",
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
112 server, port, sid, userName, password);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
113 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
114
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
115 /// <summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
116 /// Generate the minimum connection string. The connection string looks like
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
117 /// Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = server)(PORT = port)))(CONNECT_DATA = (SID = sid)));User Id=username;Password=password;Connection Timeout=timeout;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
118 /// </summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
119 /// <param name="userName">Username</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
120 /// <param name="password">Password</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
121 /// <param name="server">Server name</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
122 /// <param name="sid">Database SID</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
123 /// <param name="port">Port of the server. Default value is 1521</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
124 /// <returns>Default connection string</returns>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
125 public static string GetFullConnectionString(string userName, string password, string server, string sid,
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
126 TimeSpan timeOut, int port = 1521)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
127 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
128 return
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
129 string.Format(
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
130 "Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = {0})(PORT = {1})))(CONNECT_DATA = (SID = {2})));User Id={3};Password={4};Connection Timeout={5};",
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
131 server, port, sid, userName, password, (int)timeOut.TotalSeconds);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
132 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
133
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
134 /// <summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
135 /// Generate the minimum connection string. The connection string looks like
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
136 /// Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = server)(PORT = port)))(CONNECT_DATA = (SID = sid)));User Id=username;Password=password;Connection Timeout=timeout;Pooling=False;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
137 /// </summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
138 /// <param name="userName">Username</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
139 /// <param name="password">Password</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
140 /// <param name="server">Server name</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
141 /// <param name="sid">Database SID</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
142 /// <param name="port">Port of the server. Default value is 1521</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
143 /// <returns>Default connection string</returns>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
144 public static string GetFullConnectionStringWithoutPooling(string userName, string password, string server, string sid,
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
145 TimeSpan timeOut, int port = 1521)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
146 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
147 return
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
148 string.Format(
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
149 "Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = {0})(PORT = {1})))(CONNECT_DATA = (SID = {2})));User Id={3};Password={4};Connection Timeout={5};Pooling=False;",
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
150 server, port, sid, userName, password, (int)timeOut.TotalSeconds);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
151 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
152
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
153 /// <summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
154 /// Generate the minimum connection string. The connection string looks like
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
155 /// Data Source=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = server)(PORT = port)))(CONNECT_DATA = (SID = sid)));User Id=username;Password=password;Connection Timeout=timeout;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
156 /// </summary>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
157 /// <param name="userName">Username</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
158 /// <param name="password">Password</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
159 /// <param name="server">Server name</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
160 /// <param name="sid">Database SID</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
161 /// <param name="port">Port of the server. Default value is 1521</param>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
162 /// <returns>Default connection string</returns>
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
163 public static string GetFullConnectionString(string userName, string password, string server, string sid, int timeOutInSecond, int port = 1521)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
164 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
165 return GetFullConnectionString(userName, password, server, sid, TimeSpan.FromSeconds(timeOutInSecond), port);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
166 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
167
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
168 #endregion
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
169
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
170 public static string Interpret(IDbCommand poCommand)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
171 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
172 if (poCommand.Parameters.Count == 0)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
173 return poCommand.CommandText;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
174
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
175 var oRegex = new Regex(@"(?<string>'[^']+')|(?<Parameters>:[a-zA-Z0-9_]+)");
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
176 MatchCollection oMatchCollection = oRegex.Matches(poCommand.CommandText);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
177
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
178 string strQuery = poCommand.CommandText + " ";
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
179 int matchCount = 0;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
180
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
181 for (int i = 0; i < oMatchCollection.Count; i++)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
182 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
183 if (oMatchCollection[i].Groups["string"].Success)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
184 continue;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
185
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
186 string strParameter = oMatchCollection[i].Groups["Parameters"].Captures[0].Value;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
187
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
188 var param = (IDbDataParameter)poCommand.Parameters[matchCount];
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
189 if (param.Value is DateTime)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
190 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
191 var dt = (DateTime)param.Value;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
192
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
193 strQuery = strQuery.Replace(strParameter + " ",
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
194 dt.Date == dt
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
195 ? SqlConvertDate(dt) + " "
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
196 : SqlConvertDateTime(dt) + " ");
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
197 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
198 else if (param.Value is string)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
199 strQuery = strQuery.Replace(strParameter, SqlConvertString(param.Value.ToString()) + " ");
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
200 else if (param.Value is Int16)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
201 strQuery = strQuery.Replace(strParameter, ((Int16)param.Value).ToString(CultureInfo.InvariantCulture) + " ");
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
202 else if (param.Value is Int32)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
203 strQuery = strQuery.Replace(strParameter, ((Int32)param.Value).ToString(CultureInfo.InvariantCulture) + " ");
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
204 else if (param.Value is Int64)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
205 strQuery = strQuery.Replace(strParameter, ((Int64)param.Value).ToString(CultureInfo.InvariantCulture) + " ");
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
206 else if (param.Value is decimal)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
207 strQuery = strQuery.Replace(strParameter, ((decimal)param.Value).ToString(CultureInfo.InvariantCulture) + " ");
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
208 else if (param.Value is float)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
209 strQuery = strQuery.Replace(strParameter, ((float)param.Value).ToString(CultureInfo.InvariantCulture) + " ");
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
210 else if (param.Value is double)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
211 strQuery = strQuery.Replace(strParameter, ((double)param.Value).ToString(CultureInfo.InvariantCulture) + " ");
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
212 else if (param.Value is TimeSpan)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
213 strQuery = strQuery.Replace(strParameter, "'" + ((TimeSpan)param.Value).ToString() + "' ");
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
214 else
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
215 throw new NotImplementedException(param.Value.GetType() + " is not implemented yet.");
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
216
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
217 matchCount++;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
218 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
219
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
220 if (matchCount != poCommand.Parameters.Count)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
221 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
222 // ReSharper disable InvocationIsSkipped
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
223 Debug.WriteLine(
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
224 "Number of parameters in query is not equals to number of parameters set in the command object " +
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
225 poCommand.CommandText);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
226 // ReSharper restore InvocationIsSkipped
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
227 var msg =
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
228 "Number of parameters in query is not equals to number of parameters set in the command object : " + poCommand.CommandText + "\r\n" +
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
229 "Query params :\r\n";
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
230
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
231 foreach (Match match in oMatchCollection)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
232 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
233 msg += "\t" + match.Value + "\r\n";
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
234 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
235
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
236 msg += "\nCommand params :\r\n";
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
237
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
238 foreach (IDataParameter param in poCommand.Parameters)
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
239 {
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
240 msg += "\t" + param.ParameterName + " = " + Convert.ToString(param) + "\r\n";
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
241 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
242
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
243 throw new Exception(msg);
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
244 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
245
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
246 return strQuery;
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
247 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
248
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
249 }
f990fcb411a9 Копия текущей версии из github
cin
parents:
diff changeset
250 }