fix for trie index
[csql.git] / src / oci / SqlOciConnection.cxx
blobfae33b0a300082f4f06676bfba82a49193bbc996
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 #include <SqlOciConnection.h>
21 #include <CSql.h>
23 DbRetVal SqlOciConnection::connect (char *user, char * pass)
25 DbRetVal rv = OK;
26 char dsn[72];
27 sprintf(dsn, "DSN=%s;", Conf::config.getDSN());
28 int retVal =0;
29 /*retVal = SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &envHdl);
30 if (retVal)
32 printError(ErrSysInit, "Unable to allocate ODBC handle \n");
33 return ErrSysInit;
35 SQLSetEnvAttr(envHdl, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
37 retVal = SQLAllocHandle (SQL_HANDLE_DBC, envHdl, &dbHdl);
38 if (retVal)
40 printError(ErrSysInit, "Unable to allocate ODBC handle \n");
41 return ErrSysInit;
43 SQLCHAR outstr[1024];
44 SQLSMALLINT outstrlen;
45 retVal = SQLDriverConnect(dbHdl, NULL, (SQLCHAR*)dsn, SQL_NTS,
46 outstr, sizeof(outstr), &outstrlen,
47 SQL_DRIVER_NOPROMPT);
48 if (!SQL_SUCCEEDED(retVal)) {
49 printError(ErrSysInit, "Failed to connect to target database using dsn=%s\n", dsn);
51 SQLINTEGER i = 0;
52 SQLINTEGER native;
53 SQLCHAR state[ 7 ];
54 SQLCHAR text[256];
55 SQLSMALLINT len;
56 SQLRETURN ret;
58 fprintf(stderr,
59 "\n"
60 "The driver reported the following diagnostics whilst running "
61 "\n\n");
65 ret = SQLGetDiagRec(SQL_HANDLE_DBC, dbHdl, ++i, state, &native, text,
66 sizeof(text), &len );
68 if (SQL_SUCCEEDED(ret))
69 printf("%s:%ld:%ld:%s\n", state, i, native, text);
71 while( ret == SQL_SUCCESS );
72 rv = ErrNoConnection;
73 rv = OK; //masking the error:tmp
75 //printError(ErrSysInit, "Connecting with dsn=%s\n", dsn);
76 SQLSetConnectAttr(dbHdl, SQL_ATTR_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF, 0);
78 return rv;
81 DbRetVal SqlOciConnection::disconnect()
83 DbRetVal rv = OK;
85 SQLDisconnect (dbHdl);
86 SQLFreeHandle (SQL_HANDLE_DBC, dbHdl);
87 SQLFreeHandle (SQL_HANDLE_ENV, envHdl);
89 return rv;
91 DbRetVal SqlOciConnection::beginTrans(IsolationLevel isoLevel, TransSyncMode mode)
93 if (prevIsoLevel == isoLevel) return OK;
94 DbRetVal rv = OK;
95 int retVal =0;
96 /*SQLPOINTER iso;
98 switch(isoLevel)
100 case READ_UNCOMMITTED:
101 iso = (SQLPOINTER)SQL_TXN_READ_UNCOMMITTED;
102 break;
103 case READ_COMMITTED:
104 iso = (SQLPOINTER)SQL_TXN_READ_COMMITTED;
105 break;
106 case READ_REPEATABLE:
107 iso = (SQLPOINTER)SQL_TXN_REPEATABLE_READ;
108 break;
109 default:
110 iso = (SQLPOINTER)SQL_TXN_READ_COMMITTED;
111 break;
114 retVal = SQLSetConnectAttr(dbHdl, SQL_ATTR_TXN_ISOLATION, iso, 0);
115 if (!SQL_SUCCEEDED(retVal)) return ErrSysInit;
116 prevIsoLevel = isoLevel;
117 retVal = SQLTransact (envHdl, dbHdl, SQL_ROLLBACK);
118 if (!SQL_SUCCEEDED(retVal)) rv = ErrSysInit;
120 return rv;
122 DbRetVal SqlOciConnection::commit()
124 DbRetVal rv = OK;
125 /*int retVal = SQLTransact (envHdl, dbHdl, SQL_COMMIT);
126 if (!SQL_SUCCEEDED(retVal)) rv = ErrSysInit;
128 return rv;
130 DbRetVal SqlOciConnection::rollback()
132 DbRetVal rv = OK;
133 /*int retVal = SQLTransact (envHdl, dbHdl, SQL_ROLLBACK);
134 if (!SQL_SUCCEEDED(retVal)) rv = ErrSysInit;
136 return rv;