/Languages/IronPython/IronPython.SQLite/Row.cs

http://github.com/IronLanguages/main · C# · 106 lines · 74 code · 18 blank · 14 comment · 8 complexity · 33255b0437a079905b02e0e7c58ef4bc MD5 · raw file

  1. /* ****************************************************************************
  2. *
  3. * Copyright (c) Jeff Hardy 2010-2012.
  4. *
  5. * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
  6. * copy of the license can be found in the License.html file at the root of this distribution. If
  7. * you cannot locate the Apache License, Version 2.0, please send an email to
  8. * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
  9. * by the terms of the Apache License, Version 2.0.
  10. *
  11. * You must not remove this notice, or any other, from this software.
  12. *
  13. *
  14. * ***************************************************************************/
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Globalization;
  18. using System.Linq;
  19. using System.Text;
  20. using IronPython.Runtime;
  21. using System.Collections;
  22. using IronPython.Runtime.Exceptions;
  23. namespace IronPython.SQLite
  24. {
  25. public static partial class PythonSQLite
  26. {
  27. [PythonType]
  28. public class Row : IEnumerable
  29. {
  30. PythonTuple data;
  31. PythonTuple description;
  32. public Row(Cursor cursor, PythonTuple data)
  33. {
  34. this.data = data;
  35. this.description = cursor.description;
  36. }
  37. public override bool Equals(object obj)
  38. {
  39. Row other = obj as Row;
  40. if(other == null)
  41. return false;
  42. if(object.ReferenceEquals(this, other))
  43. return true;
  44. return this.description.Equals(other.description) && this.data.Equals(other.data);
  45. }
  46. public override int GetHashCode()
  47. {
  48. return description.GetHashCode() ^ data.GetHashCode();
  49. }
  50. public object __iter__()
  51. {
  52. return data;
  53. }
  54. public object this[long i]
  55. {
  56. get { return this.data[i]; }
  57. }
  58. public object this[string s]
  59. {
  60. get
  61. {
  62. for(int i = 0; i < data.Count; ++i)
  63. {
  64. PythonTuple col_desc = (PythonTuple)description[i];
  65. if(CultureInfo.InvariantCulture.CompareInfo.Compare(s, (string)col_desc[0], CompareOptions.IgnoreCase) == 0)
  66. return data[i];
  67. }
  68. throw CreateThrowable(PythonExceptions.IndexError, "No item with that key");
  69. }
  70. }
  71. public List keys()
  72. {
  73. List list = new List();
  74. for(int i = 0; i < data.Count; ++i)
  75. {
  76. list.append(((PythonTuple)description[i])[0]);
  77. }
  78. return list;
  79. }
  80. #region IEnumerable Members
  81. public IEnumerator GetEnumerator()
  82. {
  83. return data.GetEnumerator();
  84. }
  85. #endregion
  86. }
  87. }
  88. }