This example creates a new Database object and opens it (thereby appending it to the Databases collection) in the default Workspace object. Then it enumerates all the collections contained by each Database object and the properties of the new Database object and closes the new Database. See the methods and properties listed in the Database summary topic for additional examples.
FUNCTION Start
LOCAL oEng AS DaodBEngine
LOCAL oDb AS DaoDatabase
LOCAL oWs AS DaoWorkspace
LOCAL iDb AS LONG
LOCAL cSysDb AS STRING
LOCAL oErr AS USUAL
BEGIN SEQUENCE
set color TO w+/B
cls
oEng := DaoDbEngine{}
// Read location of System.MDW from Registry
// and use it
cSysDb := DaoRegistrySystemDb()
IF ! Empty(cSysDb) .and. File(cSysDb)
oEng:SystemDb := cSysDb
ENDIF
oWs := oEng:Workspaces:[Item,1]
oDb := oWs:OpenDatabase("\VO2Jet\Northwind.mdb",NIL,NIL,NIL)
// Enumerate all open databases.
FOR iDb:= 1 TO oWs:Databases:Count
oDb := oWs:Databases:[Item,iDb]
? "Enumeration of Database: ", oDb:Name
// Enumerate containers.
? "Container: Name, Owner, # of Documents"
oDb:Containers:ForEach( {|oCont| QOut(PadR(oCont:Name,20),PadR(oCont:Owner,20),;
oCont:Documents:Count)})
wait
// Enumerate querydefs
? "QueryDef: Name,Type"
oDb:QueryDefs:ForEach( {|oQd| QOut(PadR(oQd:Name,40),;
DaoQueryType(oQd:Type))})
wait
// Enumerate Recordsets.
// No output because no Recordset is open.
? "RecordSets: Name"
oDb:RecordSets:ForEach( {|oRs| QOut(oRs:Name)})
wait
// Enumerate relationships.
? "RecordSets: Name"
? "Relation: Name, Table, ForeignTable, Attributes"
oDb:Relations:ForEach( ;
{|oRel| QOut(PadR(oRel:Name,20),PadR(oRel:Table,15), PadR(oRel:ForeignTable,15), ;
DaoEnum2Str(oRel:Attributes, DaoRelationAttributeEnum(),TRUE))})
wait
// Enumerate table definitions.
? "TableDef: Name, DateCreated, # of Records, Attributes"
oDb:TableDefs:ForEach( {|oTd| QOut(PadR(oTd:Name,20), oTd:DateCreated, oTd:ReCordCount, ;
DaoEnum2Str(oTd:Attributes, DaoTableDefAttributeEnum(),TRUE))})
wait
// Enumerate built-in properties of database
? "odb:Name :" , oDb:Name
? "oDb:CollatingOrder :" , DaoEnum2Str(oDb:CollatingOrder, DaoCollatingOrderEnum(),FALSE)
? "oDb:Connect :" , oDb:Connect
? "oDb:QueryTimeout :" , oDb:QueryTimeout
? "oDb:Transactions :" , oDb:Transactions
? "oDb:Updatable :" , oDb:Updatable
? "oDb:Version :" , oDb:Version
NEXT
RECOVER USING oErr
Eval(ErrorBlock(),oErr)
END
oDb:Close()
Wait