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 <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
;
34 // char hostName[IDENTIFIER_LENGTH];
35 // memset(hostName, 0, IDENTIFIER_LENGTH);
36 //os::gethostname(hostName, IDENTIFIER_LENGTH);
37 nwClient
->setHost(hostname
, port
, 123);
38 rv
= nwClient
->connect();
40 printError(rv
, "Connection failed");
43 SqlPacketConnect
*pkt
= new SqlPacketConnect();
44 pkt
->setConnParam(user
, pass
);
45 pkt
->setBufferSize(bufsize
);
46 char * buffer
= (char *) malloc(bufsize
);
47 pkt
->setBuffer(buffer
);
49 rv
= send(SQL_NW_PKT_CONNECT
, buffer
, bufsize
);
51 printError(rv
, "Data could not be sent");
55 rv
= nwClient
->receive();
56 ResponsePacket
*rpkt
= (ResponsePacket
*) ((TCPClient
*)nwClient
)->respPkt
;
57 char *ptr
= (char *) &rpkt
->retVal
;
59 printError(ErrPeerResponse
, "%s", rpkt
->errorString
);
60 nwClient
->disconnect();
63 return ErrPeerResponse
;
69 DbRetVal
SqlNwConnection::disconnect()
73 printError(ErrNoConnection
, "No connection present");
74 return ErrNoConnection
;
76 rv
= nwClient
->disconnect();
82 DbRetVal
SqlNwConnection::beginTrans(IsolationLevel isoLevel
, TransSyncMode mode
)
85 printError(ErrNoConnection
, "No connection present");
86 return ErrNoConnection
;
91 DbRetVal
SqlNwConnection::commit()
94 printError(ErrNoConnection
, "No connection present");
95 return ErrNoConnection
;
98 rv
= nwClient
->send(SQL_NW_PKT_COMMIT
, NULL
, 0);
100 return nwClient
->receive();
103 DbRetVal
SqlNwConnection::rollback()
106 printError(ErrNoConnection
, "No connection present");
107 return ErrNoConnection
;
110 rv
= nwClient
->send(SQL_NW_PKT_ROLLBACK
, NULL
, 0);
112 return nwClient
->receive();