Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Ways to improve this function
Message
De
14/02/2006 15:02:44
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Ways to improve this function
Versions des environnements
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01096290
Message ID:
01096290
Vues:
61
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform