2002-05-08 Rodrigo Moya <rodrigo@ximian.com>
[mono.git] / mcs / class / System.Data / System.Data.SqlTypes / SqlString.cs
1 //
2 // System.Data.SqlTypes.SqlString
3 //
4 // Author:
5 //   Rodrigo Moya (rodrigo@ximian.com)
6 //   Daniel Morgan (danmorg@sc.rr.com)
7 //   Tim Coleman (tim@timcoleman.com)
8 //
9 // (C) Ximian, Inc. 2002
10 // (C) Copyright 2002 Tim Coleman
11 //
12
13 using System;
14 using System.Globalization;
15
16 namespace System.Data.SqlTypes
17 {
18         /// <summary>
19         /// A variable-length stream of characters 
20         /// to be stored in or retrieved from the database
21         /// </summary>
22         public struct SqlString : INullable, IComparable 
23         {
24
25                 #region Fields
26
27                 string value;
28
29                 public static readonly int BinarySort;
30                 public static readonly int IgnoreCase;
31                 public static readonly int IgnoreKanaType;
32                 public static readonly int IgnoreNonSpace;
33                 public static readonly int IgnoreWidth;
34                 public static readonly SqlString Null;
35
36                 #endregion // Fields
37
38                 #region Constructors
39
40                 // init with a string data
41                 public SqlString (string data) 
42                 {
43                         this.value = data;
44                 }
45
46                 // init with a string data and locale id values.
47                 [MonoTODO]
48                 public SqlString (string data, int lcid) 
49                 {
50                         throw new NotImplementedException ();
51                 }
52
53                 // init with locale id, compare options, 
54                 // and an array of bytes data
55                 [MonoTODO]
56                 public SqlString (int lcid, SqlCompareOptions compareOptions, byte[] data) 
57                 {
58                         throw new NotImplementedException ();
59                 }
60
61                 // init with string data, locale id, and compare options
62                 [MonoTODO]
63                 public SqlString (string data, int lcid, SqlCompareOptions compareOptions) 
64                 {
65                         throw new NotImplementedException ();
66                 }
67
68                 // init with locale id, compare options, array of bytes data,
69                 // and whether unicode is encoded or not
70                 [MonoTODO]
71                 public SqlString (int lcid, SqlCompareOptions compareOptions, byte[] data, bool fUnicode) 
72                 {
73                         throw new NotImplementedException ();
74                 }
75
76                 // init with locale id, compare options, array of bytes data,
77                 // starting index in the byte array, 
78                 // and number of bytes to copy
79                 [MonoTODO]
80                 public SqlString (int lcid, SqlCompareOptions compareOptions, byte[] data, int index, int count) 
81                 {
82                         throw new NotImplementedException ();
83                 }
84
85                 // init with locale id, compare options, array of bytes data,
86                 // starting index in the byte array, number of byte to copy,
87                 // and whether unicode is encoded or not
88                 [MonoTODO]
89                 public SqlString (int lcid, SqlCompareOptions compareOptions, byte[] data, int index, int count, bool fUnicode) 
90                 {
91                         throw new NotImplementedException ();
92                 }
93
94                 #endregion // Constructors
95
96
97                 #region Public Properties
98
99                 public CompareInfo CompareInfo {
100                         [MonoTODO]
101                         get { throw new NotImplementedException ();
102                         }
103                 }
104
105                 public CultureInfo CultureInfo {
106                         [MonoTODO]
107                         get { throw new NotImplementedException ();
108                         }
109                 }
110
111                 public bool IsNull {
112                         get { return (bool) (this == SqlString.Null); }
113                 }
114
115                 // geographics location and language (locale id)
116                 public int LCID {
117                         [MonoTODO]
118                         get { throw new NotImplementedException ();
119                         }
120                 }
121         
122                 public SqlCompareOptions SqlCompareOptions {
123                         [MonoTODO]
124                         get { throw new NotImplementedException ();
125                         }
126                 }
127
128                 public string Value {
129                         get {
130                                 if (this.IsNull)
131                                         throw new SqlNullValueException ("The property contains Null.");
132                                 else
133                                         return value;
134                         }
135                 }
136
137                 #endregion // Public Properties
138
139                 #region Public Methods
140
141                 [MonoTODO]
142                 public SqlString Clone() 
143                 {
144                         throw new NotImplementedException ();
145                 }
146
147                 [MonoTODO]
148                 public static CompareOptions CompareOptionsFromSqlCompareOptions (SqlCompareOptions compareOptions) 
149                 {
150                         throw new NotImplementedException ();
151                 }
152
153                 // **********************************
154                 // Comparison Methods
155                 // **********************************
156
157                 public int CompareTo(object value)
158                 {
159                         if (value == null)
160                                 return 1;
161                         else if (!(value is SqlString))
162                                 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlString"));
163                         else if (((SqlString)value).IsNull)
164                                 return 1;
165                         else
166                                 return this.value.CompareTo (((SqlString)value).Value);
167                 }
168
169                 public static SqlString Concat(SqlString x, SqlString y) 
170                 {
171                         return (x + y);
172                 }
173
174                 public override bool Equals(object value) 
175                 {
176                         if (!(value is SqlString))
177                                 return false;
178                         else
179                                 return (bool) (this == (SqlString)value);
180                 }
181
182                 public static SqlBoolean Equals(SqlString x, SqlString y) 
183                 {
184                         return (x == y);
185                 }
186
187                 [MonoTODO]
188                 public override int GetHashCode() 
189                 {
190                         throw new NotImplementedException ();
191                 }
192
193                 [MonoTODO]
194                 public byte[] GetNonUnicodeBytes() 
195                 {
196                         throw new NotImplementedException ();
197                 }
198
199                 [MonoTODO]
200                 public byte[] GetUnicodeBytes() 
201                 {
202                         throw new NotImplementedException ();
203                 }
204
205                 public static SqlBoolean GreaterThan(SqlString x, SqlString y) 
206                 {
207                         return (x > y);
208                 }
209
210                 public static SqlBoolean GreaterThanOrEqual(SqlString x, SqlString y) 
211                 {
212                         return (x >= y);
213                 }
214
215                 public static SqlBoolean LessThan(SqlString x, SqlString y) 
216                 {
217                         return (x < y);
218                 }
219
220                 public static SqlBoolean LessThanOrEqual(SqlString x, SqlString y) 
221                 {
222                         return (x <= y);
223                 }
224
225                 public static SqlBoolean NotEquals(SqlString x, SqlString y) 
226                 {
227                         return (x != y);
228                 }
229
230                 // ****************************************
231                 // Type Conversions From SqlString To ...
232                 // ****************************************
233
234                 public SqlBoolean ToSqlBoolean() 
235                 {
236                         return ((SqlBoolean)this);
237                 }
238
239                 public SqlByte ToSqlByte() 
240                 {
241                         return ((SqlByte)this);
242                 }
243
244                 public SqlDateTime ToSqlDateTime() 
245                 {
246                         return ((SqlDateTime)this);
247                 }
248
249                 public SqlDecimal ToSqlDecimal() 
250                 {
251                         return ((SqlDecimal)this);
252                 }
253
254                 public SqlDouble ToSqlDouble() 
255                 {
256                         return ((SqlDouble)this);
257                 }
258
259                 public SqlGuid ToSqlGuid() 
260                 {
261                         return ((SqlGuid)this);
262                 }
263
264                 public SqlInt16 ToSqlInt16() 
265                 {
266                         return ((SqlInt16)this);
267                 }
268
269                 public SqlInt32 ToSqlInt32() 
270                 {
271                         return ((SqlInt32)this);
272                 }
273
274                 public SqlInt64 ToSqlInt64() 
275                 {
276                         return ((SqlInt64)this);
277                 }
278
279                 public SqlMoney ToSqlMoney() 
280                 {
281                         return ((SqlMoney)this);
282                 }
283
284                 public SqlSingle ToSqlSingle() 
285                 {
286                         return ((SqlSingle)this);
287                 }
288
289                 public override string ToString() 
290                 {
291                         return ((string)this);
292                 }
293
294                 // ***********************************
295                 // Operators
296                 // ***********************************
297
298                 // Concatenates
299                 public static SqlString operator + (SqlString x, SqlString y) 
300                 {
301                         return new SqlString (x.Value + y.Value);
302                 }
303
304                 // Equality
305                 public static SqlBoolean operator == (SqlString x, SqlString y) 
306                 {
307                         if (x.IsNull || y.IsNull)
308                                 return SqlBoolean.Null;
309                         else
310                                 return new SqlBoolean (x.Value == y.Value);
311                 }
312
313                 // Greater Than
314                 public static SqlBoolean operator > (SqlString x, SqlString y) 
315                 {
316                         if (x.IsNull || y.IsNull)
317                                 return SqlBoolean.Null;
318                         else
319                                 throw new NotImplementedException ();
320                 }
321
322                 // Greater Than Or Equal
323                 public static SqlBoolean operator >= (SqlString x, SqlString y) 
324                 {
325                         if (x.IsNull || y.IsNull)
326                                 return SqlBoolean.Null;
327                         else
328                                 throw new NotImplementedException ();
329                 }
330
331                 public static SqlBoolean operator != (SqlString x, SqlString y) 
332                 { 
333                         if (x.IsNull || y.IsNull)
334                                 return SqlBoolean.Null;
335                         else
336                                 return new SqlBoolean (x.Value != y.Value);
337                 }
338
339                 // Less Than
340                 public static SqlBoolean operator < (SqlString x, SqlString y) 
341                 {
342                         if (x.IsNull || y.IsNull)
343                                 return SqlBoolean.Null;
344                         else
345                                 throw new NotImplementedException ();
346                 }
347
348                 // Less Than Or Equal
349                 public static SqlBoolean operator <= (SqlString x, SqlString y) 
350                 {
351                         if (x.IsNull || y.IsNull)
352                                 return SqlBoolean.Null;
353                         else
354                                 throw new NotImplementedException ();
355                 }
356
357                 // **************************************
358                 // Type Conversions
359                 // **************************************
360
361                 public static explicit operator SqlString (SqlBoolean x) 
362                 {
363                         if (x.IsNull)
364                                 return Null;
365                         else
366                                 return new SqlString (x.ByteValue.ToString ());
367                 }
368
369                 public static explicit operator SqlString (SqlByte x) 
370                 {
371                         if (x.IsNull)
372                                 return Null;
373                         else
374                                 return new SqlString (x.Value.ToString ());
375                 }
376
377                 public static explicit operator SqlString (SqlDateTime x) 
378                 {
379                         if (x.IsNull)
380                                 return Null;
381                         else
382                                 return new SqlString (x.Value.ToString ());
383                 }
384
385                 public static explicit operator SqlString (SqlDecimal x) 
386                 {
387                         if (x.IsNull)
388                                 return Null;
389                         else
390                                 return new SqlString (x.Value.ToString ());
391                 }
392
393                 public static explicit operator SqlString (SqlDouble x) 
394                 {
395                         if (x.IsNull)
396                                 return Null;
397                         else
398                                 return new SqlString (x.Value.ToString ());
399                 }
400
401                 public static explicit operator SqlString (SqlGuid x) 
402                 {
403                         if (x.IsNull)
404                                 return Null;
405                         else
406                                 return new SqlString (x.Value.ToString ());
407                 }
408
409                 public static explicit operator SqlString (SqlInt16 x) 
410                 {
411                         if (x.IsNull)
412                                 return Null;
413                         else
414                                 return new SqlString (x.Value.ToString ());
415                 }
416
417                 public static explicit operator SqlString (SqlInt32 x) 
418                 {
419                         if (x.IsNull)
420                                 return Null;
421                         else
422                                 return new SqlString (x.Value.ToString ());
423                 }
424
425                 public static explicit operator SqlString (SqlInt64 x) 
426                 {
427                         if (x.IsNull)
428                                 return Null;
429                         else
430                                 return new SqlString (x.Value.ToString ());
431                 }
432
433                 public static explicit operator SqlString (SqlMoney x) 
434                 {
435                         if (x.IsNull)
436                                 return Null;
437                         else
438                                 return new SqlString (x.Value.ToString ());
439                 }
440
441                 public static explicit operator SqlString (SqlSingle x) 
442                 {
443                         if (x.IsNull)
444                                 return Null;
445                         else
446                                 return new SqlString (x.Value.ToString ());
447                 }
448
449                 public static explicit operator string (SqlString x) 
450                 {
451                         return x.Value;
452                 }
453
454                 public static implicit operator SqlString (string x) 
455                 {
456                         return new SqlString (x);
457                 }
458
459                 #endregion // Public Methods
460         }
461 }