Bonjour ;-)

Here is the Cach� part of that call:

ClassMethod GETSURVTUBES(ByRef resu As %String) [ SqlProc ]
{
 do ##class(BaseJour.BSC).GETSURVTUBES(.resu) //method that returns a result
in resu (by ref)
 Quit
}

We implemented a standardised portal for SQL Procs to interoperate with any
SQL client.
The benefit is that we call the method by reflection, allowing us to have
only one entry point for any Cach� method.
We use this code for Delphi as well as for .NET

/// Ex�cution d'une m�thode d'une classe
/// <ul><li><u>Arguments</u>:
/// <ul><li>cacheClass : nom du package . nom de la classe (exemple:
Roche.Test)
/// <li>cmd : nom de la m�thode (exemple: PING)
/// <li>msgIn : Tableau s�rialis� de paires cl�-valeurs des arguments
/// <li><u>Retour</u>:<ul>
/// <li>msgOut : Tableau s�rialis� de paires cl�-valeurs des donn�es en
retour, contenant
/// au minimum les cl�s ERROR_CODE et ERROR_DESC.<br>
/// Si une seule valeur est retourn�e, on la trouve dans la cl� RETURN.
/// <li>mise � jour du contexte de proc�dure stock�e SQLCODE (0: ok,
1:exception)
/// </ul>
/// </ul>
/// <b><u>Format des m�thodes interfa�ables:</u></b><br>
///
/// Exemple:<br>
/// ClassMethod PING(args,rets) As %String //signature standard<br>
/// ( args et rets sont pass�s par r�f�rence )<br>
/// {<br>
///  s rets("RETURN")="PONG" //on d�crit les paires cl�s-valeurs de
retour<br>
///  q "" //le code d'erreur renvoy� est vide, ce qui signifie: pas
d'erreur<br>
/// }<br>
ClassMethod CGExecuteCmd(cacheBSCClass, cmd, msgIn As %String(MAXLEN=65536),
Output msgOut As %String(MAXLEN=65536)) [ SqlProc ]
{
 //Cr�ation: 23/02/04 JMB
 s Z1=$ZH
 s cacheError=""  //erreur sous la forme code;description
 s rets=""    // tableau de retour
 s sqlErrorCode=0  //erreur SQL
 s $zt="CGEC"
 //d�s�rialisation des arguments et stockage dans un tableau temporaire
(variable multidemensionnelle)
 s i=1
 s s1=$P(msgIn,$C(31),1)
 while (s1'="")
 {
  s args($P(s1,$C(28),1))=$P(s1,$C(28),2)
  s i=i+1
  s s1=$P(msgIn,$C(31),i)
 }
 //appel de la m�thode
 //attention: il n'y a pas de v�rif si la m�thode existe, seulement le ztrap
 s cacheError=$zobjclassmethod(cacheBSCClass,cmd,.args,.rets)
CGEC2
 s $zt=""

 //on compile les infos d'erreur. Le s�rialisation est faite avec des
s�parateurs, ce qui implique de ne pas les avoir en valeur
 i (cacheError="") s cacheError="0;"
 s errorCode=$P(cacheError,";",1), errorDesc=$P(cacheError,";",2)
 s
msgOut="ERROR_CODE"_$C(28)_errorCode_$C(31)_"ERROR_DESC"_$C(28)_errorDesc_$C
(31)

 //on d�pile le tableau de retour pour l'ajouter � la chaine de retour
 s i=$O(rets(""))
 while (i'="")
 {
  s msgOut=msgOut_i_$C(28)_rets(i)_$C(31)
  s i=$O(rets(i))
 }
 if ($L(msgOut)>0) { s msgOut=$E(msgOut,1,$L(msgOut)-1) }

 if (errorCode<0) s sqlErrorCode=-460 // General error

 // Retour du %SQLProcContext
 If ($g(%sqlcontext)'=$$$NULLOREF)
 {
 // Set %sqlcontext.RowCount=1 pas besoin car on ex�cute une m�thode
     Set %sqlcontext.SQLCode=sqlErrorCode
     If (sqlErrorCode'=0)
     {
      // Si erreur ajouter un message d'information pour avoir ce message
dans l'exception
      Set %msg=cacheError
     }
 do ##class(UsrJournal.Log).FAppend("fin:"_(($ZH-Z1)*1000)_",
msgOut="_msgOut,"CG",9)
 q
CGEC
  do ##class(UsrJournal.Log).Append("Trap CG
Command","cacheBSCClass,cmd,msgIn",8,"CG")
  s cacheError=^CGErrorDefs(-100)
  goto CGEC2
 }
}

Contact me directly if you want more code pieces.

Have a nice week-end

JM

"Thierry" <[EMAIL PROTECTED]> a �crit dans le message de news:
[EMAIL PROTECTED]
> Hi Jean Marc
>
> Thanks for the code.
> Any chance to have the cach� code corresponding to that code ?
> GETPREFS in BSC.ValideMPL ?
>
> One more thanks
> Mer�i de l'info ;-)
>
> Thierry
>
> "BOUZARD Jean-Marc" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Hi,
> >
> > my colleague is on holiday, but I found something interesting he wrote
to
> > call stored procs with D5 and ODBC Express:
> >
> > function TFaccueil.AppelprocStockee(pnomproc, param1 : string) : String;
> > begin
> > with OEDataSet1 do begin
> >    Close;
> >    StoredProc := pnomproc;
> >    Params[0].AsString := param1;
> >    ExecSQL;
> >    Result := Params[0].AsString;
> >    Close;
> > end;
> > end;
> >
> > we assume that OEDataSet1 is of type TOEDataSet, and below you can find
> what
> > is in the dfm file:
> >   object OEDataSet1: TOEDataSet
> >     hDbc = Hdbc1
> >     hStmt.CursorType = 0
> >     hStmt.SkipByPosition = True
> >     hStmt.SkipByCursor = True
> >     hStmt.Target.Target = (
> >       'OE6.01'
> >       ''
> >       ''
> >       ''
> >       '')
> >     StoredProc = 'BSC.ValideMPL_GETPREFS'
> >     Params = <
> >       item
> >         DataType = ftString
> >         Name = 'prefs'
> >         ParamType = ptInputOutput
> >       end>
> >     Cached = True
> >     Left = 528
> >     Top = 104
> >   end
> >
> >
> > Hope this will help, regards,
> >
> > JM
> >
> > "DGS/DST/DTAD" <[EMAIL PROTECTED]> a �crit dans le message de news:
> > [EMAIL PROTECTED]
> > > Hello.
> > >
> > > I am using OdbcExpress with Delphi 5
> > >
> > > Does anybody has a sample on how to call a cach� stored procedure that
> > > return something ???
> > > Like SayHello("Hello") and return "World"
> > > How to declare the cach� mehod and parameters (byref, output,...) and
> how
> > to
> > > call it ?
> > > The most difficult part seams to be on the Delphi/OdbcExpress side
> > > Each time a try a new solution, I receive a Kernel exception, nothing
or
> > an
> > > internal error 460
> > >
> > > Thanks in advance
> > >
> > > Thierry
> > >
> > >
> >
> >
>
>



Reply via email to