If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > SQLBulkOperations

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-09-04, 10:25
sleepymish sleepymish is offline
Registered User
 
Join Date: Jan 2004
Posts: 7
SQLBulkOperations

Can anyone see the error in the following code? It compiles and executes, but all the data is misaligned when inserted in the database. Someone please help, I've been working on this for weeks! =(


********************** code *********************************

void cDatabase::BulkInsertData(dataStruct DS[], SQLINTEGER numInserts)
{
if(numInserts)
{
SQLRETURN rc;
SQLUSMALLINT RowStatusArray[numInserts];
SQLINTEGER bindOffset = 0;

// set statement attributes
SQLSetStmtAttr(m_hStmt, SQL_ATTR_CURSOR_TYPE,
(void*)SQL_CURSOR_KEYSET_DRIVEN, 0);
SQLSetStmtAttr(m_hStmt, SQL_ATTR_ROW_BIND_TYPE, (void*)sizeof(dataStruct),
0);
SQLSetStmtAttr(m_hStmt, SQL_ATTR_ROW_ARRAY_SIZE, (void*)numInserts, 0);
SQLSetStmtAttr(m_hStmt, SQL_ATTR_ROW_STATUS_PTR, (void*)RowStatusArray,
0);
SQLSetStmtAttr(m_hStmt, SQL_ATTR_ROW_BIND_OFFSET_PTR, (void*)bindOffset,
0);

// execute a statement to retrieve rows from the table
rc=SQLExecDirect(m_hStmt, (SQLCHAR*) "SELECT * FROM data", SQL_NTS);
if(rc == SQL_ERROR)
printf("error\n");

// not working yet
SQLBindCol(m_hStmt, 1, SQL_C_SLONG, &DS[0].FrameID, 0, &DS[0].FrameIDLen);
SQLBindCol(m_hStmt, 2, SQL_C_CHAR, NULL, 0, 0);
SQLBindCol(m_hStmt, 3, SQL_C_UTINYINT, &DS[0].SubCode, 0,
&DS[0].SubCodeLen);
SQLBindCol(m_hStmt, 4, SQL_C_USHORT, &DS[0].Data, 0, &DS[0].DataLen);


rc = SQLBulkOperations(m_hStmt, SQL_ADD);
if(rc == SQL_ERROR)
{
printf("data insert error\n");
PrintError();
}
else if(rc == SQL_SUCCESS)
{
printf("data insert successful\n");
}
printf("after\n");
for(int j=0; j<numInserts;j++)
printf("%d, ", RowStatusArray[j]);
printf("\n");

// reset
SQLSetStmtAttr(m_hStmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)0, 0);
}
}

********************** code *********************************
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On