@@ -102,7 +102,12 @@ static int GetSQLCType(int type)
102
102
case TYPE_BIGINT: tp = SQL_C_SBIGINT; break ;
103
103
case TYPE_DOUBLE: tp = SQL_C_DOUBLE; break ;
104
104
case TYPE_TINY : tp = SQL_C_TINYINT; break ;
105
+ // #if (ODBCVER >= 0x0300)
106
+ // case TYPE_DECIM: tp = SQL_C_NUMERIC; break; (CRASH!!!)
107
+ // #else
105
108
case TYPE_DECIM: tp = SQL_C_CHAR; break ;
109
+ // #endif
110
+
106
111
} // endswitch type
107
112
108
113
return tp;
@@ -923,13 +928,13 @@ ODBConn::ODBConn(PGLOBAL g, TDBODBC *tdbp)
923
928
m_RowsetSize = (DWORD)((tdbp) ? tdbp->Rows : 10 );
924
929
m_Catver = (tdbp) ? tdbp->Catver : 0 ;
925
930
m_Rows = 0 ;
931
+ m_Fetch = 0 ;
926
932
m_Connect = NULL ;
927
933
m_User = NULL ;
928
934
m_Pwd = NULL ;
929
935
m_Updatable = true ;
930
936
m_Transact = false ;
931
937
m_Scrollable = (tdbp) ? tdbp->Scrollable : false ;
932
- m_First = true ;
933
938
m_Full = false ;
934
939
m_UseCnc = false ;
935
940
m_IDQuoteChar[0 ] = ' "' ;
@@ -984,7 +989,7 @@ void ODBConn::ThrowDBX(RETCODE rc, PSZ msg, HSTMT hstmt)
984
989
985
990
void ODBConn::ThrowDBX (PSZ msg)
986
991
{
987
- DBX* xp = new (m_G) DBX (0 , msg );
992
+ DBX* xp = new (m_G) DBX (0 , " Error " );
988
993
989
994
xp->m_ErrMsg [0 ] = msg;
990
995
throw xp;
@@ -1099,8 +1104,7 @@ int ODBConn::Open(PSZ ConnectString, POPARM sop, DWORD options)
1099
1104
// VerifyConnect(); Deprecated
1100
1105
GetConnectInfo ();
1101
1106
} catch (DBX *xp) {
1102
- // strcpy(g->Message, xp->m_ErrMsg[0]);
1103
- strcpy (g->Message , xp->GetErrorMessage (0 ));
1107
+ sprintf (g->Message , " %s: %s" , xp->m_Msg , xp->GetErrorMessage (0 ));
1104
1108
Close ();
1105
1109
// Free();
1106
1110
return -1 ;
@@ -1356,7 +1360,7 @@ int ODBConn::ExecDirectSQL(char *sql, ODBCCOL *tocols)
1356
1360
rc = SQLFreeStmt (m_hstmt, SQL_CLOSE);
1357
1361
1358
1362
if (!Check (rc))
1359
- ThrowDBX (rc, " SQLFreeStmt" );
1363
+ ThrowDBX (rc, " SQLFreeStmt" , m_hstmt );
1360
1364
1361
1365
m_hstmt = NULL ;
1362
1366
} // endif m_hstmt
@@ -1371,7 +1375,7 @@ int ODBConn::ExecDirectSQL(char *sql, ODBCCOL *tocols)
1371
1375
(void *)SQL_SCROLLABLE, 0 );
1372
1376
1373
1377
if (!Check (rc))
1374
- ThrowDBX (rc, " SQLSetStmtAttr " );
1378
+ ThrowDBX (rc, " Scrollable " , hstmt );
1375
1379
1376
1380
} // endif m_Scrollable
1377
1381
@@ -1422,7 +1426,7 @@ int ODBConn::ExecDirectSQL(char *sql, ODBCCOL *tocols)
1422
1426
1423
1427
for (n = 0 , colp = tocols; colp; colp = (PODBCCOL)colp->GetNext ())
1424
1428
if (!colp->IsSpecial ())
1425
- n++;
1429
+ n++;
1426
1430
1427
1431
// n can be 0 for query such as Select count(*) from table
1428
1432
if (n && n != (UWORD)ncol)
@@ -1458,7 +1462,7 @@ int ODBConn::ExecDirectSQL(char *sql, ODBCCOL *tocols)
1458
1462
for (int i = 0 ; i < MAX_NUM_OF_MSG && x->m_ErrMsg [i]; i++)
1459
1463
htrc (x->m_ErrMsg [i]);
1460
1464
1461
- strcpy (m_G->Message , x->GetErrorMessage (0 ));
1465
+ sprintf (m_G->Message , " %s: %s " , x-> m_Msg , x->GetErrorMessage (0 ));
1462
1466
1463
1467
if (b)
1464
1468
SQLCancel (hstmt);
@@ -1521,7 +1525,7 @@ int ODBConn::GetResultSize(char *sql, ODBCCOL *colp)
1521
1525
/* **********************************************************************/
1522
1526
/* Fetch next row. */
1523
1527
/* **********************************************************************/
1524
- int ODBConn::Fetch ()
1528
+ int ODBConn::Fetch (int pos )
1525
1529
{
1526
1530
ASSERT (m_hstmt);
1527
1531
int irc;
@@ -1531,7 +1535,9 @@ int ODBConn::Fetch()
1531
1535
1532
1536
try {
1533
1537
// do {
1534
- if (m_RowsetSize) {
1538
+ if (pos) {
1539
+ rc = SQLExtendedFetch (m_hstmt, SQL_FETCH_ABSOLUTE, pos, &crow, NULL );
1540
+ } else if (m_RowsetSize) {
1535
1541
rc = SQLExtendedFetch (m_hstmt, SQL_FETCH_NEXT, 1 , &crow, NULL );
1536
1542
} else {
1537
1543
rc = SQLFetch (m_hstmt);
@@ -1544,29 +1550,22 @@ int ODBConn::Fetch()
1544
1550
m_hstmt, m_RowsetSize, rc);
1545
1551
1546
1552
if (!Check (rc))
1547
- ThrowDBX (rc, " Fetch" , m_hstmt);
1548
-
1549
- irc = (rc == SQL_NO_DATA_FOUND) ? 0 : (int )crow;
1550
-
1551
- if (m_First) {
1552
- // First fetch. Check whether the full table was read
1553
- if ((m_Full = irc < (signed )m_RowsetSize)) {
1554
- m_Tdb->Memory = 0 ; // Not needed anymore
1555
- m_Rows = irc; // Table size
1556
- } // endif m_Full
1557
-
1558
- m_First = false ;
1559
- } // endif m_First
1553
+ ThrowDBX (rc, " Fetching" , m_hstmt);
1560
1554
1561
- if (m_Tdb->Memory == 1 )
1562
- m_Rows += irc;
1555
+ if (rc == SQL_NO_DATA_FOUND) {
1556
+ m_Full = (m_Fetch == 1 );
1557
+ irc = 0 ;
1558
+ } else
1559
+ irc = (int )crow;
1563
1560
1561
+ m_Fetch++;
1562
+ m_Rows += irc;
1564
1563
} catch (DBX *x) {
1565
1564
if (trace)
1566
1565
for (int i = 0 ; i < MAX_NUM_OF_MSG && x->m_ErrMsg [i]; i++)
1567
1566
htrc (x->m_ErrMsg [i]);
1568
1567
1569
- strcpy (g->Message , x->GetErrorMessage (0 ));
1568
+ sprintf (g->Message , " %s: %s " , x-> m_Msg , x->GetErrorMessage (0 ));
1570
1569
irc = -1 ;
1571
1570
} // end try/catch
1572
1571
@@ -1602,7 +1601,7 @@ int ODBConn::PrepareSQL(char *sql)
1602
1601
for (int i = 0 ; i < MAX_NUM_OF_MSG && x->m_ErrMsg [i]; i++)
1603
1602
htrc (x->m_ErrMsg [i]);
1604
1603
1605
- strcpy (g->Message , x->GetErrorMessage (0 ));
1604
+ sprintf (g->Message , " %s: %s " , x-> m_Msg , x->GetErrorMessage (0 ));
1606
1605
} // end try/catch
1607
1606
1608
1607
} // endif Mode
@@ -1648,7 +1647,7 @@ int ODBConn::PrepareSQL(char *sql)
1648
1647
for (int i = 0 ; i < MAX_NUM_OF_MSG && x->m_ErrMsg [i]; i++)
1649
1648
htrc (x->m_ErrMsg [i]);
1650
1649
1651
- strcpy (g->Message , x->GetErrorMessage (0 ));
1650
+ sprintf (g->Message , " %s: %s " , x-> m_Msg , x->GetErrorMessage (0 ));
1652
1651
1653
1652
if (b)
1654
1653
SQLCancel (hstmt);
@@ -1700,7 +1699,7 @@ int ODBConn::ExecuteSQL(void)
1700
1699
} // endif ncol
1701
1700
1702
1701
} catch (DBX *x) {
1703
- strcpy (m_G->Message , x->GetErrorMessage (0 ));
1702
+ sprintf (m_G->Message , " %s: %s " , x-> m_Msg , x->GetErrorMessage (0 ));
1704
1703
SQLCancel (m_hstmt);
1705
1704
rc = SQLFreeStmt (m_hstmt, SQL_DROP);
1706
1705
m_hstmt = NULL ;
@@ -1737,7 +1736,7 @@ bool ODBConn::BindParam(ODBCCOL *colp)
1737
1736
ThrowDBX (rc, " SQLDescribeParam" , m_hstmt);
1738
1737
1739
1738
} catch (DBX *x) {
1740
- strcpy (m_G->Message , x->GetErrorMessage (0 ));
1739
+ sprintf (m_G->Message , " %s: %s " , x-> m_Msg , x->GetErrorMessage (0 ));
1741
1740
colsize = colp->GetPrecision ();
1742
1741
sqlt = GetSQLType (buftype);
1743
1742
dec = IsTypeChar (buftype) ? 0 : colp->GetScale ();
@@ -1845,7 +1844,7 @@ bool ODBConn::ExecSQLcommand(char *sql)
1845
1844
for (int i = 0 ; i < MAX_NUM_OF_MSG && x->m_ErrMsg [i]; i++)
1846
1845
htrc (x->m_ErrMsg [i]);
1847
1846
1848
- sprintf (g->Message , " Remote: %s" , x->GetErrorMessage (0 ));
1847
+ sprintf (g->Message , " Remote %s : %s" , x-> m_Msg , x->GetErrorMessage (0 ));
1849
1848
1850
1849
if (b)
1851
1850
SQLCancel (hstmt);
@@ -1930,7 +1929,7 @@ PQRYRES ODBConn::GetMetaData(PGLOBAL g, char *dsn, char *src)
1930
1929
} // endfor i
1931
1930
1932
1931
} catch (DBX *x) {
1933
- strcpy (g->Message , x->GetErrorMessage (0 ));
1932
+ sprintf (g->Message , " %s: %s " , x-> m_Msg , x->GetErrorMessage (0 ));
1934
1933
goto err;
1935
1934
} // end try/catch
1936
1935
@@ -1981,7 +1980,7 @@ PQRYRES ODBConn::GetMetaData(PGLOBAL g, char *dsn, char *src)
1981
1980
} // endfor i
1982
1981
1983
1982
} catch (DBX *x) {
1984
- strcpy (g->Message , x->GetErrorMessage (0 ));
1983
+ sprintf (g->Message , " %s: %s " , x-> m_Msg , x->GetErrorMessage (0 ));
1985
1984
qrp = NULL ;
1986
1985
} // end try/catch
1987
1986
@@ -2033,7 +2032,7 @@ bool ODBConn::GetDataSources(PQRYRES qrp)
2033
2032
} // endfor i
2034
2033
2035
2034
} catch (DBX *x) {
2036
- strcpy (m_G->Message , x->GetErrorMessage (0 ));
2035
+ sprintf (m_G->Message , " %s: %s " , x-> m_Msg , x->GetErrorMessage (0 ));
2037
2036
rv = true ;
2038
2037
} // end try/catch
2039
2038
@@ -2084,7 +2083,7 @@ bool ODBConn::GetDrivers(PQRYRES qrp)
2084
2083
} // endfor n
2085
2084
2086
2085
} catch (DBX *x) {
2087
- strcpy (m_G->Message , x->GetErrorMessage (0 ));
2086
+ sprintf (m_G->Message , " %s: %s " , x-> m_Msg , x->GetErrorMessage (0 ));
2088
2087
rv = true ;
2089
2088
} // end try/catch
2090
2089
@@ -2402,7 +2401,7 @@ int ODBConn::GetCatInfo(CATPARM *cap)
2402
2401
for (int i = 0 ; i < MAX_NUM_OF_MSG && x->m_ErrMsg [i]; i++)
2403
2402
htrc (x->m_ErrMsg [i]);
2404
2403
2405
- strcpy (g->Message , x->GetErrorMessage (0 ));
2404
+ sprintf (g->Message , " %s: %s " , x-> m_Msg , x->GetErrorMessage (0 ));
2406
2405
irc = -1 ;
2407
2406
} // end try/catch
2408
2407
@@ -2506,7 +2505,7 @@ int ODBConn::Rewind(char *sql, ODBCCOL *tocols)
2506
2505
2507
2506
rbuf = (int )crow;
2508
2507
} catch (DBX *x) {
2509
- strcpy (m_G->Message , x->GetErrorMessage (0 ));
2508
+ sprintf (m_G->Message , " %s: %s " , x-> m_Msg , x->GetErrorMessage (0 ));
2510
2509
rbuf = -1 ;
2511
2510
} // end try/catch
2512
2511
0 commit comments