Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Process Database Tables as Collection Items?
Message
 
To
27/07/2015 17:46:18
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01622575
Message ID:
01622580
Views:
54
>>>I'd like to process all the tables of a VFP database, looking for column names that contain certain strings. Does an open database expose any collection properties/attributes? It would be nice to be able to do something like this:
>>>
>>>OPEN DATABASE MyDBC
>>>
>>>FOR EACH {table} IN MyDBC
>>>  ...
>>>
>>
>>Check adbObjects() function.
>
>OK, so no collection properties, ADBOBJECTS() is the best thing available.
>
>Code for those interested:
>
>CLEAR
>CLOSE DATABASES ALL
>
>OPEN DATABASE dat\data
>
>lnTableCount = ADBOBJECTS( laTables, "TABLE" )
>
>FOR lnIx1 = 1 TO lnTableCount STEP 1
>	lcTable = laTables[ lnIx1 ]
>	
>	USE ( lcTable )
>	
>	lnFieldCount = AFIELDS( laFields )
>	
>	FOR lnIx2 = 1 TO lnFieldCount STEP 1
>		lcFieldName = UPPER( laFields[ lnIx2, 1 ] )
>		
>		IF "REQUESTKEY" $ lcFieldName OR "REQFK" $ lcFieldName OR "RQFK" $ lcFieldName
>			? lcTable + "." + lcFieldName
>		
>		ENDIF
>	
>	ENDFOR
>	
>	USE
>
>ENDFOR
>
Not as elegant but an alternative:
USE dat\data.dbc SHARED
SCAN FOR objecttype = 'Field' AND ("REQUESTKEY" $ ObjectName OR "REQFK" $ ObjectName OR "RQFK" $ ObjectName)
* Your code here, should include the search for ObjectID = ParentID to get the table name
ENDSCAN
[Update]Or a select statement to get the field and the parent and then scan the resulting cursor[/Update]
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform