OleDbConnection.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. libgda.gda_init ("System.Data.OleDb", "1.0", 0, new string [0]);
  29. gdaConnection = IntPtr.Zero;
  30. connectionTimeout = 15;
  31. connectionString = null;
  32. }
  33. public OleDbConnection (string connectionString) : this ()
  34. {
  35. this.connectionString = connectionString;
  36. }
  37. #endregion // Constructors
  38. #region Properties
  39. public string ConnectionString {
  40. get {
  41. return connectionString;
  42. }
  43. set {
  44. connectionString = value;
  45. }
  46. }
  47. public int ConnectionTimeout {
  48. get {
  49. return connectionTimeout;
  50. }
  51. }
  52. public string Database {
  53. get {
  54. if (gdaConnection != IntPtr.Zero
  55. && libgda.gda_connection_is_open (gdaConnection)) {
  56. return libgda.gda_connection_get_database (gdaConnection);
  57. }
  58. return null;
  59. }
  60. }
  61. public string DataSource {
  62. get {
  63. if (gdaConnection != IntPtr.Zero
  64. && libgda.gda_connection_is_open (gdaConnection)) {
  65. return libgda.gda_connection_get_dsn (gdaConnection);
  66. }
  67. return null;
  68. }
  69. }
  70. public string Provider {
  71. get {
  72. if (gdaConnection != IntPtr.Zero
  73. && libgda.gda_connection_is_open (gdaConnection)) {
  74. return libgda.gda_connection_get_provider (gdaConnection);
  75. }
  76. return null;
  77. }
  78. }
  79. public string ServerVersion {
  80. get {
  81. if (gdaConnection != IntPtr.Zero
  82. && libgda.gda_connection_is_open (gdaConnection)) {
  83. return libgda.gda_connection_get_server_version (gdaConnection);
  84. }
  85. return null;
  86. }
  87. }
  88. public ConnectionState State
  89. {
  90. get {
  91. if (gdaConnection != IntPtr.Zero) {
  92. if (libgda.gda_connection_is_open (gdaConnection))
  93. return ConnectionState.Open;
  94. }
  95. return ConnectionState.Closed;
  96. }
  97. }
  98. internal IntPtr GdaConnection
  99. {
  100. get {
  101. return gdaConnection;
  102. }
  103. }
  104. #endregion // Properties
  105. #region Methods
  106. public OleDbTransaction BeginTransaction ()
  107. {
  108. if (gdaConnection != IntPtr.Zero)
  109. return new OleDbTransaction (this);
  110. return null;
  111. }
  112. IDbTransaction IDbConnection.BeginTransaction ()
  113. {
  114. return BeginTransaction ();
  115. }
  116. public OleDbTransaction BeginTransaction (IsolationLevel level)
  117. {
  118. if (gdaConnection != IntPtr.Zero)
  119. return new OleDbTransaction (this, level);
  120. return null;
  121. }
  122. IDbTransaction IDbConnection.BeginTransaction (IsolationLevel level)
  123. {
  124. return BeginTransaction (level);
  125. }
  126. public void ChangeDatabase (string name)
  127. {
  128. // FIXME: see http://bugzilla.gnome.org/show_bug.cgi?id=83315
  129. }
  130. public void Close ()
  131. {
  132. if (gdaConnection != IntPtr.Zero) {
  133. libgda.gda_connection_close (gdaConnection);
  134. gdaConnection = IntPtr.Zero;
  135. }
  136. }
  137. public OleDbCommand CreateCommand ()
  138. {
  139. if (gdaConnection != IntPtr.Zero
  140. && libgda.gda_connection_is_open (gdaConnection))
  141. return new OleDbCommand (null, this);
  142. return null;
  143. }
  144. [MonoTODO]
  145. protected override void Dispose (bool disposing)
  146. {
  147. throw new NotImplementedException ();
  148. }
  149. [MonoTODO]
  150. public DataTable GetOleDbSchemaTable (Guid schema, object[] restrictions)
  151. {
  152. throw new NotImplementedException ();
  153. }
  154. [MonoTODO]
  155. object ICloneable.Clone ()
  156. {
  157. throw new NotImplementedException();
  158. }
  159. IDbCommand IDbConnection.CreateCommand ()
  160. {
  161. return CreateCommand ();
  162. }
  163. public void Open ()
  164. {
  165. if (State == ConnectionState.Open)
  166. throw new InvalidOperationException ();
  167. gdaConnection = libgda.gda_client_open_connection (libgda.GdaClient,
  168. connectionString,
  169. "", "");
  170. }
  171. [MonoTODO]
  172. public static void ReleaseObjectPool ()
  173. {
  174. throw new NotImplementedException ();
  175. }
  176. #endregion
  177. #region Events and Delegates
  178. public event OleDbInfoMessageEventHandler InfoMessage;
  179. public event StateChangeEventHandler StateChange;
  180. #endregion
  181. }
  182. }