~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to port/cpl_odbc.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 $
3
3
 *
4
4
 * Project:  OGR ODBC Driver
5
5
 * Purpose:  Declarations for ODBC Access Cover API.
35
35
 
36
36
#ifndef WIN32CE /* ODBC is not supported on Windows CE. */
37
37
 
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 $");
39
39
 
40
40
#ifndef SQLColumns_TABLE_CAT 
41
41
#define SQLColumns_TABLE_CAT 1
161
161
    m_szLastError[0] = '\0';
162
162
    m_hEnv = NULL;
163
163
    m_hDBC = NULL;
 
164
    m_bInTransaction = FALSE;
 
165
    m_bAutoCommit = TRUE;
164
166
}
165
167
 
166
168
/************************************************************************/
198
200
}
199
201
 
200
202
/************************************************************************/
 
203
/*                       ClearTransaction()                             */
 
204
/************************************************************************/
 
205
 
 
206
int CPLODBCSession::ClearTransaction()
 
207
 
 
208
{
 
209
#if (ODBCVER >= 0x0300)
 
210
 
 
211
    if (m_bAutoCommit)
 
212
        return TRUE;
 
213
 
 
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) ) )
 
217
        return FALSE;
 
218
 
 
219
    if (bAutoCommit == SQL_AUTOCOMMIT_OFF)
 
220
    {
 
221
        /* switch the connection to auto commit mode (default) */
 
222
        if( Failed( SQLSetConnectAttr( m_hDBC, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_ON, 0 ) ) )
 
223
            return FALSE;
 
224
    }
 
225
 
 
226
    m_bAutoCommit = TRUE;
 
227
 
 
228
#endif
 
229
    return TRUE;
 
230
}
 
231
 
 
232
/************************************************************************/
 
233
/*                       CommitTransaction()                            */
 
234
/************************************************************************/
 
235
 
 
236
int CPLODBCSession::BeginTransaction()
 
237
 
 
238
{
 
239
#if (ODBCVER >= 0x0300)
 
240
 
 
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) ) )
 
244
        return FALSE;
 
245
 
 
246
    if (bAutoCommit == SQL_AUTOCOMMIT_ON)
 
247
    {
 
248
        /* switch the connection to manual commit mode */
 
249
        if( Failed( SQLSetConnectAttr( m_hDBC, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_OFF, 0 ) ) )
 
250
            return FALSE;
 
251
    }
 
252
 
 
253
    m_bInTransaction = TRUE;
 
254
    m_bAutoCommit = FALSE;
 
255
 
 
256
#endif
 
257
    return TRUE;
 
258
}
 
259
 
 
260
/************************************************************************/
 
261
/*                       CommitTransaction()                            */
 
262
/************************************************************************/
 
263
 
 
264
int CPLODBCSession::CommitTransaction()
 
265
 
 
266
{
 
267
#if (ODBCVER >= 0x0300)
 
268
 
 
269
    if (m_bInTransaction)
 
270
    {
 
271
        if( Failed( SQLEndTran( SQL_HANDLE_DBC, m_hDBC, SQL_COMMIT ) ) )
 
272
        {
 
273
            return FALSE;
 
274
        }
 
275
        m_bInTransaction = FALSE;
 
276
    }
 
277
 
 
278
#endif
 
279
    return TRUE;
 
280
}
 
281
 
 
282
/************************************************************************/
 
283
/*                       RollbackTransaction()                          */
 
284
/************************************************************************/
 
285
 
 
286
int CPLODBCSession::RollbackTransaction()
 
287
 
 
288
{
 
289
#if (ODBCVER >= 0x0300)
 
290
 
 
291
    if (m_bInTransaction)
 
292
    {
 
293
        m_bInTransaction = FALSE;
 
294
 
 
295
        int nRetCode = SQLEndTran( SQL_HANDLE_DBC, m_hDBC, SQL_ROLLBACK );
 
296
        
 
297
        if( nRetCode != SQL_SUCCESS && nRetCode != SQL_SUCCESS_WITH_INFO )
 
298
            return FALSE;
 
299
    }
 
300
 
 
301
#endif
 
302
    return TRUE;
 
303
}
 
304
 
 
305
/************************************************************************/
201
306
/*                               Failed()                               */
202
307
/*                                                                      */
203
308
/*      Test if a return code indicates failure, return TRUE if that    */
221
326
              &nTextLength );
222
327
    m_szLastError[nTextLength] = '\0';
223
328
 
 
329
    if( nRetCode == SQL_ERROR && m_bInTransaction )
 
330
        RollbackTransaction();
 
331
 
224
332
    return TRUE;
225
333
}
226
334
 
260
368
        return FALSE;
261
369
    }
262
370
 
263
 
    SQLSetConnectOption( m_hDBC,SQL_LOGIN_TIMEOUT,5 );
 
371
    SQLSetConnectOption( m_hDBC,SQL_LOGIN_TIMEOUT,30 );
264
372
 
265
373
    if( pszUserid == NULL )
266
374
        pszUserid = "";
402
510
        Append( pszStatement );
403
511
    }
404
512
 
 
513
#if (ODBCVER >= 0x0300)
 
514
 
 
515
    if ( !m_poSession->IsInTransaction() )
 
516
    {
 
517
        /* commit pending transactions and set to autocommit mode*/
 
518
        m_poSession->ClearTransaction();
 
519
    }
 
520
 
 
521
#endif
 
522
 
405
523
    if( Failed( 
406
524
            SQLExecDirect( m_hStmt, (SQLCHAR *) m_pszStatement, SQL_NTS ) ) )
407
525
        return FALSE;
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
 
873
 
751
874
            }
752
875
                        
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;
757
881
 
758
882
            while( TRUE )
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
784
913
                }
785
914
                else
786
915
                    nChunkLen = cbDataLen;
1137
1266
void CPLODBCStatement::Clear()
1138
1267
 
1139
1268
{
 
1269
    /* Closing the cursor if opened */
 
1270
    if( m_hStmt != NULL )
 
1271
        SQLFreeStmt( m_hStmt, SQL_CLOSE );
 
1272
    
1140
1273
    ClearColumnData();
1141
1274
 
1142
1275
    if( m_pszStatement != NULL )
1148
1281
    m_nStatementLen = 0;
1149
1282
    m_nStatementMax = 0;
1150
1283
 
 
1284
    m_nColCount = 0;
 
1285
 
1151
1286
    if( m_papszColNames )
1152
1287
    {
1153
1288
        CPLFree( m_panColType );
1213
1348
    if( pszSchema == NULL )
1214
1349
        pszSchema = "";
1215
1350
#endif
 
1351
 
 
1352
#if (ODBCVER >= 0x0300)
 
1353
 
 
1354
    if ( !m_poSession->IsInTransaction() )
 
1355
    {
 
1356
        /* commit pending transactions and set to autocommit mode*/
 
1357
        m_poSession->ClearTransaction();
 
1358
    }
 
1359
 
 
1360
#endif
1216
1361
/* -------------------------------------------------------------------- */
1217
1362
/*      Fetch columns resultset for this table.                         */
1218
1363
/* -------------------------------------------------------------------- */
1332
1477
    if( pszSchema == NULL )
1333
1478
        pszSchema = "";
1334
1479
 
 
1480
#if (ODBCVER >= 0x0300)
 
1481
 
 
1482
    if ( !m_poSession->IsInTransaction() )
 
1483
    {
 
1484
        /* commit pending transactions and set to autocommit mode*/
 
1485
        m_poSession->ClearTransaction();
 
1486
    }
 
1487
 
 
1488
#endif
 
1489
 
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 );
1374
1529
 
 
1530
#if (ODBCVER >= 0x0300)
 
1531
 
 
1532
    if ( !m_poSession->IsInTransaction() )
 
1533
    {
 
1534
        /* commit pending transactions and set to autocommit mode*/
 
1535
        m_poSession->ClearTransaction();
 
1536
    }
 
1537
 
 
1538
#endif
 
1539
 
1375
1540
/* -------------------------------------------------------------------- */
1376
1541
/*      Fetch columns resultset for this table.                         */
1377
1542
/* -------------------------------------------------------------------- */