Adding tests for composite keys
[csql.git] / include / SqlConnection.h
blob01ce3d50fc9d48727548fa49ca226cff4ec114bb
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 #ifndef SQLCONNECTION_H
21 #define SQLCONNECTION_H
22 #include<CSql.h>
23 #include<AbsSqlConnection.h>
24 #include<SqlFactory.h>
26 class SqlConnection : public AbsSqlConnection
28 Connection conn;
29 bool isConnOpen;
30 public:
31 SqlConnection(){innerConn = NULL; isConnOpen = false; }
33 /** opens connection to the sql engine
34 * @param user username for authentication
35 * @param pass password for authentication
36 * @return DbRetVal
38 DbRetVal connect (char *user, char * pass) {
39 DbRetVal ret = conn.open(user, pass);
40 if (ret == OK) isConnOpen = true;
41 return ret;
44 /** closes connection to the database and releases all the resources
45 * @return DbRetVal
47 DbRetVal disconnect () {
48 DbRetVal ret = conn.close();
49 if (ret == OK) isConnOpen = false;
50 return ret;
53 /** Commits active transaction.
54 * It makes all the changes made in the current transaction permanent and <br/>
55 * it also releases the locks held by the current transaction.<br/>
56 * After a transaction commits, application is required to start another <br/>
57 * transaction for further database operations.
58 * @return DbRetVal
60 DbRetVal commit() { return conn.commit(); }
62 /** Aborts the active transaction.
63 * undo all the changes made in the current transaction and it also <br/>
64 * releases the locks held by the current transaction.<br/>
65 * After a transaction rollback, application is required to start another <br/>
66 * transaction for further database operations.
67 * @return DbRetVal
69 DbRetVal rollback() { return conn.rollback(); }
71 /** Starts a transaction.
72 * The previous transaction should be either committed or rollback <br/>
73 * before beginTrans is called. <br/>
74 * Applications are required to start transaction before they attempt any <br>
75 * database operation.
76 * @param isoLevel isolation level. Default is read committed.
77 * @return DbRetVal
79 DbRetVal beginTrans (IsolationLevel isoLevel = READ_COMMITTED,
80 TransSyncMode mode = OSYNC)
81 { return conn.startTransaction(isoLevel); }
83 Connection& getConnObject(){ return conn; }
84 bool isConnectionOpen() { if (isConnOpen) return true; return false; };
86 friend class SqlFactory;
89 #endif