1 /***************************************************************************
2 * Copyright (C) 2007 by Prabakaran Thirumalai *
3 * praba_tuty@yahoo.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #include <SqlGwConnection.h>
24 DbRetVal
SqlGwConnection::connect (char *user
, char * pass
)
26 isCSqlConnected
= false;
27 isAdapterConnected
= false;
28 strcpy(username
, user
);
29 strcpy(password
, pass
);
31 if (innerConn
) rv
= innerConn
->connect(user
,pass
);
32 if (rv
== OK
) isCSqlConnected
= true;
33 if (adapter
) rv
= adapter
->connect(user
,pass
);
34 if (rv
== OK
) isAdapterConnected
= true;
35 if (!isAdapterConnected
&& !isCSqlConnected
) return ErrNoConnection
;
39 DbRetVal
SqlGwConnection::disconnect()
42 if (innerConn
&& isCSqlConnected
) rv
=innerConn
->disconnect();
43 if (rv
!= OK
) return rv
;
44 if (adapter
&& isAdapterConnected
) rv
= adapter
->disconnect();
45 isCSqlConnected
= false;
46 isAdapterConnected
= false;
49 DbRetVal
SqlGwConnection::beginTrans(IsolationLevel isoLevel
, TransSyncMode smode
)
52 if (!isAdapterConnected
&& !isCSqlConnected
) return ErrNoConnection
;
53 if (innerConn
&& isCSqlConnected
) rv
= innerConn
->beginTrans(isoLevel
, smode
);
54 if (rv
!= OK
) return rv
;
55 if (adapter
&& isAdapterConnected
) rv
= adapter
->beginTrans(isoLevel
);
57 txnHdlr
= CSqlHandler
;
60 DbRetVal
SqlGwConnection::commit()
63 if (innerConn
&& isCSqlConnected
)
64 //(txnHdlr == CSqlHandler || txnHdlr == CSqlAndAdapterHandler))
65 rv
= innerConn
->commit();
66 if (rv
!= OK
) return rv
;
68 (txnHdlr
== AdapterHandler
|| txnHdlr
== CSqlAndAdapterHandler
))
69 rv
= adapter
->commit();
70 if (!isAdapterConnected
&& !isCSqlConnected
) return ErrNoConnection
;
73 DbRetVal
SqlGwConnection::rollback()
76 if (innerConn
&& isCSqlConnected
)
77 //(txnHdlr == CSqlHandler || txnHdlr == CSqlAndAdapterHandler))
78 rv
= innerConn
->rollback();
79 if (rv
!= OK
) return rv
;
80 if (adapter
&& isAdapterConnected
&&
81 (txnHdlr
== AdapterHandler
|| txnHdlr
== CSqlAndAdapterHandler
))
82 rv
= adapter
->rollback();
83 if (!isAdapterConnected
&& !isCSqlConnected
) return ErrNoConnection
;
86 DbRetVal
SqlGwConnection::connectCSqlIfNotConnected()
88 if (!isCSqlConnected
) {
89 DbRetVal rv
= innerConn
->connect(username
, password
);
90 if (rv
!= OK
) return rv
;
91 isCSqlConnected
= true;
95 DbRetVal
SqlGwConnection::connectAdapterIfNotConnected()
97 if (!isAdapterConnected
) {
98 DbRetVal rv
= adapter
->connect(username
, password
);
99 if (rv
!= OK
) return rv
;
100 isAdapterConnected
= true;