Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SqlString.cs
Go to the documentation of this file.
5using System.Text;
6using System.Xml;
9
10namespace System.Data.SqlTypes;
11
13[XmlSchemaProvider("GetXsdType")]
14[TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
16{
17 private string m_value;
18
20
21 private readonly int m_lcid;
22
23 private readonly SqlCompareOptions m_flag;
24
25 private bool m_fNotNull;
26
27 public static readonly SqlString Null = new SqlString(fNull: true);
28
29 internal static readonly UnicodeEncoding s_unicodeEncoding = new UnicodeEncoding();
30
31 public static readonly int IgnoreCase = 1;
32
33 public static readonly int IgnoreWidth = 16;
34
35 public static readonly int IgnoreNonSpace = 2;
36
37 public static readonly int IgnoreKanaType = 8;
38
39 public static readonly int BinarySort = 32768;
40
41 public static readonly int BinarySort2 = 16384;
42
43 public bool IsNull => !m_fNotNull;
44
45 public string Value
46 {
47 get
48 {
49 if (!IsNull)
50 {
51 return m_value;
52 }
53 throw new SqlNullValueException();
54 }
55 }
56
57 public int LCID
58 {
59 get
60 {
61 if (!IsNull)
62 {
63 return m_lcid;
64 }
65 throw new SqlNullValueException();
66 }
67 }
68
70 {
71 get
72 {
73 if (!IsNull)
74 {
76 }
77 throw new SqlNullValueException();
78 }
79 }
80
82 {
83 get
84 {
85 if (!IsNull)
86 {
88 return m_cmpInfo;
89 }
90 throw new SqlNullValueException();
91 }
92 }
93
95 {
96 get
97 {
98 if (!IsNull)
99 {
100 return m_flag;
101 }
102 throw new SqlNullValueException();
103 }
104 }
105
106 private SqlString(bool fNull)
107 {
108 m_value = null;
109 m_cmpInfo = null;
110 m_lcid = 0;
112 m_fNotNull = false;
113 }
114
115 public SqlString(int lcid, SqlCompareOptions compareOptions, byte[]? data, int index, int count, bool fUnicode)
116 {
117 m_lcid = lcid;
120 if (data == null)
121 {
122 m_fNotNull = false;
123 m_value = null;
124 m_cmpInfo = null;
125 return;
126 }
127 m_fNotNull = true;
128 m_cmpInfo = null;
129 if (fUnicode)
130 {
131 m_value = s_unicodeEncoding.GetString(data, index, count);
132 return;
133 }
135 Encoding encoding = Encoding.GetEncoding(cultureInfo.TextInfo.ANSICodePage);
136 m_value = encoding.GetString(data, index, count);
137 }
138
139 public SqlString(int lcid, SqlCompareOptions compareOptions, byte[] data, bool fUnicode)
140 : this(lcid, compareOptions, data, 0, data.Length, fUnicode)
141 {
142 }
143
144 public SqlString(int lcid, SqlCompareOptions compareOptions, byte[]? data, int index, int count)
145 : this(lcid, compareOptions, data, index, count, fUnicode: true)
146 {
147 }
148
149 public SqlString(int lcid, SqlCompareOptions compareOptions, byte[] data)
150 : this(lcid, compareOptions, data, 0, data.Length, fUnicode: true)
151 {
152 }
153
154 public SqlString(string? data, int lcid, SqlCompareOptions compareOptions)
155 {
156 m_lcid = lcid;
159 m_cmpInfo = null;
160 if (data == null)
161 {
162 m_fNotNull = false;
163 m_value = null;
164 }
165 else
166 {
167 m_fNotNull = true;
168 m_value = data;
169 }
170 }
171
172 public SqlString(string? data, int lcid)
174 {
175 }
176
181
183 {
184 m_lcid = lcid;
187 if (data == null)
188 {
189 m_fNotNull = false;
190 m_value = null;
191 m_cmpInfo = null;
192 }
193 else
194 {
195 m_value = data;
197 m_fNotNull = true;
198 }
199 }
200
201 private void SetCompareInfo()
202 {
203 if (m_cmpInfo == null)
204 {
206 }
207 }
208
209 public static implicit operator SqlString(string x)
210 {
211 return new SqlString(x);
212 }
213
214 public static explicit operator string(SqlString x)
215 {
216 return x.Value;
217 }
218
219 public override string ToString()
220 {
221 if (!IsNull)
222 {
223 return m_value;
224 }
225 return SQLResource.NullString;
226 }
227
228 public byte[]? GetUnicodeBytes()
229 {
230 if (IsNull)
231 {
232 return null;
233 }
234 return s_unicodeEncoding.GetBytes(m_value);
235 }
236
237 public byte[]? GetNonUnicodeBytes()
238 {
239 if (IsNull)
240 {
241 return null;
242 }
244 Encoding encoding = Encoding.GetEncoding(cultureInfo.TextInfo.ANSICodePage);
245 return encoding.GetBytes(m_value);
246 }
247
249 {
250 if (x.IsNull || y.IsNull)
251 {
252 return Null;
253 }
254 if (x.m_lcid != y.m_lcid || x.m_flag != y.m_flag)
255 {
257 }
258 return new SqlString(x.m_lcid, x.m_flag, x.m_value + y.m_value, (x.m_cmpInfo == null) ? y.m_cmpInfo : x.m_cmpInfo);
259 }
260
261 private static int StringCompare(SqlString x, SqlString y)
262 {
263 if (x.m_lcid != y.m_lcid || x.m_flag != y.m_flag)
264 {
266 }
267 x.SetCompareInfo();
268 y.SetCompareInfo();
269 if ((x.m_flag & SqlCompareOptions.BinarySort) != 0)
270 {
271 return CompareBinary(x, y);
272 }
273 if ((x.m_flag & SqlCompareOptions.BinarySort2) != 0)
274 {
275 return CompareBinary2(x, y);
276 }
277 string value = x.m_value;
278 string value2 = y.m_value;
279 int num = value.Length;
280 int num2 = value2.Length;
281 while (num > 0 && value[num - 1] == ' ')
282 {
283 num--;
284 }
285 while (num2 > 0 && value2[num2 - 1] == ' ')
286 {
287 num2--;
288 }
290 return x.m_cmpInfo.Compare(x.m_value, 0, num, y.m_value, 0, num2, options);
291 }
292
294 {
295 if (x.IsNull || y.IsNull)
296 {
297 return SqlBoolean.Null;
298 }
299 int num = StringCompare(x, y);
300 bool flag = false;
301 switch (ecExpectedResult)
302 {
303 case EComparison.EQ:
304 flag = num == 0;
305 break;
306 case EComparison.LT:
307 flag = num < 0;
308 break;
309 case EComparison.LE:
310 flag = num <= 0;
311 break;
312 case EComparison.GT:
313 flag = num > 0;
314 break;
315 case EComparison.GE:
316 flag = num >= 0;
317 break;
318 default:
319 return SqlBoolean.Null;
320 }
321 return new SqlBoolean(flag);
322 }
323
324 public static explicit operator SqlString(SqlBoolean x)
325 {
326 if (!x.IsNull)
327 {
328 return new SqlString(x.Value.ToString());
329 }
330 return Null;
331 }
332
333 public static explicit operator SqlString(SqlByte x)
334 {
335 if (!x.IsNull)
336 {
337 return new SqlString(x.Value.ToString((IFormatProvider?)null));
338 }
339 return Null;
340 }
341
342 public static explicit operator SqlString(SqlInt16 x)
343 {
344 if (!x.IsNull)
345 {
346 return new SqlString(x.Value.ToString((IFormatProvider?)null));
347 }
348 return Null;
349 }
350
351 public static explicit operator SqlString(SqlInt32 x)
352 {
353 if (!x.IsNull)
354 {
355 return new SqlString(x.Value.ToString((IFormatProvider?)null));
356 }
357 return Null;
358 }
359
360 public static explicit operator SqlString(SqlInt64 x)
361 {
362 if (!x.IsNull)
363 {
364 return new SqlString(x.Value.ToString((IFormatProvider?)null));
365 }
366 return Null;
367 }
368
369 public static explicit operator SqlString(SqlSingle x)
370 {
371 if (!x.IsNull)
372 {
373 return new SqlString(x.Value.ToString((IFormatProvider?)null));
374 }
375 return Null;
376 }
377
378 public static explicit operator SqlString(SqlDouble x)
379 {
380 if (!x.IsNull)
381 {
382 return new SqlString(x.Value.ToString((IFormatProvider?)null));
383 }
384 return Null;
385 }
386
387 public static explicit operator SqlString(SqlDecimal x)
388 {
389 if (!x.IsNull)
390 {
391 return new SqlString(x.ToString());
392 }
393 return Null;
394 }
395
396 public static explicit operator SqlString(SqlMoney x)
397 {
398 if (!x.IsNull)
399 {
400 return new SqlString(x.ToString());
401 }
402 return Null;
403 }
404
405 public static explicit operator SqlString(SqlDateTime x)
406 {
407 if (!x.IsNull)
408 {
409 return new SqlString(x.ToString());
410 }
411 return Null;
412 }
413
414 public static explicit operator SqlString(SqlGuid x)
415 {
416 if (!x.IsNull)
417 {
418 return new SqlString(x.ToString());
419 }
420 return Null;
421 }
422
424 {
425 if (IsNull)
426 {
427 return new SqlString(fNull: true);
428 }
429 return new SqlString(m_value, m_lcid, m_flag);
430 }
431
433 {
434 return Compare(x, y, EComparison.EQ);
435 }
436
438 {
439 return !(x == y);
440 }
441
443 {
444 return Compare(x, y, EComparison.LT);
445 }
446
448 {
449 return Compare(x, y, EComparison.GT);
450 }
451
453 {
454 return Compare(x, y, EComparison.LE);
455 }
456
458 {
459 return Compare(x, y, EComparison.GE);
460 }
461
463 {
464 return x + y;
465 }
466
467 public static SqlString Add(SqlString x, SqlString y)
468 {
469 return x + y;
470 }
471
473 {
474 return x == y;
475 }
476
478 {
479 return x != y;
480 }
481
483 {
484 return x < y;
485 }
486
488 {
489 return x > y;
490 }
491
493 {
494 return x <= y;
495 }
496
498 {
499 return x >= y;
500 }
501
503 {
504 return (SqlBoolean)this;
505 }
506
508 {
509 return (SqlByte)this;
510 }
511
513 {
514 return (SqlDateTime)this;
515 }
516
518 {
519 return (SqlDouble)this;
520 }
521
523 {
524 return (SqlInt16)this;
525 }
526
528 {
529 return (SqlInt32)this;
530 }
531
533 {
534 return (SqlInt64)this;
535 }
536
538 {
539 return (SqlMoney)this;
540 }
541
543 {
544 return (SqlDecimal)this;
545 }
546
548 {
549 return (SqlSingle)this;
550 }
551
553 {
554 return (SqlGuid)this;
555 }
556
558 {
559 if ((compareOptions & (SqlCompareOptions.IgnoreCase | SqlCompareOptions.IgnoreNonSpace | SqlCompareOptions.IgnoreKanaType | SqlCompareOptions.IgnoreWidth | SqlCompareOptions.BinarySort | SqlCompareOptions.BinarySort2)) != compareOptions)
560 {
561 throw new ArgumentOutOfRangeException("compareOptions");
562 }
563 }
564
566 {
569 if ((compareOptions & (SqlCompareOptions.BinarySort | SqlCompareOptions.BinarySort2)) != 0)
570 {
571 throw ADP.ArgumentOutOfRange("compareOptions");
572 }
573 if ((compareOptions & SqlCompareOptions.IgnoreCase) != 0)
574 {
575 compareOptions2 |= CompareOptions.IgnoreCase;
576 }
577 if ((compareOptions & SqlCompareOptions.IgnoreNonSpace) != 0)
578 {
579 compareOptions2 |= CompareOptions.IgnoreNonSpace;
580 }
581 if ((compareOptions & SqlCompareOptions.IgnoreKanaType) != 0)
582 {
583 compareOptions2 |= CompareOptions.IgnoreKanaType;
584 }
585 if ((compareOptions & SqlCompareOptions.IgnoreWidth) != 0)
586 {
587 compareOptions2 |= CompareOptions.IgnoreWidth;
588 }
589 return compareOptions2;
590 }
591
592 private bool FBinarySort()
593 {
594 if (!IsNull)
595 {
596 return (m_flag & (SqlCompareOptions.BinarySort | SqlCompareOptions.BinarySort2)) != 0;
597 }
598 return false;
599 }
600
601 private static int CompareBinary(SqlString x, SqlString y)
602 {
603 byte[] bytes = s_unicodeEncoding.GetBytes(x.m_value);
604 byte[] bytes2 = s_unicodeEncoding.GetBytes(y.m_value);
605 int num = bytes.Length;
606 int num2 = bytes2.Length;
607 int num3 = ((num < num2) ? num : num2);
608 int i;
609 for (i = 0; i < num3; i++)
610 {
611 if (bytes[i] < bytes2[i])
612 {
613 return -1;
614 }
615 if (bytes[i] > bytes2[i])
616 {
617 return 1;
618 }
619 }
620 i = num3;
621 int num4 = 32;
622 if (num < num2)
623 {
624 for (; i < num2; i += 2)
625 {
626 int num5 = bytes2[i + 1] << 8 + bytes2[i];
627 if (num5 != num4)
628 {
629 if (num4 <= num5)
630 {
631 return -1;
632 }
633 return 1;
634 }
635 }
636 }
637 else
638 {
639 for (; i < num; i += 2)
640 {
641 int num5 = bytes[i + 1] << 8 + bytes[i];
642 if (num5 != num4)
643 {
644 if (num5 <= num4)
645 {
646 return -1;
647 }
648 return 1;
649 }
650 }
651 }
652 return 0;
653 }
654
655 private static int CompareBinary2(SqlString x, SqlString y)
656 {
657 string value = x.m_value;
658 string value2 = y.m_value;
659 int length = value.Length;
660 int length2 = value2.Length;
661 int num = ((length < length2) ? length : length2);
662 for (int i = 0; i < num; i++)
663 {
664 if (value[i] < value2[i])
665 {
666 return -1;
667 }
668 if (value[i] > value2[i])
669 {
670 return 1;
671 }
672 }
673 char c = ' ';
674 if (length < length2)
675 {
676 for (int i = num; i < length2; i++)
677 {
678 if (value2[i] != c)
679 {
680 if (c <= value2[i])
681 {
682 return -1;
683 }
684 return 1;
685 }
686 }
687 }
688 else
689 {
690 for (int i = num; i < length; i++)
691 {
692 if (value[i] != c)
693 {
694 if (value[i] <= c)
695 {
696 return -1;
697 }
698 return 1;
699 }
700 }
701 }
702 return 0;
703 }
704
705 public int CompareTo(object? value)
706 {
708 {
709 return CompareTo(value2);
710 }
711 throw ADP.WrongType(value.GetType(), typeof(SqlString));
712 }
713
715 {
716 if (IsNull)
717 {
718 if (!value.IsNull)
719 {
720 return -1;
721 }
722 return 0;
723 }
724 if (value.IsNull)
725 {
726 return 1;
727 }
728 int num = StringCompare(this, value);
729 if (num < 0)
730 {
731 return -1;
732 }
733 if (num > 0)
734 {
735 return 1;
736 }
737 return 0;
738 }
739
740 public override bool Equals([NotNullWhen(true)] object? value)
741 {
743 {
744 return false;
745 }
746 if (sqlString.IsNull || IsNull)
747 {
748 if (sqlString.IsNull)
749 {
750 return IsNull;
751 }
752 return false;
753 }
754 return (this == sqlString).Value;
755 }
756
757 public override int GetHashCode()
758 {
759 if (IsNull)
760 {
761 return 0;
762 }
763 byte[] array;
764 if (FBinarySort())
765 {
766 array = s_unicodeEncoding.GetBytes(m_value.TrimEnd());
767 }
768 else
769 {
772 try
773 {
777 }
778 catch (ArgumentException)
779 {
781 options = CompareOptions.None;
782 }
783 array = compareInfo.GetSortKey(m_value.TrimEnd(), options).KeyData;
784 }
785 return SqlBinary.HashByteArray(array, array.Length);
786 }
787
789 {
790 return null;
791 }
792
794 {
795 string attribute = reader.GetAttribute("nil", "http://www.w3.org/2001/XMLSchema-instance");
796 if (attribute != null && XmlConvert.ToBoolean(attribute))
797 {
798 reader.ReadElementString();
799 m_fNotNull = false;
800 }
801 else
802 {
803 m_value = reader.ReadElementString();
804 m_fNotNull = true;
805 }
806 }
807
809 {
810 if (IsNull)
811 {
812 writer.WriteAttributeString("xsi", "nil", "http://www.w3.org/2001/XMLSchema-instance", "true");
813 }
814 else
815 {
816 writer.WriteString(m_value);
817 }
818 }
819
821 {
822 return new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
823 }
824}
static ArgumentOutOfRangeException ArgumentOutOfRange(string parameterName)
Definition ADP.cs:713
static Exception WrongType(Type got, Type expected)
Definition ADP.cs:174
static string CompareDiffCollationMessage
static string ConcatDiffCollationMessage
int Compare(string? string1, string? string2)
static CultureInfo InvariantCulture
static CultureInfo GetCultureInfo(int culture)
static Encoding GetEncoding(int codepage)
Definition Encoding.cs:593
virtual byte[] GetBytes(char[] chars)
Definition Encoding.cs:781
unsafe string GetString(byte *bytes, int byteCount)
Definition Encoding.cs:973
static bool ToBoolean(string s)
string? GetAttribute(string name)
virtual string ReadElementString()
Definition XmlReader.cs:667
static int HashByteArray(byte[] rgbValue, int length)
Definition SqlBinary.cs:302
static readonly SqlBoolean Null
Definition SqlBoolean.cs:21
override string ToString()
Definition SqlGuid.cs:86
override string ToString()
Definition SqlMoney.cs:153
SqlString(int lcid, SqlCompareOptions compareOptions, byte[] data, bool fUnicode)
Definition SqlString.cs:139
static SqlBoolean NotEquals(SqlString x, SqlString y)
Definition SqlString.cs:477
static SqlBoolean GreaterThanOrEqual(SqlString x, SqlString y)
Definition SqlString.cs:497
readonly SqlCompareOptions m_flag
Definition SqlString.cs:23
SqlString(int lcid, SqlCompareOptions compareOptions, byte[]? data, int index, int count)
Definition SqlString.cs:144
int CompareTo(object? value)
Definition SqlString.cs:705
static SqlBoolean GreaterThan(SqlString x, SqlString y)
Definition SqlString.cs:487
static SqlString operator+(SqlString x, SqlString y)
Definition SqlString.cs:248
static readonly int IgnoreWidth
Definition SqlString.cs:33
static SqlBoolean operator<=(SqlString x, SqlString y)
Definition SqlString.cs:452
override bool Equals([NotNullWhen(true)] object? value)
Definition SqlString.cs:740
static readonly SqlString Null
Definition SqlString.cs:27
static readonly int IgnoreKanaType
Definition SqlString.cs:37
static readonly int BinarySort2
Definition SqlString.cs:41
static readonly int IgnoreNonSpace
Definition SqlString.cs:35
static void ValidateSqlCompareOptions(SqlCompareOptions compareOptions)
Definition SqlString.cs:557
static SqlBoolean LessThan(SqlString x, SqlString y)
Definition SqlString.cs:482
static CompareOptions CompareOptionsFromSqlCompareOptions(SqlCompareOptions compareOptions)
Definition SqlString.cs:565
static SqlBoolean operator>=(SqlString x, SqlString y)
Definition SqlString.cs:457
SqlString(int lcid, SqlCompareOptions compareOptions, string data, CompareInfo cmpInfo)
Definition SqlString.cs:182
static SqlString Add(SqlString x, SqlString y)
Definition SqlString.cs:467
static int StringCompare(SqlString x, SqlString y)
Definition SqlString.cs:261
static SqlBoolean operator<(SqlString x, SqlString y)
Definition SqlString.cs:442
static SqlBoolean operator!=(SqlString x, SqlString y)
Definition SqlString.cs:437
int CompareTo(SqlString value)
Definition SqlString.cs:714
static SqlString Concat(SqlString x, SqlString y)
Definition SqlString.cs:462
static readonly UnicodeEncoding s_unicodeEncoding
Definition SqlString.cs:29
SqlString(int lcid, SqlCompareOptions compareOptions, byte[] data)
Definition SqlString.cs:149
static readonly int IgnoreCase
Definition SqlString.cs:31
SqlString(string? data, int lcid, SqlCompareOptions compareOptions)
Definition SqlString.cs:154
static SqlBoolean operator==(SqlString x, SqlString y)
Definition SqlString.cs:432
static int CompareBinary(SqlString x, SqlString y)
Definition SqlString.cs:601
override string ToString()
Definition SqlString.cs:219
static XmlQualifiedName GetXsdType(XmlSchemaSet schemaSet)
Definition SqlString.cs:820
static SqlBoolean Compare(SqlString x, SqlString y, EComparison ecExpectedResult)
Definition SqlString.cs:293
static readonly int BinarySort
Definition SqlString.cs:39
SqlString(string? data, int lcid)
Definition SqlString.cs:172
SqlString(int lcid, SqlCompareOptions compareOptions, byte[]? data, int index, int count, bool fUnicode)
Definition SqlString.cs:115
static SqlBoolean Equals(SqlString x, SqlString y)
Definition SqlString.cs:472
static SqlBoolean operator>(SqlString x, SqlString y)
Definition SqlString.cs:447
static int CompareBinary2(SqlString x, SqlString y)
Definition SqlString.cs:655
static SqlBoolean LessThanOrEqual(SqlString x, SqlString y)
Definition SqlString.cs:492