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 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");
40 SqlPacketConnect
*pkt
= new SqlPacketConnect();
41 pkt
->setConnParam(user
, pass
, sqlApiImplType
);
42 pkt
->setBufferSize(bufsize
);
43 char * buffer
= (char *) malloc(bufsize
);
44 pkt
->setBuffer(buffer
);
46 rv
= nwClient
->send(SQL_NW_PKT_CONNECT
, buffer
, bufsize
);
48 printError(rv
, "Data could not be sent");
52 rv
= nwClient
->receive();
53 ResponsePacket
*rpkt
= (ResponsePacket
*) ((TCPClient
*)nwClient
)->respPkt
;
54 char *ptr
= (char *) &rpkt
->retVal
;
56 printError(ErrPeerResponse
, "%s", rpkt
->errorString
);
57 nwClient
->disconnect();
60 return ErrPeerResponse
;
66 DbRetVal
SqlNwConnection::disconnect()
70 printError(ErrNoConnection
, "No connection present");
71 return ErrNoConnection
;
73 rv
= nwClient
->disconnect();
79 DbRetVal
SqlNwConnection::beginTrans(IsolationLevel isoLevel
, TransSyncMode mode
)
82 printError(ErrNoConnection
, "No connection present");
83 return ErrNoConnection
;
88 DbRetVal
SqlNwConnection::commit()
91 printError(ErrNoConnection
, "No connection present");
92 return ErrNoConnection
;
95 rv
= nwClient
->send(SQL_NW_PKT_COMMIT
);
97 return nwClient
->receive();
100 DbRetVal
SqlNwConnection::rollback()
103 printError(ErrNoConnection
, "No connection present");
104 return ErrNoConnection
;
107 rv
= nwClient
->send(SQL_NW_PKT_ROLLBACK
);
109 return nwClient
->receive();