2 // System.Data.SqlTypes.SqlInt64
5 // Tim Coleman <tim@timcoleman.com>
6 // Ville Palo <vi64pa@koti.soon.fi>
8 // (C) Copyright 2002 Tim Coleman
12 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
14 // Permission is hereby granted, free of charge, to any person obtaining
15 // a copy of this software and associated documentation files (the
16 // "Software"), to deal in the Software without restriction, including
17 // without limitation the rights to use, copy, modify, merge, publish,
18 // distribute, sublicense, and/or sell copies of the Software, and to
19 // permit persons to whom the Software is furnished to do so, subject to
20 // the following conditions:
22 // The above copyright notice and this permission notice shall be
23 // included in all copies or substantial portions of the Software.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.Globalization;
37 namespace System.Data.SqlTypes
39 public struct SqlInt64 : INullable, IComparable
47 public static readonly SqlInt64 MaxValue = new SqlInt64 (9223372036854775807);
48 public static readonly SqlInt64 MinValue = new SqlInt64 (-9223372036854775808);
50 public static readonly SqlInt64 Null;
51 public static readonly SqlInt64 Zero = new SqlInt64 (0);
57 public SqlInt64 (long value)
68 get { return !notNull; }
74 throw new SqlNullValueException ();
84 public static SqlInt64 Add (SqlInt64 x, SqlInt64 y)
89 public static SqlInt64 BitwiseAnd (SqlInt64 x, SqlInt64 y)
94 public static SqlInt64 BitwiseOr (SqlInt64 x, SqlInt64 y)
99 public int CompareTo (object value)
103 else if (!(value is SqlInt64))
104 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SqlTypes.SqlInt64"));
105 return CompareSqlInt64 ((SqlInt64) value);
109 public int CompareTo (SqlInt64 value)
111 return CompareSqlInt64 ((SqlInt64) value);
115 private int CompareSqlInt64 (SqlInt64 value)
120 return this.value.CompareTo (value.Value);
123 public static SqlInt64 Divide (SqlInt64 x, SqlInt64 y)
128 public override bool Equals (object value)
130 if (!(value is SqlInt64))
132 else if (this.IsNull && ((SqlInt64)value).IsNull)
134 else if (((SqlInt64)value).IsNull)
137 return (bool) (this == (SqlInt64)value);
140 public static SqlBoolean Equals (SqlInt64 x, SqlInt64 y)
145 public override int GetHashCode ()
147 return (int)(value & 0xffffffff) ^ (int)(value >> 32);
150 public static SqlBoolean GreaterThan (SqlInt64 x, SqlInt64 y)
155 public static SqlBoolean GreaterThanOrEqual (SqlInt64 x, SqlInt64 y)
160 public static SqlBoolean LessThan (SqlInt64 x, SqlInt64 y)
165 public static SqlBoolean LessThanOrEqual (SqlInt64 x, SqlInt64 y)
170 public static SqlInt64 Mod (SqlInt64 x, SqlInt64 y)
176 public static SqlInt64 Modulus (SqlInt64 x, SqlInt64 y)
182 public static SqlInt64 Multiply (SqlInt64 x, SqlInt64 y)
187 public static SqlBoolean NotEquals (SqlInt64 x, SqlInt64 y)
192 public static SqlInt64 OnesComplement (SqlInt64 x)
201 public static SqlInt64 Parse (string s)
204 return new SqlInt64 (Int64.Parse (s));
208 public static SqlInt64 Subtract (SqlInt64 x, SqlInt64 y)
213 public SqlBoolean ToSqlBoolean ()
215 return ((SqlBoolean)this);
218 public SqlByte ToSqlByte ()
220 return ((SqlByte)this);
223 public SqlDecimal ToSqlDecimal ()
225 return ((SqlDecimal)this);
228 public SqlDouble ToSqlDouble ()
230 return ((SqlDouble)this);
233 public SqlInt16 ToSqlInt16 ()
235 return ((SqlInt16)this);
238 public SqlInt32 ToSqlInt32 ()
240 return ((SqlInt32)this);
243 public SqlMoney ToSqlMoney ()
245 return ((SqlMoney)this);
248 public SqlSingle ToSqlSingle ()
250 return ((SqlSingle)this);
253 public SqlString ToSqlString ()
255 return ((SqlString)this);
258 public override string ToString ()
263 return value.ToString ();
266 public static SqlInt64 Xor (SqlInt64 x, SqlInt64 y)
271 public static SqlInt64 operator + (SqlInt64 x, SqlInt64 y)
274 return new SqlInt64 (x.Value + y.Value);
278 public static SqlInt64 operator & (SqlInt64 x, SqlInt64 y)
280 return new SqlInt64 (x.value & y.Value);
283 public static SqlInt64 operator | (SqlInt64 x, SqlInt64 y)
285 return new SqlInt64 (x.value | y.Value);
288 public static SqlInt64 operator / (SqlInt64 x, SqlInt64 y)
291 return new SqlInt64 (x.Value / y.Value);
295 public static SqlBoolean operator == (SqlInt64 x, SqlInt64 y)
297 if (x.IsNull || y.IsNull)
298 return SqlBoolean.Null;
300 return new SqlBoolean (x.Value == y.Value);
303 public static SqlInt64 operator ^ (SqlInt64 x, SqlInt64 y)
305 return new SqlInt64 (x.Value ^ y.Value);
308 public static SqlBoolean operator > (SqlInt64 x, SqlInt64 y)
310 if (x.IsNull || y.IsNull)
311 return SqlBoolean.Null;
313 return new SqlBoolean (x.Value > y.Value);
316 public static SqlBoolean operator >= (SqlInt64 x, SqlInt64 y)
318 if (x.IsNull || y.IsNull)
319 return SqlBoolean.Null;
321 return new SqlBoolean (x.Value >= y.Value);
324 public static SqlBoolean operator != (SqlInt64 x, SqlInt64 y)
326 if (x.IsNull || y.IsNull)
327 return SqlBoolean.Null;
329 return new SqlBoolean (!(x.Value == y.Value));
332 public static SqlBoolean operator < (SqlInt64 x, SqlInt64 y)
334 if (x.IsNull || y.IsNull)
335 return SqlBoolean.Null;
337 return new SqlBoolean (x.Value < y.Value);
340 public static SqlBoolean operator <= (SqlInt64 x, SqlInt64 y)
342 if (x.IsNull || y.IsNull)
343 return SqlBoolean.Null;
345 return new SqlBoolean (x.Value <= y.Value);
348 public static SqlInt64 operator % (SqlInt64 x, SqlInt64 y)
350 return new SqlInt64(x.Value % y.Value);
353 public static SqlInt64 operator * (SqlInt64 x, SqlInt64 y)
356 return new SqlInt64 (x.Value * y.Value);
360 public static SqlInt64 operator ~ (SqlInt64 x)
363 return SqlInt64.Null;
365 return new SqlInt64 (~(x.Value));
368 public static SqlInt64 operator - (SqlInt64 x, SqlInt64 y)
371 return new SqlInt64 (x.Value - y.Value);
375 public static SqlInt64 operator - (SqlInt64 n)
377 return new SqlInt64 (-(n.Value));
380 public static explicit operator SqlInt64 (SqlBoolean x)
383 return SqlInt64.Null;
385 return new SqlInt64 ((long)x.ByteValue);
388 public static explicit operator SqlInt64 (SqlDecimal x)
392 return SqlInt64.Null;
394 return new SqlInt64 ((long)x.Value);
398 public static explicit operator SqlInt64 (SqlDouble x)
401 return SqlInt64.Null;
404 return new SqlInt64 ((long)x.Value);
409 public static explicit operator long (SqlInt64 x)
414 public static explicit operator SqlInt64 (SqlMoney x)
418 return SqlInt64.Null;
420 return new SqlInt64 ((long) Math.Round (x.Value));
424 public static explicit operator SqlInt64 (SqlSingle x)
427 return SqlInt64.Null;
430 return new SqlInt64 ((long)x.Value);
435 public static explicit operator SqlInt64 (SqlString x)
438 return SqlInt64.Parse (x.Value);
442 public static implicit operator SqlInt64 (long x)
444 return new SqlInt64 (x);
447 public static implicit operator SqlInt64 (SqlByte x)
450 return SqlInt64.Null;
452 return new SqlInt64 ((long)x.Value);
455 public static implicit operator SqlInt64 (SqlInt16 x)
458 return SqlInt64.Null;
460 return new SqlInt64 ((long)x.Value);
463 public static implicit operator SqlInt64 (SqlInt32 x)
466 return SqlInt64.Null;
468 return new SqlInt64 ((long)x.Value);