2006-11-16 Nagappan A <anagappan@novell.com>
[mono.git] / mcs / class / System.Data / System.Data.ProviderBase / DbCommandBase.cs
1 //
2 // System.Data.ProviderBase.DbCommandBase
3 //
4 // Author:
5 //   Tim Coleman (tim@timcoleman.com)
6 //       Boris Kirzner (borisk@mainsoft.com)
7 //
8 // Copyright (C) Tim Coleman, 2003
9 //
10
11 //
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
13 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 //
34
35 #if NET_2_0 || TARGET_JVM
36
37 using System.Data.Common;
38
39 namespace System.Data.ProviderBase {
40         public abstract class DbCommandBase : DbCommand
41         {
42                 #region Fields
43                 
44                 string _commandText;
45                 int _commandTimeout;
46                 CommandType _commandType;
47                 bool _designTimeVisible;
48                 UpdateRowSource _updatedRowSource;
49
50                 #endregion // Fields
51
52                 #region Constructors
53                 
54                 protected DbCommandBase ()
55                 {
56                         _commandText = String.Empty;
57                         _commandTimeout = 30;
58                         _commandType = CommandType.Text;
59                         _designTimeVisible = true;
60                         _updatedRowSource = UpdateRowSource.Both;
61                 }
62
63                 protected DbCommandBase (DbCommandBase from)
64                 {
65                         _commandText = from._commandText;
66                         _commandTimeout = from._commandTimeout;
67                         _commandType = from._commandType;
68                         _updatedRowSource = from._updatedRowSource;
69                         _designTimeVisible = from._designTimeVisible;
70                 }
71
72                 #endregion // Constructors
73
74                 #region Properties
75
76                 public override string CommandText {
77                         get { return _commandText; }
78                         set { _commandText = value; }
79                 }
80                 public override int CommandTimeout {
81                         get { return _commandTimeout; }
82                         set { _commandTimeout = value; }
83                 }
84
85                 public override CommandType CommandType {
86                         get { return _commandType; }
87                         set { _commandType = value; }
88                 }
89
90                 public override bool DesignTimeVisible {
91                         get { return _designTimeVisible; }
92                         set { _designTimeVisible = value; }
93                 }       
94
95                 public override UpdateRowSource UpdatedRowSource {
96                         get { return _updatedRowSource; }
97                         set { _updatedRowSource = value; }
98                 }
99
100                 #endregion // Properties
101
102                 #region Methods
103
104                 [MonoTODO]
105                 public override void Cancel ()
106                 {
107                         throw new NotImplementedException ();
108                 }
109
110                 
111                 public override int ExecuteNonQuery ()
112                 {
113                         IDataReader reader = null;
114                         try {
115                                 reader = ExecuteReader ();
116                         }
117                         finally {
118                                 if (reader != null)
119                                         reader.Close ();                                
120                         }
121                         return reader.RecordsAffected;
122                 }
123
124                 public override object ExecuteScalar ()
125                 {
126                         IDataReader reader = ExecuteReader(CommandBehavior.SingleRow | CommandBehavior.SequentialAccess);
127                         
128                         try {
129                                 do {
130                                         if (reader.FieldCount > 0 && reader.Read ())
131                                                 return reader.GetValue (0);                     
132                                 }
133                                 while (reader.NextResult ());
134                                 return null;
135                         } finally {
136                                 reader.Close();
137                         }
138                 }
139
140                 [MonoTODO]
141                 public override void Prepare ()
142                 {
143                         throw new NotImplementedException ();
144                 }
145
146                 public virtual void PropertyChanging ()
147                 {
148                 }
149
150                 public virtual void ResetCommandTimeout ()
151                 {
152                         _commandTimeout = 30;
153                 }
154
155                 [MonoTODO]
156                 protected internal static void SetInputParameterValues (DbCommand command, object[] inputParameterValues)
157                 {
158                         throw new NotImplementedException ();
159                 }
160
161                 #endregion // Methods
162         }
163 }
164
165 #endif