OleDbConnection.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //
  2. // System.Data.OleDb.OleDbConnection
  3. //
  4. // Author:
  5. // Rodrigo Moya ([email protected])
  6. //
  7. // Copyright (C) Rodrigo Moya, 2002
  8. //
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Data.Common;
  12. using System.Exception;
  13. namespace System.Data.OleDb
  14. {
  15. public sealed class OleDbConnection : Component, ICloneable, IDbConnection
  16. {
  17. private IntPtr m_gdaConnection = IntPtr.Zero;
  18. private string m_string = "";
  19. private int m_timeout = 15; // default is 15 seconds
  20. /*
  21. * Constructors
  22. */
  23. public OleDbConnection ()
  24. {
  25. }
  26. /*
  27. * Properties
  28. */
  29. public OleDbConnection (string cnc_string) : this ()
  30. {
  31. m_string = cnc_string;
  32. }
  33. string IDbConnection.ConnectionString
  34. {
  35. get {
  36. return m_string;
  37. }
  38. set {
  39. m_string = value;
  40. }
  41. }
  42. int IDbConnection.ConnectionTimeout
  43. {
  44. get {
  45. return m_timeout;
  46. }
  47. }
  48. string IDbConnection.Database
  49. {
  50. get {
  51. if (m_gdaConnection != IntPtr.Zero
  52. && libgda.gda_connection_is_open (m_gdaConnection)) {
  53. return libgda.gda_connection_get_database (m_gdaConnection);
  54. }
  55. return null;
  56. }
  57. }
  58. public string DataSource
  59. {
  60. [MonoTODO]
  61. get {
  62. throw new NotImplementedException ();
  63. }
  64. }
  65. public string Provider
  66. {
  67. get {
  68. if (m_gdaConnection != IntPtr.Zero
  69. && libgda.gda_connection_is_open (m_gdaConnection)) {
  70. return libgda.gda_connection_get_provider (m_gdaConnection);
  71. }
  72. return null;
  73. }
  74. }
  75. public string ServerVersion
  76. {
  77. [MonoTODO]
  78. get {
  79. throw new NotImplementedException ();
  80. }
  81. }
  82. ConnectionState IDbConnection.State
  83. {
  84. get {
  85. if (m_gdaConnection != IntPtr.Zero) {
  86. if (libgda.gda_connection_is_open (m_gdaConnection))
  87. return ConnectionState.Open;
  88. }
  89. return ConnectionState.Closed;
  90. }
  91. }
  92. /*
  93. * Methods
  94. */
  95. IDbTransaction IDbConnection.BeginTransaction ()
  96. {
  97. if (m_gdaConnection != IntPtr.Zero)
  98. return new OleDbTransaction (this);
  99. return null;
  100. }
  101. IDbTransaction IDbConnection.BeginTransaction (IsolationLevel level)
  102. {
  103. if (m_gdaConnection != IntPtr.Zero)
  104. return new OleDbTransaction (this, level);
  105. return null;
  106. }
  107. void IDbConnection.ChangeDatabase (string name)
  108. {
  109. // FIXME: see http://bugzilla.gnome.org/show_bug.cgi?id=83315
  110. }
  111. [MonoTODO]
  112. object ICloneable.Clone ()
  113. {
  114. throw new NotImplementedException();
  115. }
  116. void IDbConnection.Close ()
  117. {
  118. if (m_gdaConnection != IntPtr.Zero) {
  119. libgda.gda_connection_close (m_gdaConnection);
  120. m_gdaConnection = IntPtr.Zero;
  121. }
  122. }
  123. IDbCommand IDbConnection.CreateCommand ()
  124. {
  125. if (m_gdaConnection != IntPtr.Zero
  126. && libgda.gda_connection_is_open (m_gdaConnection)) {
  127. return new OleDbCommand ();
  128. }
  129. return null;
  130. }
  131. [MonoTODO]
  132. public DataTable GetOleDbSchemaTable (Guid schema,
  133. object[] restrictions)
  134. {
  135. throw new NotImplementedException ();
  136. }
  137. void IDbConnection.Open ()
  138. {
  139. if (m_gdaConnection != IntPtr.Zero ||
  140. libgda.gda_connection_is_open (m_gdaConnection))
  141. throw new InvalidOperationException ();
  142. m_gdaConnection = libgda.gda_client_open_connection (
  143. libgda.GdaClient,
  144. m_string,
  145. "", "");
  146. }
  147. /*
  148. * Events
  149. */
  150. public event OleDbInfoMessageEventHandler InfoMessage;
  151. public event StateChangeEventHandler StateChange;
  152. }
  153. }