Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Ways to improve this function
Message
 
 
À
14/02/2006 15:02:44
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01096290
Message ID:
01096294
Vues:
18
Hi Renauld,

Your function seems to be missing TRY CATCH block to avoid failure cases. Also you don't have to macro expand tcTableName, you can use name expression, e.g. (tcTableName). Other than that it looks like it can do the job within its documented limits.

See this message for my function Re: ALTER TABLE delete DBF from disk Thread #1094908 Message #1095005

UPDATE. Since you're using VFP7 you may use ON ERROR command instead as in my function. But you should be cautious doing ALTER table command because it may fail.

>Is there any otherways I can improve this function? This just basically check a table with given parameters and fix it for you, well basic things that is. Similar functions/code that does more than this is highly appreciated.
>
>
>close all
>use customer excl
>&& This add a field called ALTADDR1
>fmodtable("ADD","CUSTOMER","ALTADDR1","C","100")
>&& This modify a field called ALTADDR2
>fmodtable("ALTER","CUSTOMER","ALTADDR2","C","200")
>&& This DROP a field called ALTADDR
>fmodtable("DROP","CUSTOMER","ALTADDR","C")
>
>
>
>*---------------------------------------------------------------
>*-- Generic table maintenance
>*-- Current limitations:
>*--
>*-- Parameters are as follow:
>*-- 	tcAction = ALTER;ADD;DROP
>*--		tcTableName, tcFieldName, tcFieldType
>*--		tcFieldLen1(for type C and N), tcFieldLen2(for type N)
>*--
>*--| Currently limited to type C,N,I,L,D
>*--|Alter command only works for type C & N
>*---------------------------------------------------------------
>
>FUNCTION fmodtable
>LPARAMETERS tcAction, tcTableName, tcFieldName, tcFieldType, tcFieldLen1, tcFieldLen2
>
>LOCAL lFlag, lcFieldStru
>
>lFlag = .F.
>lcFieldStru = ""
>	
>*-- Initialize table fields first
>DO CASE
> CASE tcFieldType == "C"
>  lcFieldStru = tcFieldType + "(" + tcFieldLen1 + ")"
> CASE tcFieldType == "N"
>  lcFieldStru = tcFieldType + "(" + tcFieldLen1 +","+ tcFieldLen2 + ")"
> CASE tcFieldType == "I" 		
>  lcFieldStru = tcFieldType
> CASE tcFieldType == "D" 		
>  lcFieldStru = tcFieldType
> CASE tcFieldType == "L"
>  lcFieldStru = tcFieldType
>
> RETURN lcFieldStru
>ENDCASE
>	
>	
>DO CASE
> CASE tcAction == "ADD"
>  SELECT &tcTableName
>   FOR I = 1 TO FCOUNT()
>    IF FIELD(I) == tcFieldName
>	lFlag= .T.
>	EXIT
>    ENDIF
>   ENDFOR
>
>   IF !lFlag
>    ALTER TABLE &tcTableName ADD COLUMN &tcFieldName &lcFieldStru
>   ENDIF
>
> CASE tcAction == "ALTER"
>  IF tcFieldType == "C" OR tcFieldType == "N"
>   IF FSIZE(tcFieldName) <> VAL(tcFieldLen1)
>    ALTER TABLE &tcTableName ALTER COLUMN &tcFieldName &lcFieldStru
>   ENDIF			
>  ENDIF
>		
>CASE tcAction == "DROP"
> ALTER Table &tcTableName Drop COLUMN &tcFieldName			
>
>ENDCASE
>
>ENDFUNC
>
>
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform