Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
The number in Replicate creates a problem
Message
De
04/04/2022 19:03:01
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Problèmes
Divers
Thread ID:
01684050
Message ID:
01684051
Vues:
63
>Hi,
>
>I am troubleshooting the following issue. And I can't figure out what causes it.
>
>A somewhat long SQL Select has the following segment:
>
>REPLICATE(' ',10-LEN(ALLTRIM(REFERENCE)))
>
>
>The purpose of the above is to create a string of entity codes (nbsp) equal to the number of spaces after some entry in a field. The field name is REFERENCE. It used to be up to 10 characters in length. And the user was able to enter only up to 10 characters. And the above code worked.
>Then I increased the length of the field to 15. But the entry in the field is still the same, less or equal to 10 characters.
>Now the above code does not work. The SQL Select returns the error:
>
>String is too long to fit.
>
>
>If I change the 10 in the above REPLICATE with 15, no error.
>
>REPLICATE(' ',15-LEN(ALLTRIM(REFERENCE)))
>
>
>I don't understand why? Since the entry in the REFERENCE field is still only up 10 characters, the code 10-LEN... should work. Unless I miss something obvious.

Definitely strange. Some ideas:

1. "Reference" sounds like a VFP reserved word, can you test with some other name for that field?
2. Can you apply an alias for it i.e. LEN( ALLTRIM( SomeAlias.Reference ) )
3. Could you use something like PADR( ) to simplify your code or work around this issue?

Another thing to be wary of is if you're specifying a variable-length output column in a VFP SELECT, the length of that column in the final output will be determined by the length of the result of that expression the first time it gets evaluated. This is a guess, but if the first evaluated length is shorter than the result of later evaluations, then maybe VFP is trying to cram 10 pounds of characters into a 5 pound sack so it throws the error you're seeing.

The only safe way I know to avoid this kind of issue is to avoid variable-length expressions in output columns i.e. always CAST( ), PADR( ) them (or similar) to some fixed length.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform