1
1
/******************************************************************************
2
* $Id: cpl_odbc.cpp 19176 2010-03-24 17:50:49Z chaitanya $
2
* $Id: cpl_odbc.cpp 20862 2010-10-17 15:47:12Z tamas $
4
4
* Project: OGR ODBC Driver
5
5
* Purpose: Declarations for ODBC Access Cover API.
36
36
#ifndef WIN32CE /* ODBC is not supported on Windows CE. */
38
CPL_CVSID("$Id: cpl_odbc.cpp 19176 2010-03-24 17:50:49Z chaitanya $");
38
CPL_CVSID("$Id: cpl_odbc.cpp 20862 2010-10-17 15:47:12Z tamas $");
40
40
#ifndef SQLColumns_TABLE_CAT
41
41
#define SQLColumns_TABLE_CAT 1
200
202
/************************************************************************/
203
/* ClearTransaction() */
204
/************************************************************************/
206
int CPLODBCSession::ClearTransaction()
209
#if (ODBCVER >= 0x0300)
214
SQLUINTEGER bAutoCommit;
215
/* See if we already in manual commit mode */
216
if ( Failed( SQLGetConnectAttr( m_hDBC, SQL_ATTR_AUTOCOMMIT, &bAutoCommit, sizeof(SQLUINTEGER), NULL) ) )
219
if (bAutoCommit == SQL_AUTOCOMMIT_OFF)
221
/* switch the connection to auto commit mode (default) */
222
if( Failed( SQLSetConnectAttr( m_hDBC, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_ON, 0 ) ) )
226
m_bAutoCommit = TRUE;
232
/************************************************************************/
233
/* CommitTransaction() */
234
/************************************************************************/
236
int CPLODBCSession::BeginTransaction()
239
#if (ODBCVER >= 0x0300)
241
SQLUINTEGER bAutoCommit;
242
/* See if we already in manual commit mode */
243
if ( Failed( SQLGetConnectAttr( m_hDBC, SQL_ATTR_AUTOCOMMIT, &bAutoCommit, sizeof(SQLUINTEGER), NULL) ) )
246
if (bAutoCommit == SQL_AUTOCOMMIT_ON)
248
/* switch the connection to manual commit mode */
249
if( Failed( SQLSetConnectAttr( m_hDBC, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_OFF, 0 ) ) )
253
m_bInTransaction = TRUE;
254
m_bAutoCommit = FALSE;
260
/************************************************************************/
261
/* CommitTransaction() */
262
/************************************************************************/
264
int CPLODBCSession::CommitTransaction()
267
#if (ODBCVER >= 0x0300)
269
if (m_bInTransaction)
271
if( Failed( SQLEndTran( SQL_HANDLE_DBC, m_hDBC, SQL_COMMIT ) ) )
275
m_bInTransaction = FALSE;
282
/************************************************************************/
283
/* RollbackTransaction() */
284
/************************************************************************/
286
int CPLODBCSession::RollbackTransaction()
289
#if (ODBCVER >= 0x0300)
291
if (m_bInTransaction)
293
m_bInTransaction = FALSE;
295
int nRetCode = SQLEndTran( SQL_HANDLE_DBC, m_hDBC, SQL_ROLLBACK );
297
if( nRetCode != SQL_SUCCESS && nRetCode != SQL_SUCCESS_WITH_INFO )
305
/************************************************************************/
203
308
/* Test if a return code indicates failure, return TRUE if that */
748
866
if (nFetchType == SQL_C_CHAR)
749
867
while ((cbDataLen > 1) && (szWrkData[cbDataLen - 1] == 0))
750
868
--cbDataLen; // trimming the extra terminators: bug 990
869
else if (nFetchType == SQL_C_WCHAR)
870
while ((cbDataLen > 1) && (szWrkData[cbDataLen - 1] == 0)
871
&& (szWrkData[cbDataLen - 2] == 0))
872
cbDataLen -= 2; // trimming the extra terminators
753
m_papszColValues[iCol] = (char *) CPLMalloc(cbDataLen+1);
876
m_papszColValues[iCol] = (char *) CPLMalloc(cbDataLen+2);
754
877
memcpy( m_papszColValues[iCol], szWrkData, cbDataLen );
755
878
m_papszColValues[iCol][cbDataLen] = '\0';
879
m_papszColValues[iCol][cbDataLen+1] = '\0';
756
880
m_panColValueLengths[iCol] = cbDataLen;
781
905
while ( (nChunkLen > 1)
782
906
&& (szWrkData[nChunkLen - 1] == 0) )
783
907
--nChunkLen; // trimming the extra terminators
908
else if (nFetchType == SQL_C_WCHAR)
909
while ( (nChunkLen > 1)
910
&& (szWrkData[nChunkLen - 1] == 0)
911
&& (szWrkData[nChunkLen - 2] == 0) )
912
nChunkLen -= 2; // trimming the extra terminators
786
915
nChunkLen = cbDataLen;
1213
1348
if( pszSchema == NULL )
1214
1349
pszSchema = "";
1352
#if (ODBCVER >= 0x0300)
1354
if ( !m_poSession->IsInTransaction() )
1356
/* commit pending transactions and set to autocommit mode*/
1357
m_poSession->ClearTransaction();
1216
1361
/* -------------------------------------------------------------------- */
1217
1362
/* Fetch columns resultset for this table. */
1218
1363
/* -------------------------------------------------------------------- */
1332
1477
if( pszSchema == NULL )
1333
1478
pszSchema = "";
1480
#if (ODBCVER >= 0x0300)
1482
if ( !m_poSession->IsInTransaction() )
1484
/* commit pending transactions and set to autocommit mode*/
1485
m_poSession->ClearTransaction();
1335
1490
/* -------------------------------------------------------------------- */
1336
1491
/* Fetch columns resultset for this table. */
1337
1492
/* -------------------------------------------------------------------- */
1372
1527
CPLDebug( "ODBC", "CatalogNameL: %s\nSchema name: %s\n",
1373
1528
pszCatalog, pszSchema );
1530
#if (ODBCVER >= 0x0300)
1532
if ( !m_poSession->IsInTransaction() )
1534
/* commit pending transactions and set to autocommit mode*/
1535
m_poSession->ClearTransaction();
1375
1540
/* -------------------------------------------------------------------- */
1376
1541
/* Fetch columns resultset for this table. */
1377
1542
/* -------------------------------------------------------------------- */