2003-06-11 Francisco Figueiredo Jr. <fxjrlists@yahoo.com.br>
[mono.git] / mcs / class / Npgsql / Npgsql / NpgsqlParameter.cs
1 // created on 18/5/2002 at 01:25
2
3 // Npgsql.NpgsqlParameter.cs
4 // 
5 // Author:
6 //      Francisco Jr. (fxjrlists@yahoo.com.br)
7 //
8 //      Copyright (C) 2002 The Npgsql Development Team
9 //      npgsql-general@gborg.postgresql.org
10 //      http://gborg.postgresql.org/project/npgsql/projdisplay.php
11 //
12 // This library is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU Lesser General Public
14 // License as published by the Free Software Foundation; either
15 // version 2.1 of the License, or (at your option) any later version.
16 // 
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 // Lesser General Public License for more details.
21 // 
22 // You should have received a copy of the GNU Lesser General Public
23 // License along with this library; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
26
27 using System;
28 using System.Data;
29 using NpgsqlTypes;
30
31
32 namespace Npgsql
33 {
34         ///<summary>
35         /// This class represents a parameter to a command that will be sent to server
36         ///</summary>
37         public sealed class NpgsqlParameter : IDbDataParameter, IDataParameter
38         {
39         
40     // Logging related values
41     private static readonly String CLASSNAME = "NpgsqlParameter";
42     
43                 // Fields to implement IDbDataParameter interface.
44                 private byte                            precision;
45                 private byte                            scale;
46                 private Int32                           size;
47                 
48                 // Fields to implement IDataParameter
49                 private DbType                          db_type;
50                 private ParameterDirection      direction;
51                 private Boolean                         is_nullable;
52                 private String                          name;
53                 private String                          source_column;
54                 private DataRowVersion          source_version;
55                 private Object                          value;
56                 
57                 
58                 
59                 // Constructors
60                 // [TODO] Implement other constructors.
61                 
62                 public NpgsqlParameter()
63                 {
64                         
65                 }
66                 
67                 public NpgsqlParameter(String parameterName, DbType parameterType)
68                 {
69                         name = parameterName;
70                   if (name[0] != ':') // Support both ':'paramname and paramname constructions.
71                     name = ':' + name;
72                   
73                         db_type = parameterType;
74                         
75                 }
76                 
77                 public NpgsqlParameter(String parameterName, DbType parameterType, Int32 size, String sourceColumn)
78                 {
79                         name = parameterName;
80                   if (name[0] != ':') // Support both ':'paramname and paramname constructions.
81                     name = ':' + name;
82                         db_type = parameterType;
83                         this.size = size;
84                         source_column = sourceColumn;
85                         direction = ParameterDirection.Input;
86                 }
87                 // Implementation of IDbDataParameter
88                 
89                 public Byte Precision
90                 {
91                         get
92                         {
93                                 return precision;
94                         }
95                         
96                         set
97                         {
98                                 precision = value;
99                                 NpgsqlEventLog.LogMsg("Set " + CLASSNAME + ".Precision = " + value, LogLevel.Normal);
100                         }
101                 }
102                 
103                 public Byte Scale
104                 {
105                         get
106                         {
107                                 return scale;
108                         }
109                         
110                         set
111                         {
112                                 scale = value;
113                                 NpgsqlEventLog.LogMsg("Set " + CLASSNAME + ".Scale = " + value, LogLevel.Normal);
114                         }
115                 }
116                 
117                 public Int32 Size
118                 {
119                         get
120                         {
121                                 return size;
122                         }
123                         
124                         set
125                         {
126                                 size = value;
127                                 NpgsqlEventLog.LogMsg("Set " + CLASSNAME + ".Size = " + value, LogLevel.Normal);
128                         }
129                 }
130                 
131                 public DbType DbType
132                 {
133                         get
134                         {
135                                 return db_type;
136                         }
137                         
138                         // [TODO] Validate data type.
139                         set
140                         {
141                                 db_type = value;
142                                 NpgsqlEventLog.LogMsg("Set " + CLASSNAME + ".DbType = " + value, LogLevel.Normal);
143                         }
144                 }
145                 
146                 
147                 
148                 public ParameterDirection Direction
149                 {
150                         get
151                         {
152                                 NpgsqlEventLog.LogMsg("Get " + CLASSNAME + ".Direction", LogLevel.Normal);
153                                 return direction;
154                         }
155                         
156                         set
157                         {
158                                 direction = value;
159                                 NpgsqlEventLog.LogMsg("Set " + CLASSNAME + ".Direction = " + value, LogLevel.Normal);
160                         }
161                 }
162                 
163                 public Boolean IsNullable
164                 {
165                         get
166                         {
167                                 return is_nullable;
168                         }
169                         
170                         set
171                         {
172                                 is_nullable = value;
173                                 NpgsqlEventLog.LogMsg("Set " + CLASSNAME + ".IsNullable = " + value, LogLevel.Normal);
174                         }
175                 }
176                 
177                 public String ParameterName
178                 {
179                         get
180                         {
181                                 NpgsqlEventLog.LogMsg("Get " + CLASSNAME + ".ParameterName", LogLevel.Normal);
182                                 return name;
183                         }
184                         
185                         set
186                         {
187                                 name = value;
188                           if (name[0] != ':')
189                             name = ':' + name;
190                                 NpgsqlEventLog.LogMsg("Set " + CLASSNAME + ".ParameterName = " + value, LogLevel.Normal);
191                         }
192                 }
193                 
194                 public String SourceColumn 
195                 {
196                         get
197                         {
198                                 NpgsqlEventLog.LogMsg(CLASSNAME + ".get_SourceColumn" + value, LogLevel.Normal);
199                                 return source_column;
200                         }
201                         
202                         set
203                         {
204                                 source_column = value;
205                                 NpgsqlEventLog.LogMsg("Set " + CLASSNAME + ".SourceColumn = " + value, LogLevel.Normal);
206                         }
207                 }
208                 
209                 public DataRowVersion SourceVersion
210                 {
211                         get
212                         {
213                                 NpgsqlEventLog.LogMsg(CLASSNAME + ".get_SourceVersion = " + value, LogLevel.Normal);
214                                 return source_version;
215                         }
216                         
217                         set
218                         {
219                                 source_version = value;
220                                 NpgsqlEventLog.LogMsg("Set " + CLASSNAME + ".SourceVersion = " + value, LogLevel.Normal);
221                         }
222                 }
223                 
224                 public Object Value
225                 {
226                         get
227                         {
228                                 NpgsqlEventLog.LogMsg("Get " + CLASSNAME + ".Value", LogLevel.Normal);
229                                 return value;
230                         }
231                         
232                         // [TODO] Check and validate data type.
233                         set
234                         {
235                                 this.value = value;
236                                 NpgsqlEventLog.LogMsg("Set " + CLASSNAME + ".Value", LogLevel.Normal);
237                         }
238                 }
239                                 
240         }
241 }