windows porting first phase- ported os layer, storage module to windows
[csql.git] / include / SqlOdbcConnection.h
blob7ed3584a989c752e5a9bcc64a0e1c86d06f98fb4
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 SQLODBCCONNECTION_H
21 #define SQLODBCCONNECTION_H
22 #include <CSql.h>
23 #include <AbsSqlConnection.h>
24 #include <SqlFactory.h>
25 #include <sql.h>
26 #include <sqlext.h>
28 #ifdef WINNT
29 typedef signed short int SWORD;
30 #endif
32 struct SQLFuncPtrs{
33 SQLRETURN (*SQLAllocHandlePtr)(SQLSMALLINT, SQLHANDLE, SQLHANDLE*);
34 SQLRETURN (*SQLSetEnvAttrPtr)(SQLHENV, SQLINTEGER, SQLPOINTER, SQLINTEGER);
35 SQLRETURN (*SQLDriverConnectPtr)(SQLHDBC, SQLHWND, SQLCHAR*, SQLSMALLINT, SQLCHAR*, SQLSMALLINT, SQLSMALLINT*, SQLUSMALLINT);
36 SQLRETURN (*SQLGetDiagRecPtr)(SQLSMALLINT, SQLHANDLE, SQLSMALLINT, SQLCHAR*, SQLINTEGER*, SQLCHAR*, SQLSMALLINT, SQLSMALLINT*);
37 SQLRETURN (*SQLSetConnectAttrPtr)(SQLHDBC, SQLINTEGER, SQLPOINTER, SQLINTEGER);
38 SQLRETURN (*SQLFreeHandlePtr)(SQLSMALLINT, SQLHANDLE);
39 SQLRETURN (*SQLTransactPtr)(SQLHENV, SQLHDBC, SQLUSMALLINT);
41 SQLRETURN (*SQLExecDirectPtr)(SQLHSTMT, SQLCHAR*, SQLINTEGER);
42 SQLRETURN (*SQLPreparePtr)(SQLHSTMT, SQLCHAR*, SQLINTEGER);
43 SQLRETURN (*SQLNumResultColsPtr)(SQLHSTMT, SQLSMALLINT*);
44 SQLRETURN (*SQLDescribeColPtr)(SQLHSTMT, SQLUSMALLINT, SQLCHAR*, SQLSMALLINT, SQLSMALLINT*, SQLSMALLINT*, SQLULEN*,SQLSMALLINT*, SQLSMALLINT*);
45 SQLRETURN (*SQLBindColPtr)(SQLHSTMT, SQLUSMALLINT, SQLSMALLINT, SQLPOINTER, SQLLEN, SQLLEN*);
46 SQLRETURN (*SQLNumParamsPtr)(SQLHSTMT, SQLSMALLINT*);
47 SQLRETURN (*SQLDescribeParamPtr)(SQLHSTMT, SQLUSMALLINT, SQLSMALLINT*, SQLULEN*, SQLSMALLINT*, SQLSMALLINT*);
48 SQLRETURN (*SQLBindParameterPtr)( SQLHSTMT, SQLUSMALLINT, SQLSMALLINT, SQLSMALLINT, SQLSMALLINT, SQLULEN, SQLSMALLINT, SQLPOINTER, SQLLEN, SQLLEN*);
49 SQLRETURN (*SQLExecutePtr)(SQLHSTMT);
50 SQLRETURN (*SQLRowCountPtr)(SQLHSTMT, SQLLEN*);
51 SQLRETURN (*SQLFetchPtr)(SQLHSTMT);
52 SQLRETURN (*SQLFetchScrollPtr)(SQLHSTMT, SQLSMALLINT, SQLLEN);
53 SQLRETURN (*SQLCloseCursorPtr)(SQLHSTMT);
54 SQLRETURN (*SQLPrimaryKeysPtr)( SQLHSTMT, SQLCHAR*, SQLSMALLINT, SQLCHAR*, SQLSMALLINT, SQLCHAR*, SQLSMALLINT);
55 SQLRETURN (*SQLGetDataPtr)(SQLHSTMT,SQLUSMALLINT,SQLSMALLINT,SQLPOINTER, SQLLEN,SQLLEN*);
56 SQLRETURN (*SQLDisconnectPtr)(SQLHDBC);
57 SQLRETURN (*SQLTablesPtr)(SQLHSTMT ,SQLCHAR *, SQLSMALLINT , SQLCHAR * , SQLSMALLINT, SQLCHAR *, SQLSMALLINT, SQLCHAR*,SQLSMALLINT);
58 SQLRETURN (*SQLProcedureColumnsPtr)(SQLHSTMT, SQLCHAR *, SQLSMALLINT, SQLCHAR *, SQLSMALLINT, SQLCHAR *, SQLSMALLINT,SQLCHAR *, SQLSMALLINT);
61 /**
62 * @class SqlOdbcConnection
65 //class SqlOdbcSym {
66 // public:
67 //};
69 class DllExport SqlOdbcConnection : public AbsSqlConnection
71 Connection dummyConn;
72 char errState[STATE_LENGTH];
73 char dsName[IDENTIFIER_LENGTH];
74 bool isConnOpen;
75 TDBInfo tdbName;
76 public:
77 SQLHENV envHdl;
78 SQLHDBC dbHdl;
79 char dsString[IDENTIFIER_LENGTH];
80 IsolationLevel prevIsoLevel;
81 SqlOdbcConnection()
83 strcpy(errState,"00000");
84 innerConn = NULL;
85 tdbName = mysql;
86 prevIsoLevel = READ_COMMITTED;
87 dsName[0]='\0';
88 isConnOpen = false;
90 ~SqlOdbcConnection(){}
92 void setDsName(char *dsname){ strcpy(dsName,dsname);}
93 char *getDsName(){return dsName;}
94 void setTrDbName(char *name);
95 TDBInfo getTrDbName(){return tdbName;}
96 static bool symbolsLoaded;
97 static struct SQLFuncPtrs ODBCFuncPtrs;
99 void setErrorState( SQLHDBC dbc);
100 DbRetVal loadSymbols();
102 //Note::forced to implement this as it is pure virtual in base class
103 Connection& getConnObject(){ return dummyConn; }
104 bool isConnectionOpen() { if (isConnOpen) return true; return false; }
106 DbRetVal connect (char *user, char * pass);
108 DbRetVal disconnect();
110 DbRetVal commit();
112 DbRetVal rollback();
114 DbRetVal beginTrans (IsolationLevel isoLevel, TransSyncMode mode);
116 friend class SqlFactory;
119 #endif