OleDbConnection.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. //
  2. // System.Data.OleDb.OleDbConnection
  3. //
  4. // Authors:
  5. // Rodrigo Moya ([email protected])
  6. // Tim Coleman ([email protected])
  7. //
  8. // Copyright (C) Rodrigo Moya, 2002
  9. // Copyright (C) Tim Coleman, 2002
  10. //
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Data.Common;
  14. namespace System.Data.OleDb
  15. {
  16. public sealed class OleDbConnection : Component, ICloneable, IDbConnection
  17. {
  18. #region Fields
  19. string connectionString;
  20. int connectionTimeout;
  21. OleDbDataReader dataReader;
  22. bool dataReaderOpen;
  23. IntPtr gdaConnection;
  24. #endregion
  25. #region Constructors
  26. public OleDbConnection ()
  27. {
  28. gdaConnection = IntPtr.Zero;
  29. connectionTimeout = 15;
  30. }
  31. public OleDbConnection (string connectionString)
  32. : this ()
  33. {
  34. this.connectionString = connectionString;
  35. }
  36. #endregion // Constructors
  37. #region Properties
  38. public string ConnectionString {
  39. get { return connectionString; }
  40. set { connectionString = value; }
  41. }
  42. public int ConnectionTimeout {
  43. get { return connectionTimeout; }
  44. }
  45. public string Database {
  46. get {
  47. if (gdaConnection != IntPtr.Zero && libgda.gda_connection_is_open (gdaConnection)) {
  48. return libgda.gda_connection_get_database (gdaConnection);
  49. }
  50. return null;
  51. }
  52. }
  53. public string DataSource {
  54. [MonoTODO]
  55. get {
  56. throw new NotImplementedException ();
  57. }
  58. }
  59. public string Provider {
  60. get {
  61. if (gdaConnection != IntPtr.Zero && libgda.gda_connection_is_open (gdaConnection)) {
  62. return libgda.gda_connection_get_provider (gdaConnection);
  63. }
  64. return null;
  65. }
  66. }
  67. public string ServerVersion {
  68. [MonoTODO]
  69. get { throw new NotImplementedException (); }
  70. }
  71. public ConnectionState State
  72. {
  73. get {
  74. if (gdaConnection != IntPtr.Zero) {
  75. if (libgda.gda_connection_is_open (gdaConnection))
  76. return ConnectionState.Open;
  77. }
  78. return ConnectionState.Closed;
  79. }
  80. }
  81. internal IntPtr GdaConnection
  82. {
  83. get { return gdaConnection; }
  84. }
  85. #endregion // Properties
  86. #region Methods
  87. public OleDbTransaction BeginTransaction ()
  88. {
  89. if (gdaConnection != IntPtr.Zero)
  90. return new OleDbTransaction (this);
  91. return null;
  92. }
  93. public OleDbTransaction BeginTransaction (IsolationLevel level)
  94. {
  95. if (gdaConnection != IntPtr.Zero)
  96. return new OleDbTransaction (this, level);
  97. return null;
  98. }
  99. public void ChangeDatabase (string name)
  100. {
  101. // FIXME: see http://bugzilla.gnome.org/show_bug.cgi?id=83315
  102. }
  103. public void Close ()
  104. {
  105. if (gdaConnection != IntPtr.Zero) {
  106. libgda.gda_connection_close (gdaConnection);
  107. gdaConnection = IntPtr.Zero;
  108. }
  109. }
  110. public OleDbCommand CreateCommand ()
  111. {
  112. if (gdaConnection != IntPtr.Zero && libgda.gda_connection_is_open (gdaConnection))
  113. return new OleDbCommand ();
  114. return null;
  115. }
  116. [MonoTODO]
  117. protected override void Dispose (bool disposing)
  118. {
  119. throw new NotImplementedException ();
  120. }
  121. [MonoTODO]
  122. public DataTable GetOleDbSchemaTable (Guid schema, object[] restrictions)
  123. {
  124. throw new NotImplementedException ();
  125. }
  126. [MonoTODO]
  127. object ICloneable.Clone ()
  128. {
  129. throw new NotImplementedException();
  130. }
  131. [MonoTODO]
  132. IDbTransaction IDbConnection.BeginTransaction ()
  133. {
  134. throw new NotImplementedException ();
  135. }
  136. [MonoTODO]
  137. IDbTransaction IDbConnection.BeginTransaction (IsolationLevel level)
  138. {
  139. throw new NotImplementedException ();
  140. }
  141. [MonoTODO]
  142. IDbCommand IDbConnection.CreateCommand ()
  143. {
  144. throw new NotImplementedException ();
  145. }
  146. public void Open ()
  147. {
  148. if (gdaConnection != IntPtr.Zero || libgda.gda_connection_is_open (gdaConnection))
  149. throw new InvalidOperationException ();
  150. gdaConnection = libgda.gda_client_open_connection (libgda.GdaClient, connectionString, "", "");
  151. }
  152. [MonoTODO]
  153. public static void ReleaseObjectPool ()
  154. {
  155. throw new NotImplementedException ();
  156. }
  157. #endregion
  158. #region Internal Methods
  159. // Used to prevent OleDbConnection
  160. // from doing anything while
  161. // OleDbDataReader is open.
  162. // Open the Reader. (called from OleDbCommand)
  163. internal void OpenReader(OleDbDataReader reader)
  164. {
  165. if(dataReaderOpen == true) {
  166. // TODO: throw exception here?
  167. // because a reader
  168. // is already open
  169. }
  170. else {
  171. dataReader = reader;
  172. dataReaderOpen = true;
  173. }
  174. }
  175. #endregion
  176. #region Events and Delegates
  177. public event OleDbInfoMessageEventHandler InfoMessage;
  178. public event StateChangeEventHandler StateChange;
  179. #endregion
  180. }
  181. }