OleDbConnection.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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, null);
  29. gdaConnection = IntPtr.Zero;
  30. connectionTimeout = 15;
  31. connectionString = null;
  32. }
  33. public OleDbConnection (string connectionString) : this ()
  34. {
  35. 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 && libgda.gda_connection_is_open (gdaConnection)) {
  55. return libgda.gda_connection_get_database (gdaConnection);
  56. }
  57. return null;
  58. }
  59. }
  60. public string DataSource {
  61. [MonoTODO]
  62. get {
  63. throw new NotImplementedException ();
  64. }
  65. }
  66. public string Provider {
  67. get {
  68. if (gdaConnection != IntPtr.Zero && libgda.gda_connection_is_open (gdaConnection)) {
  69. return libgda.gda_connection_get_provider (gdaConnection);
  70. }
  71. return null;
  72. }
  73. }
  74. public string ServerVersion {
  75. [MonoTODO]
  76. get {
  77. throw new NotImplementedException ();
  78. }
  79. }
  80. public ConnectionState State
  81. {
  82. get {
  83. if (gdaConnection != IntPtr.Zero) {
  84. if (libgda.gda_connection_is_open (gdaConnection))
  85. return ConnectionState.Open;
  86. }
  87. return ConnectionState.Closed;
  88. }
  89. }
  90. internal IntPtr GdaConnection
  91. {
  92. get {
  93. return gdaConnection;
  94. }
  95. }
  96. #endregion // Properties
  97. #region Methods
  98. public OleDbTransaction BeginTransaction ()
  99. {
  100. if (gdaConnection != IntPtr.Zero)
  101. return new OleDbTransaction (this);
  102. return null;
  103. }
  104. IDbTransaction IDbConnection.BeginTransaction ()
  105. {
  106. return BeginTransaction ();
  107. }
  108. public OleDbTransaction BeginTransaction (IsolationLevel level)
  109. {
  110. if (gdaConnection != IntPtr.Zero)
  111. return new OleDbTransaction (this, level);
  112. return null;
  113. }
  114. IDbTransaction IDbConnection.BeginTransaction (IsolationLevel level)
  115. {
  116. return BeginTransaction (level);
  117. }
  118. public void ChangeDatabase (string name)
  119. {
  120. // FIXME: see http://bugzilla.gnome.org/show_bug.cgi?id=83315
  121. }
  122. public void Close ()
  123. {
  124. if (gdaConnection != IntPtr.Zero) {
  125. libgda.gda_connection_close (gdaConnection);
  126. gdaConnection = IntPtr.Zero;
  127. }
  128. }
  129. public OleDbCommand CreateCommand ()
  130. {
  131. if (gdaConnection != IntPtr.Zero && libgda.gda_connection_is_open (gdaConnection))
  132. return new OleDbCommand (null, this);
  133. return null;
  134. }
  135. [MonoTODO]
  136. protected override void Dispose (bool disposing)
  137. {
  138. throw new NotImplementedException ();
  139. }
  140. [MonoTODO]
  141. public DataTable GetOleDbSchemaTable (Guid schema, object[] restrictions)
  142. {
  143. throw new NotImplementedException ();
  144. }
  145. [MonoTODO]
  146. object ICloneable.Clone ()
  147. {
  148. throw new NotImplementedException();
  149. }
  150. IDbCommand IDbConnection.CreateCommand ()
  151. {
  152. return CreateCommand ();
  153. }
  154. public void Open ()
  155. {
  156. if (gdaConnection != IntPtr.Zero ||
  157. libgda.gda_connection_is_open (gdaConnection))
  158. throw new InvalidOperationException ();
  159. gdaConnection = libgda.gda_client_open_connection (libgda.GdaClient,
  160. connectionString,
  161. "", "");
  162. }
  163. [MonoTODO]
  164. public static void ReleaseObjectPool ()
  165. {
  166. throw new NotImplementedException ();
  167. }
  168. #endregion
  169. #region Internal Methods
  170. // Used to prevent OleDbConnection
  171. // from doing anything while
  172. // OleDbDataReader is open.
  173. // Open the Reader. (called from OleDbCommand)
  174. internal void OpenReader (OleDbDataReader reader)
  175. {
  176. if(dataReaderOpen == true) {
  177. // TODO: throw exception here?
  178. // because a reader
  179. // is already open
  180. }
  181. else {
  182. dataReader = reader;
  183. dataReaderOpen = true;
  184. }
  185. }
  186. #endregion
  187. #region Events and Delegates
  188. public event OleDbInfoMessageEventHandler InfoMessage;
  189. public event StateChangeEventHandler StateChange;
  190. #endregion
  191. }
  192. }