sqldata/sqlociapi.cpp
// Execute the statement and get scalar result
Execute the statement and get scalar result
Execute the statement and get scalar result
int SqlOciApi::ExecuteScalar(const char *query, int *result, size_t *time_spent)
{
	if(query == NULL || _ociHandleAlloc == NULL || _ociStmtPrepare == NULL || _ociDefineByPos == NULL ||
		_ociStmtExecute == NULL || _ociHandleFree == NULL)
		return -1;
	size_t start = GetTickCount();
	OCIStmt *stmtp;
	OCIDefine *defnpp;
	int q_result = 0;
	int rc = _ociHandleAlloc((dvoid*)_envhp, (dvoid**)&stmtp, OCI_HTYPE_STMT, 0, NULL);
	rc = _ociStmtPrepare(stmtp, _errhp, (text*)query, (ub4)strlen(query), OCI_NTV_SYNTAX, OCI_DEFAULT);
	rc = _ociDefineByPos(stmtp, &defnpp, _errhp, 1, &q_result, sizeof(int), SQLT_INT, NULL, NULL, NULL, OCI_DEFAULT);
	rc = _ociStmtExecute(_svchp, stmtp, _errhp, 1, 0, NULL, NULL, OCI_EXACT_FETCH);
	if(rc != 0)
		SetError();
	if(result)
		*result = q_result;
	_ociHandleFree(stmtp, OCI_HTYPE_STMT);
	if(time_spent != NULL)
		*time_spent = GetTickCount() - start;
	return rc;
}
int SqlOciApi :: ExecuteScalar ( const char * query , int * result , size_t * time_spent ) { if ( query == NULL || _ociHandleAlloc == NULL || _ociStmtPrepare == NULL || _ociDefineByPos == NULL || _ociStmtExecute == NULL || _ociHandleFree == NULL ) return -1 ; size_t start = GetTickCount ( ) ; OCIStmt * stmtp ; OCIDefine * defnpp ; int q_result = 0 ; int rc = _ociHandleAlloc ( ( dvoid * ) _envhp , ( dvoid * * ) & stmtp , OCI_HTYPE_STMT , 0 , NULL ) ; rc = _ociStmtPrepare ( stmtp , _errhp , ( text * ) query , ( ub4 ) strlen ( query ) , OCI_NTV_SYNTAX , OCI_DEFAULT ) ; rc = _ociDefineByPos ( stmtp , & defnpp , _errhp , 1 , & q_result , sizeof ( int ) , SQLT_INT , NULL , NULL , NULL , OCI_DEFAULT ) ; rc = _ociStmtExecute ( _svchp , stmtp , _errhp , 1 , 0 , NULL , NULL , OCI_EXACT_FETCH ) ; if ( rc != 0 ) SetError ( ) ; if ( result ) * result = q_result ; _ociHandleFree ( stmtp , OCI_HTYPE_STMT ) ; if ( time_spent != NULL ) * time_spent = GetTickCount ( ) - start ; return rc ; }
Execute the statement and get scalar result
Execute the statement and get scalar result
// Allocate a statement handle // Execute the statement // Set the query result