0
So habe ich das ganze bis jetzt geschafft.
Mein Problem ich kann keinen output Parameter angeben in die Prozedur und auch ausgeben als Datentyp
#include <stdafx.h>
#define XP_NOERROR 0
#define XP_ERROR 1
#define MAXCOLNAME 25
#define MAXNAME 25
#define MAXTEXT 255
#ifdef __cplusplus
extern "C" {
#endif
RETCODE __declspec(dllexport) xp_formel(SRV_PROC *srvproc);
#ifdef __cplusplus
}
#endif
RETCODE __declspec(dllexport) xp_formel(SRV_PROC *srvproc)
{
int a = 0;
int b = 0,zehler = 0;
int iLength,iType,iParamCount,i = 0;
CString szText,szTemp,sInt;
CString szOutBuffer = "";
//Get the number of parameters passed to the Extended stored procedure.
iParamCount=srv_rpcparams(srvproc);
if (iParamCount == -1)
{
return (XP_ERROR);
}
// Parse for all parameters that have been Passed
// Note SQL Extended stored procedure use start index 1 unlike 0 in C
// but quite like Basic
for (i = 1; i <= iParamCount; i++)
{
szText = _T("");
//Retrieve the data length of the Extended stored procedure call parameter.
iLength=srv_paramlen(srvproc,i);
//Retrieve the data type of the Extended stored procedure call parameter.
iType=srv_paramtype(srvproc,i);
if(iLength <= 0)
{
return (XP_ERROR);
}
else
{
switch(iType)
{
case SRVCHAR://character data type.
szText.Format("%s",(const char *) srv_paramdata (srvproc,i));
break;
case SRVVARCHAR://Variable-length character data type.
szText.Format("%s",(const char *) srv_paramdata (srvproc,i));
break;
case SRVINTN://tinyint, smallint, or int data type, null values allowed.
sInt.Format("%d",*((int*) srv_paramdata (srvproc,i)));
zehler ++;
if(zehler==1)
a = atoi(sInt);
if(zehler!=1)
b= atoi(sInt);
break;
//Handling for other data types
default:
a=b=0;
szText = "";
break;
}
}
}
iLength = szOutBuffer.GetLength();
char buffer[20];
long c = a+b;
szOutBuffer = _ltoa(c,buffer,10);
int status = srv_paramstatus(srvproc, i+1);
//Defines the column Output_Info and source and destination data types for a specific column in a row.
srv_describe(srvproc,1,"Output_Info",255,SRVVARCHAR,iLength,SRVVARCHAR,iLength,(void *)(szOutBuffer.GetBuffer( iLength )));
//Send the output result set to the SQL Server for viewing in clients like ISQLW
srv_sendrow(srvproc);
//Inform the Server that you are finsihed with the send
//else subsequent ODS calls will cause an Invalid Cursor State
//as it is still waiting for the information
srv_senddone(srvproc,SRV_DONE_FINAL,0,0);
szOutBuffer.ReleaseBuffer();
return XP_NOERROR ;
}