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 ***************************************************************************/
21 #include <SqlNwConnection.h>
25 DbRetVal
SqlNwConnection::connect (char *user
, char * pass
)
29 printError(ErrAlready
, "Connection is already open");
32 if (nwClient
== NULL
) nwClient
= new TCPClient();
33 int bufsize
= 2 * IDENTIFIER_LENGTH
+ sizeof(int);
34 nwClient
->setHost(hostname
, port
, 123);
35 rv
= nwClient
->connect();
37 printError(rv
, "Connection failed");
42 SqlPacketConnect
*pkt
= new SqlPacketConnect();
43 pkt
->setConnParam(user
, pass
, sqlApiImplType
);
44 pkt
->setBufferSize(bufsize
);
45 char * buffer
= (char *) malloc(bufsize
);
46 pkt
->setBuffer(buffer
);
48 rv
= nwClient
->send(SQL_NW_PKT_CONNECT
, buffer
, bufsize
);
50 printError(rv
, "Data could not be sent");
56 rv
= nwClient
->receive();
57 if (rv
== ErrPeerTimeOut
) {
61 return ErrNoConnection
;
63 ResponsePacket
*rpkt
= (ResponsePacket
*) ((TCPClient
*)nwClient
)->respPkt
;
64 if (rpkt
->errRetVal
!= OK
) {
68 return rpkt
->errRetVal
;
74 DbRetVal
SqlNwConnection::disconnect()
78 printError(ErrNoConnection
, "No connection present");
79 return ErrNoConnection
;
81 rv
= nwClient
->disconnect();
88 DbRetVal
SqlNwConnection::beginTrans(IsolationLevel isoLevel
, TransSyncMode mode
)
91 printError(ErrNoConnection
, "No connection present");
92 return ErrNoConnection
;
97 DbRetVal
SqlNwConnection::commit()
100 printError(ErrNoConnection
, "No connection present");
101 return ErrNoConnection
;
104 rv
= nwClient
->send(SQL_NW_PKT_COMMIT
);
105 if (rv
== ErrNoConnection
) {
106 setConnClosed(false);
109 rv
= nwClient
->receive();
110 if (rv
== ErrNoConnection
|| rv
== ErrPeerTimeOut
) {
111 setConnClosed(false);
112 return ErrNoConnection
;
117 DbRetVal
SqlNwConnection::rollback()
120 printError(ErrNoConnection
, "No connection present");
121 return ErrNoConnection
;
124 rv
= nwClient
->send(SQL_NW_PKT_ROLLBACK
);
125 if (rv
== ErrNoConnection
) {
126 setConnClosed(false);
129 rv
= nwClient
->receive();
130 if (rv
== ErrNoConnection
|| rv
== ErrPeerTimeOut
) {
131 setConnClosed(false);
132 return ErrNoConnection
;