dvidal


hi,

I need some code that asks if there is a field in a fox table and if it isn't, it must add a field to the table.

Thanks,




Re: fox table question

dni


You may use afiels() function (or fldlist() for older vfp) to put in an array the filed list:

AFIELDS( ArrayName [, nWorkArea | cTableAlias ] )
http://msdn2.microsoft.com/en-us/library/aa977240(VS.71).aspx
then you may use ALTER TABLE (OR modi stru) to add fields:
https://msdn.microsoft.com/library/default.asp url=/library/en-us/fox7help/html/lngalter_table___sql.asp






Re: fox table question

Alex Feldstein

The easiest way is to check the size of the field (0 if it does not exist).

Open the table EXCLUSIVE

If Fsize("mycolumn") = 0
 Alter Table mytable add column mycolumn C(10)
EndIf

Conversely, if you want to delete it.

If Fsize("mycolumn") > 0
 Alter Table mytable drop column mycolumn
EndIf

 






Re: fox table question

Tamar E. Granor

If you go with FSIZE(), make sure you have SET COMPATIBLE OFF.

Tamar