Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
UDF function in SQL
Message
 
 
À
12/09/2004 16:09:13
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00941478
Message ID:
00941479
Vues:
8
This message has been marked as the solution to the initial question of the thread.
What error do you get? VFP calls UDF one extra time at the beginning to determine field size. It may use either the first record in the table or empty record. You shoud account for that in UDF code. Something like
DO CASE
CASE tnMonth = 0 OR tnYear=0 or tnPage = 0
   lcUrl=""
CASE (tnMonth>=10 AND tnYear=2003) OR tnYear>2003
   lcUrl=gcCgiMagazine+'9,7,3,'+gaMonth[tnMonth,1]+ALLTRIM(STR(tnYear))+'/Page'+ALLTRIM(STR(tnPage))+'.asp'
OTHERWISE
   lcUrl=gcClientMagazine+gaMonth[tnMonth,1]+ALLTRIM(STR(tnYear))+'/Page'+ALLTRIM(STR(tnPage))+'.asp'
ENDCASE
>I have this SQL which contains a UDF function:
>
>
>SELECT MagaSche.Numero,Title,Message AS Summary,;
> PADR(GetUrlArticleMagazine(MagaSche.Month,MagaSche.Year,MagaSche.Page),250) AS Url,;
> MagaSche.Year,MagaSche.Month,MagaSche.Page,MagaSche.Creation FROM MagaSche;
> WHERE MagaSche.Month=lnMonth AND MagaSche.Year=lnYear AND MagaSche.Statut=4;
> ORDER BY Page INTO CURSOR Temp
>
>
>The function is:
>
>
>* Return the URL for a magazine
>* expN1 Month
>* expN2 Year
>* expN3 Page
>FUNCTION GetURLArticleMagazine
>PARAMETERS tnMonth,tnYear,tnPage
>LOCAL lcUrl
>IF (tnMonth>=10 AND tnYear=2003) OR tnYear>2003
>   lcUrl=gcCgiMagazine+'9,7,3,'+gaMonth[tnMonth,1]+ALLTRIM(STR(tnYear))+'/Page'+ALLTRIM(STR(tnPage))+'.asp'
>   ELSE
>   lcUrl=gcClientMagazine+gaMonth[tnMonth,1]+ALLTRIM(STR(tnYear))+'/Page'+ALLTRIM(STR(tnPage))+'.asp'
>ENDIF
>RETURN lcUrl
>
>
>The SQL is defined so the IF condition will go in the first choice. This is for all records found for the SQL.
>
>However, this generates an error. In order for the code to execute successfully, I have to initialize lcURL to blank. So, this is the function I have presently:
>
>
>* Return the URL for a magazine
>* expN1 Month
>* expN2 Year
>* expN3 Page
>FUNCTION GetURLArticleMagazine
>PARAMETERS tnMonth,tnYear,tnPage
>LOCAL lcUrl
>lcUrl=''
>IF (tnMonth>=10 AND tnYear=2003) OR tnYear>2003
>   lcUrl=gcCgiMagazine+'9,7,3,'+gaMonth[tnMonth,1]+ALLTRIM(STR(tnYear))+'/Page'+ALLTRIM(STR(tnPage))+'.asp'
>   ELSE
>   lcUrl=gcClientMagazine+gaMonth[tnMonth,1]+ALLTRIM(STR(tnYear))+'/Page'+ALLTRIM(STR(tnPage))+'.asp'
>ENDIF
>RETURN lcUrl
>
>
>My question is why am I forced to initialize lcURL to blank in this case even if all the times the function will be called, the first selection will always be selected?
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform