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
);
49 printDebug(DM_Network
, "DEBUG:::NWCONNECT send connect pkt %d\n", rv
);
51 printError(rv
, "Data could not be sent");
57 rv
= nwClient
->receive();
58 printDebug(DM_Network
, "DEBUG:::NWCONNECT receive connect pkt %d \n", rv
);
59 if (rv
== ErrPeerTimeOut
) {
63 return ErrNoConnection
;
65 ResponsePacket
*rpkt
= (ResponsePacket
*) ((TCPClient
*)nwClient
)->respPkt
;
66 if (rpkt
->errRetVal
!= OK
) {
70 return rpkt
->errRetVal
;
76 DbRetVal
SqlNwConnection::disconnect()
80 printError(ErrNoConnection
, "No connection present");
81 return ErrNoConnection
;
83 rv
= nwClient
->disconnect();
90 DbRetVal
SqlNwConnection::beginTrans(IsolationLevel isoLevel
, TransSyncMode mode
)
93 printError(ErrNoConnection
, "No connection present");
94 return ErrNoConnection
;
99 DbRetVal
SqlNwConnection::commit()
102 printError(ErrNoConnection
, "No connection present");
103 return ErrNoConnection
;
106 rv
= nwClient
->send(SQL_NW_PKT_COMMIT
);
107 if (rv
== ErrNoConnection
) {
108 setConnClosed(false);
111 rv
= nwClient
->receive();
112 if (rv
== ErrNoConnection
|| rv
== ErrPeerTimeOut
) {
113 setConnClosed(false);
114 return ErrNoConnection
;
119 DbRetVal
SqlNwConnection::rollback()
122 printError(ErrNoConnection
, "No connection present");
123 return ErrNoConnection
;
126 rv
= nwClient
->send(SQL_NW_PKT_ROLLBACK
);
127 if (rv
== ErrNoConnection
) {
128 setConnClosed(false);
131 rv
= nwClient
->receive();
132 if (rv
== ErrNoConnection
|| rv
== ErrPeerTimeOut
) {
133 setConnClosed(false);
134 return ErrNoConnection
;