* System.Data.OleDb/OleDbConnection.cs (ChangeDatabase): implemented.
* System.Data.OleDb/OleDbException.cs (OleDbException): added internal
constructor.
(ErrorCode, Message, Source, Errors): implemented.
* System.Data.OleDb/OleDbError.cs: implemented the full class.
* System.Data.OleDb/libgda.cs: added more libgda functions.
* System.Data.OleDb/TestOleDb.cs (TestOleDb): display properties for
the opened connection.
svn path=/trunk/mcs/; revision=6725
+2002-08-18 Rodrigo Moya <rodrigo@ximian.com>
+
+ * System.Data.OleDb/OleDbConnection.cs (ChangeDatabase): implemented.
+
+ * System.Data.OleDb/OleDbException.cs (OleDbException): added internal
+ constructor.
+ (ErrorCode, Message, Source, Errors): implemented.
+
+ * System.Data.OleDb/OleDbError.cs: implemented the full class.
+
+ * System.Data.OleDb/libgda.cs: added more libgda functions.
+
+ * System.Data.OleDb/TestOleDb.cs (TestOleDb): display properties for
+ the opened connection.
+
2002-08-18 Rodrigo Moya <rodrigo@ximian.com>
* System.Data.OleDb/OleDbConnection.cs (ServerVersion): implemented.
public void ChangeDatabase (string name)
{
- // FIXME: see http://bugzilla.gnome.org/show_bug.cgi?id=83315
+ if (gdaConnection == IntPtr.Zero)
+ throw new ArgumentException ();
+ if (State != ConnectionState.Open)
+ throw new InvalidOperationException ();
+
+ if (!libgda.gda_connection_change_database (gdaConnection, name))
+ throw new OleDbException (this);
}
public void Close ()
{
public sealed class OleDbError
{
+ private string errorMessage;
+ private int nativeError;
+ private string errorSource;
+ private string sqlState;
+
+ #region Constructors
+
+ internal OleDbError (string msg, int code, string source, string sql)
+ {
+ errorMessage = msg;
+ nativeError = code;
+ errorSource = source;
+ sqlState = sql;
+ }
+
+ #endregion // Constructors
+
#region Properties
public string Message {
- [MonoTODO]
- get { throw new NotImplementedException (); }
+ get {
+ return errorMessage;
+ }
}
public int NativeError {
- [MonoTODO]
- get { throw new NotImplementedException (); }
+ get {
+ return nativeError;
+ }
}
public string Source {
- [MonoTODO]
- get { throw new NotImplementedException (); }
+ get {
+ return errorSource;
+ }
}
public string SqlState {
- [MonoTODO]
- get { throw new NotImplementedException (); }
+ get {
+ return sqlState;
+ }
}
#endregion
#region Properties
public int Count {
- get { return list.Count; }
+ get {
+ return list.Count;
+ }
}
public OleDbError this[int index] {
- get { return (OleDbError) list[index]; }
+ get {
+ return (OleDbError) list[index];
+ }
}
object ICollection.SyncRoot {
- get { return list.SyncRoot; }
+ get {
+ return list.SyncRoot;
+ }
}
bool ICollection.IsSynchronized {
- get { return list.IsSynchronized; }
+ get {
+ return list.IsSynchronized;
+ }
}
#endregion // Properties
#region Methods
+ internal void Add (OleDbError error)
+ {
+ list.Add ((object) error);
+ }
+
[MonoTODO]
public void CopyTo (Array array, int index)
{
[Serializable]
public sealed class OleDbException : ExternalException
{
+ private OleDbConnection connection;
+
+ #region Constructors
+
+ internal OleDbException (OleDbConnection cnc)
+ {
+ connection = cnc;
+ }
+
+ #endregion // Constructors
+
#region Properties
public override int ErrorCode {
- [MonoTODO]
- get { throw new NotImplementedException (); }
+ get {
+ GdaList glist;
+ IntPtr errors;
+
+ errors = libgda.gda_connection_get_errors (connection.GdaConnection);
+ if (errors != IntPtr.Zero) {
+ glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
+ return (int) libgda.gda_error_get_number (glist.data);
+ }
+
+ return -1;
+ }
}
- public OleDbErrorCollection Errors {
- [MonoTODO]
- get { throw new NotImplementedException (); }
+ public OleDbErrorCollection Errors {
+ get {
+ GdaList glist;
+ IntPtr errors;
+ OleDbErrorCollection col = new OleDbErrorCollection ();
+
+ errors = libgda.gda_connection_get_errors (connection.GdaConnection);
+ if (errors != IntPtr.Zero) {
+ glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
+ while (glist != null) {
+ col.Add (new OleDbError (
+ libgda.gda_error_get_description (glist.data),
+ (int) libgda.gda_error_get_number (glist.data),
+ libgda.gda_error_get_source (glist.data),
+ libgda.gda_error_get_sqlstate (glist.data)));
+ glist = (GdaList) Marshal.PtrToStructure (glist.next,
+ typeof (GdaList));
+ }
+ }
+
+ return col;
+ }
}
public override string Message {
- [MonoTODO]
- get { throw new NotImplementedException (); }
+ get {
+ GdaList glist;
+ IntPtr errors;
+ string msg = "";
+
+ errors = libgda.gda_connection_get_errors (connection.GdaConnection);
+ if (errors != IntPtr.Zero) {
+ glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
+ while (glist != null) {
+ msg = msg + ";" + libgda.gda_error_get_description (glist.data);
+ glist = (GdaList) Marshal.PtrToStructure (glist.next,
+ typeof (GdaList));
+ }
+
+ return msg;
+ }
+
+ return null;
+ }
}
public override string Source {
- [MonoTODO]
- get { throw new NotImplementedException (); }
+ get {
+ GdaList glist;
+ IntPtr errors;
+
+ errors = libgda.gda_connection_get_errors (connection.GdaConnection);
+ if (errors != IntPtr.Zero) {
+ glist = (GdaList) Marshal.PtrToStructure (errors, typeof (GdaList));
+ return libgda.gda_error_get_source (glist.data);
+ }
+
+ return null;
+ }
}
#endregion // Properties
m_cnc = new OleDbConnection ("PostgreSQL");
m_cnc.Open ();
+ Console.WriteLine ("Connected to:");
+ Console.WriteLine (" Data Source: " + m_cnc.DataSource);
+ Console.WriteLine (" Database: " + m_cnc.Database);
+ Console.WriteLine (" Connection string: " + m_cnc.ConnectionString);
+ Console.WriteLine (" Provider: " + m_cnc.Provider);
+ Console.WriteLine (" Server version:" + m_cnc.ServerVersion);
+
+ /* create temporary table */
Console.WriteLine ("Creating temporary table...");
cmd = new OleDbCommand ("CREATE TABLE mono_test_table ( " +
" name varchar(25), email varchar(50), date_entered timestamp)",
[DllImport("gda-2")]
public static extern string gda_connection_get_password (IntPtr cnc);
+ [DllImport("gda-2")]
+ public static extern bool gda_connection_change_database (IntPtr cnc, string name);
+
[DllImport("gda-2")]
public static extern IntPtr gda_transaction_new (string name);
[DllImport("gda-2")]
public static extern IntPtr gda_connection_execute_single_command (IntPtr cnc, IntPtr command, IntPtr parameterList);
+ [DllImport("gda-2")]
+ public static extern IntPtr gda_connection_get_errors (IntPtr cnc);
+
[DllImport("gda-2")]
public static extern IntPtr gda_command_new (string text, GdaCommandType type, GdaCommandOptions options);
[DllImport("gda-2")]
public static extern void gda_command_set_command_type (IntPtr cmd, GdaCommandType type);
+
+ [DllImport("gda-2")]
+ public static extern string gda_error_get_description (IntPtr error);
+
+ [DllImport("gda-2")]
+ public static extern long gda_error_get_number (IntPtr error);
+
+ [DllImport("gda-2")]
+ public static extern string gda_error_get_source (IntPtr error);
+
+ [DllImport("gda-2")]
+ public static extern string gda_error_get_sqlstate (IntPtr error);
+
}
}