counter used in for loop is initialized. earlier it was defined inside the loop
[csql.git] / src / gateway / SqlGwConnection.cxx
blob658d5f839d123d9d88cac9365dec842ef2b31ff9
1 /***************************************************************************
2 * Copyright (C) 2007 by Prabakaran Thirumalai *
3 * praba_tuty@yahoo.com *
4 * *
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. *
9 * *
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. *
14 * *
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>
21 #include <CSql.h>
22 #include <Network.h>
24 DbRetVal SqlGwConnection::connect (char *user, char * pass)
26 isCSqlConnected = false;
27 isAdapterConnected = false;
28 strcpy(username, user);
29 strcpy(password, pass);
30 DbRetVal rv = OK;
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;
36 return OK;
39 DbRetVal SqlGwConnection::disconnect()
41 DbRetVal rv = OK;
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;
47 return rv;
49 DbRetVal SqlGwConnection::beginTrans(IsolationLevel isoLevel, TransSyncMode smode)
51 DbRetVal rv = OK;
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);
56 //mode = smode;
57 txnHdlr = CSqlHandler;
58 return rv;
60 DbRetVal SqlGwConnection::commit()
62 DbRetVal rv = OK;
63 if (innerConn && isCSqlConnected)
64 //(txnHdlr == CSqlHandler || txnHdlr == CSqlAndAdapterHandler))
65 rv = innerConn->commit();
66 if (rv != OK) return rv;
67 if (adapter &&
68 (txnHdlr == AdapterHandler || txnHdlr == CSqlAndAdapterHandler))
69 rv = adapter->commit();
70 if (!isAdapterConnected && !isCSqlConnected) return ErrNoConnection;
71 return rv;
73 DbRetVal SqlGwConnection::rollback()
75 DbRetVal rv = OK;
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;
84 return rv;
86 DbRetVal SqlGwConnection::connectCSqlIfNotConnected()
88 if (!isCSqlConnected) {
89 DbRetVal rv = innerConn->connect(username, password);
90 if (rv != OK) return rv;
91 isCSqlConnected = true;
93 return OK;
95 DbRetVal SqlGwConnection::connectAdapterIfNotConnected()
97 if (!isAdapterConnected) {
98 DbRetVal rv = adapter->connect(username, password);
99 if (rv != OK) return rv;
100 isAdapterConnected = true;
102 return OK;