adding more debug messages to odbc
[csql.git] / include / SqlConnection.h
blobc946eab47eae8d57356ea23215aca8a27a103286
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>
25 class SqlStatement;
27 struct CachedStmtNode{
28 SqlStatement *sqlStmt;
29 int stmtLength;
30 char *sqlString;
32 class SqlConnection : public AbsSqlConnection
34 Connection conn;
35 bool isConnOpen;
36 public:
37 List cachedStmts;
38 SqlConnection(){ innerConn = NULL; isConnOpen = false; }
39 ~SqlConnection();
41 /** opens connection to the sql engine
42 * @param user username for authentication
43 * @param pass password for authentication
44 * @return DbRetVal
46 DbRetVal connect (char *user, char * pass) {
47 DbRetVal ret = conn.open(user, pass);
48 if (ret == OK) isConnOpen = true;
49 return ret;
52 /** closes connection to the database and releases all the resources
53 * @return DbRetVal
55 DbRetVal disconnect () {
56 DbRetVal ret = conn.close();
57 if (ret == OK) isConnOpen = false;
58 return ret;
61 /** Commits active transaction.
62 * It makes all the changes made in the current transaction permanent and <br/>
63 * it also releases the locks held by the current transaction.<br/>
64 * After a transaction commits, application is required to start another <br/>
65 * transaction for further database operations.
66 * @return DbRetVal
68 DbRetVal commit() { return conn.commit(); }
70 /** Aborts the active transaction.
71 * undo all the changes made in the current transaction and it also <br/>
72 * releases the locks held by the current transaction.<br/>
73 * After a transaction rollback, application is required to start another <br/>
74 * transaction for further database operations.
75 * @return DbRetVal
77 DbRetVal rollback() { return conn.rollback(); }
79 /** Starts a transaction.
80 * The previous transaction should be either committed or rollback <br/>
81 * before beginTrans is called. <br/>
82 * Applications are required to start transaction before they attempt any <br>
83 * database operation.
84 * @param isoLevel isolation level. Default is read committed.
85 * @return DbRetVal
87 DbRetVal beginTrans (IsolationLevel isoLevel = READ_COMMITTED,
88 TransSyncMode mode = OSYNC)
89 { return conn.startTransaction(isoLevel); }
91 Connection& getConnObject(){ return conn; }
92 bool isConnectionOpen() { if (isConnOpen) return true; return false; };
93 DbRetVal getExclusiveLock(){ return conn.getExclusiveLock(); }
95 SqlStatement* findInCache(char *stmtStr);
96 void flushCacheStmt();
97 void addToCache(SqlStatement *stmt, char *stmtStr);
99 friend class SqlFactory;
102 #endif