ODBC Problem with SQLBulkOperations(hstmt, SQL_ADD) 
Author Message
 ODBC Problem with SQLBulkOperations(hstmt, SQL_ADD)

The following function tries to insert 5 values in a Table named "Test". It
has 2 Columns: "Col1" of type interger and "Col2" of type char(8). The
RowSetSize is 3. So at the 2nd insertion only 2 out of 3 RowSet-Entries will
be valid.
The function works fine if i set  "nRowSize2 = 1;" in the else-Block. I
found sample code in the docs for SQL_BIND_BY_ROW but what do i do in the
case of SQL_BIND_BY_COLUMN ? Please help.

I am using Sybase Adaptive Server 6.0.

Any hints are apprectiated.

Dieter Ruscha

// -------------------------------------------------------------------------
----
Error-Handling removed
void odbcbulkinsert()
{
 SQLHENV  henv;
 SQLHDBC  hdbc;
 SQLHSTMT hstmt; // Braucht jede Tabelle selber, da hierdran die Spalten
gebunden werden.
 // Load the Driver Manager and allocate the environment handle
 SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
 // Registers the version of ODBC
 SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
 // Allocate a connection handle
 SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
 // So wird direkt commited
 SQLSetConnectOption(hdbc, SQL_AUTOCOMMIT, 0);
 // Connect to the data source
 SQLConnect(
  hdbc,
  (SQLTCHAR*) "D_SERIVCETOOL", SQL_NTS,
  (SQLCHAR*) "dba", SQL_NTS,
  (SQLCHAR*) "sql", SQL_NTS
  );

 // Initialize the Statem
 SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
 const SQLUINTEGER nRowSize = 3;
    SQLINTEGER iCol1[nRowSize];
    SQLINTEGER cbCol1[nRowSize] = {sizeof(SQLINTEGER), sizeof(SQLINTEGER),
sizeof(SQLINTEGER)};
 SQLCHAR* szCol2 = (SQLCHAR*)(new SQLCHAR[nRowSize][8+1]);

    SQLINTEGER cbCol2[nRowSize]  = {SQL_NTS, SQL_NTS, SQL_NTS};

 SQLSetStmtAttr(hstmt, SQL_ATTR_CONCURRENCY, (void*)SQL_CONCUR_LOCK ,0);
 SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_BIND_TYPE, SQL_BIND_BY_COLUMN, 0);

 SQLCHAR szQuery[] = "Select * from Test";
 SQLExecDirect(hstmt, szQuery, SQL_NTS);
 SQLBindCol(hstmt, 1, SQL_C_SLONG, iCol1, 0,   cbCol1);
 SQLBindCol(hstmt, 2, SQL_C_CHAR,  szCol2,  8+1, cbCol2);

 SQLRETURN sqlReturn = SQLFetch(hstmt);

 for (int i = 0; i < 2; ++i)
 {
  int nRowSize2 = 0;
  if (i == 0)
  {
   iCol1[0] = 0;
   iCol1[1] = 1;
   iCol1[2] = 2;
   _tcsncpy((TCHAR*)&szCol2[0*(8+1)], _T("bus"), 8+1);
   _tcsncpy((TCHAR*)&szCol2[1*(8+1)], _T("car"), 8+1);
   _tcsncpy((TCHAR*)&szCol2[2*(8+1)], _T("plane"), 8+1);
   nRowSize2 = 3;
  }
  else if (i == 1)
  {
   iCol1[0] = 4;
   iCol1[1] = 5;
   iCol1[2] = 6;
   _tcsncpy((TCHAR*)&szCol2[0*(8+1)], _T("horse"), 8+1);
   _tcsncpy((TCHAR*)&szCol2[1*(8+1)], _T("dog"), 8+1);
   _tcsncpy((TCHAR*)&szCol2[2*(8+1)], _T("cat"), 8+1);
   nRowSize2 = 2; // Everythink works fine, if i set nRowSize to 1
  }
  SQLSetStmtAttr(hstmt, SQL_ATTR_ROW_ARRAY_SIZE, (void*)nRowSize2, 0);
  sqlReturn = SQLBulkOperations(hstmt, SQL_ADD);
  CheckError(sqlReturn, hstmt);
// if nRowSize is 2, my function CheckError Reports the following
Error-Message:
// Restricted attribute datatype violation: cannot convert dog to an int
// ErrorCode  07006
 }

    SQLTransact(henv, hdbc, SQL_COMMIT);
 SQLFreeStmt(hstmt, SQL_CLOSE);
 SQLDisconnect(hdbc);
 SQLFreeConnect(hdbc);
 SQLFreeEnv(henv);
 delete [] szCol2;

Quote:
}



Tue, 27 Aug 2002 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. ODBC SDK SQLBulkOperations

2. hstmt busy error

3. HSTMT bindings may not be changed

4. How to tell hstmt is busy

5. Connection is busy with results from another hstmt

6. Microsoft.Data.Odbc.dll causes System.dll problem

7. Firebird and Odbc - invalid cast problem

8. ODBC API problem

9. Problem with ODBC (In VC++)

10. Problems with Mysql + ODBC driver with IDataReader

11. ODBC Problems

12. Problem with ODBC

 

 
Powered by phpBB® Forum Software