Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SqlDataSource.cs « System.Web.UI.WebControls « System.Web « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 069795afe35042ad73f35d2208f7999d72a4c6e6 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
//
// System.Web.UI.WebControls.SqlDataSource
//
// Authors:
//	Ben Maurer (bmaurer@users.sourceforge.net)
//	Sanjay Gupta (gsanjay@novell.com)
//	Chris Toshok (toshok@ximian.com)
//
// (C) 2003 Ben Maurer
// (C) 2004-2006 Novell, Inc. (http://www.novell.com)
//

//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#if NET_2_0
using System.Collections;
using System.Collections.Specialized;
using System.Configuration;
using System.Drawing;
using System.Web.Configuration;
using System.Data.Common;
using System.Data.SqlClient;
using System.Text;
using System.ComponentModel;

namespace System.Web.UI.WebControls {

	[ParseChildrenAttribute (true)]
	[PersistChildrenAttribute (false)]
	[DefaultPropertyAttribute ("SelectQuery")]
	[DesignerAttribute ("System.Web.UI.Design.WebControls.SqlDataSourceDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
	[DefaultEventAttribute ("Selecting")]
	public class SqlDataSource : DataSourceControl {
		
		public SqlDataSource ()
		{
		}

		public SqlDataSource (string connectionString, string selectCommand)
		{
			ConnectionString = connectionString;
			SelectCommand = selectCommand;
		}
		
		public SqlDataSource (string providerName, string connectionString, string selectCommand)
		{
			ProviderName = providerName;
			ConnectionString = connectionString;
			SelectCommand = selectCommand;
		}

		protected override DataSourceView GetView (string viewName)
		{
			if (viewName == "" || viewName == null)
				return View;
			else
				throw new ArgumentException ("viewName");
		}
		
		protected virtual SqlDataSourceView CreateDataSourceView (string viewName)
		{
			SqlDataSourceView view = new SqlDataSourceView (this, viewName, this.Context);
			view.DataSourceViewChanged += new EventHandler (ViewChanged);
			if (IsTrackingViewState)
				((IStateManager) view).TrackViewState ();			
			return view;
		}

		protected virtual DbProviderFactory GetDbProviderFactory ()
		{
			DbProviderFactory f = null;

			if (ProviderName != null && ProviderName != "") {
				try {
					f = DbProviderFactories.GetFactory(ProviderName);
				}
				catch { /* nada */ }
				if (f != null)
					return f;
			}

			return SqlClientFactory.Instance;
		}

		internal DbProviderFactory GetDbProviderFactoryInternal ()
		{
			return GetDbProviderFactory ();
		}

		protected override ICollection GetViewNames ()
		{
			return new string [] { "DefaultView" };
		}
			
		public int Insert ()
		{
			return View.Insert (null);
		}
		
		public int Delete ()
		{
			return View.Delete (null, null);
		}
		
		public IEnumerable Select (DataSourceSelectArguments args)
		{
			return View.Select (args);			
		}
		
		public int Update ()
		{
			return View.Update (null, null, null);
		}
			
		protected override void LoadViewState (object savedState)
		{
			Pair p = savedState as Pair;
			if (p != null) {
				base.LoadViewState (p.First);
				((IStateManager) View).LoadViewState (p.Second);
			}
		}
		
		protected override object SaveViewState ()
		{
			object me = base.SaveViewState (), view = ((IStateManager) View).SaveViewState ();
			if (me != null || view != null)
				return new Pair (me, view);
			else
				return null;
		}
		
		protected override void TrackViewState ()
		{
			base.TrackViewState ();
			if (view != null)
				((IStateManager) view).TrackViewState ();
		}

#region TODO
		[MonoTODO]
		[DefaultValue ("")]
		public virtual string CacheKeyDependency {
			get { return ViewState.GetString ("CacheKeyDependency", ""); }
			set { ViewState ["CacheKeyDependency"] = value; }
		}

		[MonoTODO]
		[DefaultValue (true)]
		public virtual bool CancelSelectOnNullParameter {
			get { return ViewState.GetBool ("CancelSelectOnNullParameter", true); }
			set { ViewState["CancelSelectOnNullParameter"] = value; }
		}

		[MonoTODO]
		[DefaultValue (ConflictOptions.OverwriteChanges)]
		public ConflictOptions ConflictDetection {
			get { return (ConflictOptions) ViewState.GetInt ("ConflictDetection", (int)ConflictOptions.OverwriteChanges); }
			set { ViewState ["ConflictDetection"] = value; }
		}

		[MonoTODO]
		[DefaultValue (SqlDataSourceCommandType.Text)]
		public SqlDataSourceCommandType DeleteCommandType {
			get { return (SqlDataSourceCommandType) ViewState.GetInt ("DeleteCommandType", (int)SqlDataSourceCommandType.StoredProcedure); }
			set { ViewState ["DeleteCommandType"] = value; }
		}

		[MonoTODO]
		[DefaultValue (SqlDataSourceCommandType.Text)]
		public SqlDataSourceCommandType InsertCommandType {
			get { return (SqlDataSourceCommandType) ViewState.GetInt ("InsertCommandType", (int)SqlDataSourceCommandType.StoredProcedure); }
			set { ViewState ["InsertCommandType"] = value; }
		}

		[MonoTODO]
		[DefaultValue (SqlDataSourceCommandType.Text)]
		public SqlDataSourceCommandType SelectCommandType {
			get { return (SqlDataSourceCommandType) ViewState.GetInt ("SelectCommandType", (int)SqlDataSourceCommandType.StoredProcedure); }
			set { ViewState ["SelectCommandType"] = value; }
		}

		[MonoTODO]
		[DefaultValue (SqlDataSourceCommandType.Text)]
		public SqlDataSourceCommandType UpdateCommandType {
			get { return (SqlDataSourceCommandType) ViewState.GetInt ("UpdateCommandType", (int)SqlDataSourceCommandType.StoredProcedure); }
			set { ViewState ["UpdateCommandType"] = value; }
		}

		[MonoTODO]
		[DefaultValue ("{0}")]
		public string OldValuesParameterFormatString {
			get { return ViewState.GetString ("OldValuesParameterFormatString", "{0}"); }
			set { ViewState ["OldValuesParameterFormatString"] = value; }
		}
		
		[DefaultValue ("")]
		[MonoTODO]
		public virtual string SqlCacheDependency {
			get { return ViewState.GetString ("SqlCacheDependency", ""); }
			set { ViewState ["SqlCacheDependency"] = value; }
		}

		[MonoTODO]
		[DefaultValue ("")]
		public string SortParameterName {
			get { return ViewState.GetString ("SortParameterName", ""); }
			set { ViewState ["SortParameterName"] = value; }
		}

		[DefaultValue (0)]
		//		[TypeConverter (typeof (DataSourceCacheDurationConverter))]
		public virtual int CacheDuration {
			get { return ViewState.GetInt ("CacheDuration", 0); }
			set { ViewState ["CacheDuration"] = value; }
		}

		[DefaultValue (DataSourceCacheExpiry.Absolute)]
		public virtual DataSourceCacheExpiry CacheExpirationPolicy {
			get { return (DataSourceCacheExpiry) ViewState.GetInt ("CacheExpirationPolicy", (int)DataSourceCacheExpiry.Absolute); }
			set { ViewState ["CacheExpirationPolicy"] = value; }
		}

		[DefaultValue (false)]
		public virtual bool EnableCaching {
			get { return ViewState.GetBool ("EnableCaching", false); }
			set { ViewState ["EnableCaching"] = value; }
		}
#endregion

		[DefaultValueAttribute ("")]
		[TypeConverterAttribute ("System.Web.UI.Design.WebControls.DataProviderNameConverter, " + Consts.AssemblySystem_Design)]
		public virtual string ProviderName {
			get { return ViewState.GetString ("ProviderName", ""); }
			set { ViewState ["ProviderName"] = value; }
		}
		
		
		[EditorAttribute ("System.Web.UI.Design.WebControls.SqlDataSourceConnectionStringEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
		[DefaultValueAttribute ("")]
		public virtual string ConnectionString {
			get { return ViewState.GetString ("ConnectionString", ""); }
			set { ViewState ["ConnectionString"] = value; }
		}
		
		[DefaultValueAttribute (SqlDataSourceMode.DataSet)]
		public SqlDataSourceMode DataSourceMode {
			get { return (SqlDataSourceMode) ViewState.GetInt ("DataSourceMode", (int)SqlDataSourceMode.DataSet); }
			set { ViewState ["DataSourceMode"] = value; }
		}
				
		[DefaultValueAttribute ("")]
		public string DeleteCommand {
			get { return View.DeleteCommand; }
			set { View.DeleteCommand = value; }
		}
		
		[EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
		[MergablePropertyAttribute (false)]
		[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
		[DefaultValueAttribute (null)]
		public ParameterCollection DeleteParameters {
			get { return View.DeleteParameters; }
		}
		
		[DefaultValueAttribute (null)]
		[EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
		[MergablePropertyAttribute (false)]
		[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
		public ParameterCollection FilterParameters {
			get { return View.FilterParameters; }
		}
		
		[DefaultValueAttribute ("")]
		public string InsertCommand {
			get { return View.InsertCommand; }
			set { View.InsertCommand = value; }
		}
		
		[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
		[DefaultValueAttribute (null)]
		[MergablePropertyAttribute (false)]
		[EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
		public ParameterCollection InsertParameters {
			get { return View.InsertParameters; }
		}

		[DefaultValueAttribute ("")]
		public string SelectCommand {
			get { return View.SelectCommand; }
			set { View.SelectCommand = value; }
		}
		
		[DefaultValueAttribute (null)]
		[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
		[MergablePropertyAttribute (false)]
		[EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
		public ParameterCollection SelectParameters {
			get { return View.SelectParameters; }
		}
		
		[DefaultValueAttribute ("")]
		public string UpdateCommand {
			get { return View.UpdateCommand; }
			set { View.UpdateCommand = value; }
		}
		
		[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
		[EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
		[MergablePropertyAttribute (false)]
		[DefaultValueAttribute (null)]
		public ParameterCollection UpdateParameters {
			get { return View.UpdateParameters; }
		}
		
		[DefaultValueAttribute ("")]
		public string FilterExpression {
			get { return View.FilterExpression; }
			set { View.FilterExpression = value; }
		}
		
		public event SqlDataSourceStatusEventHandler Deleted {
			add { View.Deleted += value; }
			remove { View.Deleted -= value; }
		}
		
		public event SqlDataSourceCommandEventHandler Deleting {
			add { View.Deleting += value; }
			remove { View.Deleting -= value; }
		}
		
		public event SqlDataSourceStatusEventHandler Inserted {
			add { View.Inserted += value; }
			remove { View.Inserted -= value; }
		}
		
		public event SqlDataSourceFilteringEventHandler Filtering {
			add { View.Filtering += value; }
			remove { View.Filtering -= value; }
		}

		public event SqlDataSourceCommandEventHandler Inserting {
			add { View.Inserting += value; }
			remove { View.Inserting -= value; }
		}
		
		public event SqlDataSourceStatusEventHandler Selected {
			add { View.Selected += value; }
			remove { View.Selected -= value; }
		}
		
		public event SqlDataSourceSelectingEventHandler Selecting {
			add { View.Selecting += value; }
			remove { View.Selecting -= value; }
		}
		
		public event SqlDataSourceStatusEventHandler Updated {
			add { View.Updated += value; }
			remove { View.Updated -= value; }
		}
		
		public event SqlDataSourceCommandEventHandler Updating {
			add { View.Updating += value; }
			remove { View.Updating -= value; }
		}
		
		SqlDataSourceView view;
		SqlDataSourceView View {
			get {
				if (view == null) {
					view = CreateDataSourceView ("DefaultView");
					view.DataSourceViewChanged += new EventHandler (ViewChanged);
					if (IsTrackingViewState)
						((IStateManager) view).TrackViewState ();
				}
				return view;
			}
		}
		
		void ViewChanged (object source, EventArgs e)
		{
			RaiseDataSourceChangedEvent (e);
		}
	}
}
#endif