Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Morning.... I am having probs wi

Status
Not open for further replies.

AndyFutureRoute

Programmer
Dec 5, 2002
7
GB
Morning....

I am having probs with a chunk of my code, its causing a segmentation fault when i try and execute an SQL command that i have bound paremeters too, I was wondering if anyone could pot an obvious mistake for me?!

for(unsigned int i = 0; i < rowNum.size(); i++){
SQLAllocHandle( SQL_HANDLE_STMT, hDbc ,&hStmt);
SQLPrepare(hStmt,(SQLCHAR*)&quot;DELETE FROM [character] WHERE characterID = ?&quot;, SQL_NTS);

int val = rowNum;
cout << &quot;Bind Vector Contents &quot; << i << &quot; &quot;<< rowNum << &quot; &quot; ;
ret = SQLBindParameter(hStmt, //StatementHandle
1, //ParameterNumber
SQL_PARAM_INPUT, //InputOutputType
SQL_INTEGER, //ValueType INput
SQL_INTEGER, //ParameterType Actual Table Type
0, //ColumnSize
NULL, //DecimalDigits
&val, //ParameterValuePtr
sizeof(val), //BufferLength
SQL_NTS); //StrLen_or_IndPtr
SQLError(ret);
ret = SQLExecute(hStmt);

cout << &quot;Delete OP &quot;; SQLError(ret);
if(ret == SQL_SUCCESS){
norecordsinserted--;
}
SQLFreeHandle( SQL_HANDLE_STMT, hStmt );

}





I am binding the value held in vector to the end of the delete statement, which should delete the appropriate record, i know that this vector hold the correct info, but when i execute the command it seg faults....


Any help?!?!?!.....

Cheers

Andy
 
Without examining your code I can tell you that segmentation faults usually occurr because you're trying to access something that doesn't yet exist - for example:

[tt]// declare some array
int myInts[10];

// initialize them all here

// this causes a segmentation fault....
int i = myInts[10];[/tt]

You can see above that the array only holds 10 values which are indexed 0 thru 9. Trying to access index 10 of the array will cause the segmentation fault.
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top