OleDbConnection.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. if (gdaConnection == IntPtr.Zero)
  129. throw new ArgumentException ();
  130. if (State != ConnectionState.Open)
  131. throw new InvalidOperationException ();
  132. if (!libgda.gda_connection_change_database (gdaConnection, name))
  133. throw new OleDbException (this);
  134. }
  135. public void Close ()
  136. {
  137. if (gdaConnection != IntPtr.Zero) {
  138. libgda.gda_connection_close (gdaConnection);
  139. gdaConnection = IntPtr.Zero;
  140. }
  141. }
  142. public OleDbCommand CreateCommand ()
  143. {
  144. if (gdaConnection != IntPtr.Zero
  145. && libgda.gda_connection_is_open (gdaConnection))
  146. return new OleDbCommand (null, this);
  147. return null;
  148. }
  149. [MonoTODO]
  150. protected override void Dispose (bool disposing)
  151. {
  152. throw new NotImplementedException ();
  153. }
  154. [MonoTODO]
  155. public DataTable GetOleDbSchemaTable (Guid schema, object[] restrictions)
  156. {
  157. throw new NotImplementedException ();
  158. }
  159. [MonoTODO]
  160. object ICloneable.Clone ()
  161. {
  162. throw new NotImplementedException();
  163. }
  164. IDbCommand IDbConnection.CreateCommand ()
  165. {
  166. return CreateCommand ();
  167. }
  168. public void Open ()
  169. {
  170. if (State == ConnectionState.Open)
  171. throw new InvalidOperationException ();
  172. gdaConnection = libgda.gda_client_open_connection (libgda.GdaClient,
  173. connectionString,
  174. "", "");
  175. }
  176. [MonoTODO]
  177. public static void ReleaseObjectPool ()
  178. {
  179. throw new NotImplementedException ();
  180. }
  181. #endregion
  182. #region Events and Delegates
  183. public event OleDbInfoMessageEventHandler InfoMessage;
  184. public event StateChangeEventHandler StateChange;
  185. #endregion
  186. }
  187. }