2010/12/30

Firebird C API - 질의문 수행 후 반영된 레코드 수 구하는 함수

struct AFFECTED_ROW
{
int Insert;
int Select;
int Update;
int Delete;

AFFECTED_ROW()
{
Init();
}

void Init()
{
Insert = 0;
Select = 0;
Update = 0;
Delete = 0;
}
};


void CTestEFBDlg::GetAffectedRow( isc_stmt_handle stmt, AFFECTED_ROW& affected )
{
static char const info_count[] = { isc_info_sql_records };
char result[64] = { 0, };
int ret = 0;

ISC_STATUS_ARRAY status;
ISC_LONG sqlcode;

affected.Init();

isc_dsql_sql_info( status, &stmt, sizeof(info_count), info_count, sizeof(result), result );

if ( status[ 0 ] == 1 && status[ 1 ] > 0 )
{
// Error occurred
sqlcode = isc_sqlcode( status );

char szMsg[512];
isc_sql_interprete( (short)sqlcode, szMsg, 512 );

CString strMsg;
strMsg.Format( _T("Fail to isc_dsql_sql_info : %d - %s"), sqlcode, CString( szMsg ) );
AppendResult( strMsg );
}
else
{
char* pCur = result;
int length;
if ( *pCur == isc_info_sql_records )
{
pCur++;
length = isc_vax_integer(pCur, 2);
pCur += 2;

while(*pCur != 1)
{
switch(*pCur)
{
case isc_info_req_select_count:
pCur++;
length = isc_vax_integer(pCur, 2);
pCur += 2;
affected.Select = isc_vax_integer(pCur, length);
pCur += length;
break;
case isc_info_req_insert_count:
pCur++;
length = isc_vax_integer(pCur, 2);
pCur += 2;
affected.Insert = isc_vax_integer(pCur, length);
pCur += length;
break;
case isc_info_req_update_count:
pCur++;
length = isc_vax_integer(pCur, 2);
pCur += 2;
affected.Update = isc_vax_integer(pCur, length);
pCur += length;
break;
case isc_info_req_delete_count:
pCur++;
length = isc_vax_integer(pCur, 2);
pCur += 2;
affected.Delete = isc_vax_integer(pCur, length);
pCur += length;
break;
default:
pCur++;
break;
}
}
}
}
}


GetAffectedRow( stmt, affected );

CString strMsg;
strMsg.Format( _T("%d Row(s) Updated"), affected.Update );
AfxMessageBox( strMsg );
<

Original Post : http://neodreamer-dev.tistory.com/481

No comments :

Post a Comment