2e576494ecd07ca2737ac385259cd2715a8567ca
[mono.git] / mcs / class / System.Data / System.Data.SqlClient / SqlTransaction.cs
1 //
2 // System.Data.SqlClient.SqlTransaction.cs
3 //
4 // Author:
5 //   Rodrigo Moya (rodrigo@ximian.com)
6 //
7 // (C) Ximian, Inc. 2002
8 //
9 using System;
10 using System.Data;
11 using System.Data.Common;
12
13 namespace System.Data.SqlClient
14 {
15         /// <summary>
16         /// Represents a transaction to be performed on a SQL database.
17         /// </summary>
18         // public sealed class SqlTransaction : MarshalByRefObject,
19         //      IDbTransaction, IDisposable
20         public sealed class SqlTransaction : IDbTransaction
21         {
22                 #region Fields
23
24                 private SqlConnection conn = null;
25                 //        How do you get/set the 
26                 //        IsolationLevel in PostgreSQL?
27                 private IsolationLevel isolationLevel = 
28                         IsolationLevel.ReadCommitted;
29                 // There are two IsolationLevel's for PostgreSQL:
30                 //    ReadCommitted and Serializable, 
31                 // but ReadCommitted is the default 
32                 
33                 #endregion
34                
35                 #region Public Methods
36
37                 [MonoTODO]
38                 public void Commit ()
39                 {
40                         IntPtr pgResult;
41                         ExecStatusType execStatus;
42
43                         pgResult = PostgresLibrary.
44                                 PQexec (conn.PostgresConnection, 
45                                         "COMMIT");
46                         /* FIXME: check result and emit 
47                          * exceptions on errors 
48                          */
49                         execStatus = PostgresLibrary.
50                                 PQresultStatus (pgResult);
51
52                         String cmdStatus;
53                         cmdStatus = PostgresLibrary.
54                                 PQcmdStatus(pgResult);
55
56                         Console.WriteLine("*** Command Status: " +
57                                 cmdStatus);
58
59                         PostgresLibrary.PQclear (pgResult);
60                 }               
61
62                 [MonoTODO]
63                 public void Rollback()
64                 {
65                         IntPtr pgResult;
66                         ExecStatusType execStatus;
67
68                         pgResult = PostgresLibrary.
69                                 PQexec (conn.PostgresConnection, 
70                                         "ROLLBACK");
71                         /* FIXME: check result and emit 
72                          * exceptions on errors 
73                          */
74                         execStatus = PostgresLibrary.
75                                 PQresultStatus (pgResult);
76
77                         String cmdStatus;
78                         cmdStatus = PostgresLibrary.
79                                 PQcmdStatus(pgResult);
80
81                         Console.WriteLine("*** Command Status: " +
82                                 cmdStatus);
83
84                         PostgresLibrary.PQclear (pgResult);
85                 }
86
87                 #endregion // Public Methods
88
89                 #region Internal Methods to System.Data.dll Assembly
90
91                 internal void Begin()
92                 {
93                         IntPtr pgResult;
94                         ExecStatusType execStatus;
95
96                         pgResult = PostgresLibrary.
97                                 PQexec (conn.PostgresConnection, 
98                                         "BEGIN");
99                         /* FIXME: check result and emit 
100                          * exceptions on errors 
101                          */
102                         execStatus = PostgresLibrary.
103                                 PQresultStatus (pgResult);
104
105                         String cmdStatus;
106                         cmdStatus = PostgresLibrary.
107                                 PQcmdStatus(pgResult);
108
109                         Console.WriteLine("*** Command Status: " +
110                                 cmdStatus);
111
112                         PostgresLibrary.PQclear (pgResult);
113                 }
114
115                 internal void SetIsolationLevel(IsolationLevel isoLevel)
116                 {
117                         this.isolationLevel = isoLevel;
118                 }
119
120                 internal void SetConnection(SqlConnection connection)
121                 {
122                         this.conn = connection;
123                 }
124
125                 #endregion // Internal Methods to System.Data.dll Assembly
126
127                 #region Properties
128
129                 IDbConnection IDbTransaction.Connection {
130                         get { 
131                                 return Connection; 
132                         }
133                 }
134
135                 public SqlConnection Connection {
136                         get { 
137                                 return conn; 
138                         }
139                 }
140
141                 public IsolationLevel IsolationLevel {
142                         get { 
143                                 return isolationLevel; 
144                         }
145                 }
146
147                 [MonoTODO]
148                 public void Dispose()
149                 {
150                         // FIXME: need to properly release resources
151                 }
152         
153                 #endregion // Properties
154
155         }
156 }