Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 DBC Questions ? 2

Status
Not open for further replies.

IForgot

Programmer
Mar 20, 2002
122
US
1. Is there a way to determine if a Database is Open?

I want to use:
SET DATABASE TO <DBCName>

But before doing that I want to test to ensure that the DBC is OPEN. If I attempt to execute the command and the DBC is not Open, an error is generated.

2. Is there a way to get a listing of the Tables/Views contained in an Open Database?

Your advice is greatly appreciated.

Thanks,
I_Forgot
 
1. You can OPEN the database without error even if it's already open.

2. Try DISPLAY TABLES

Jim
 
IForgot,

Try this:

nCountDBC = ADatabases(aDBC)
nCountTable = AUsed(aTable)
For x = 1 to nCountDBC
? aDBC[x, 1] && DBC name
?? ' (' + aDBC[x, 2] + ')' && DBC Fullname
For y = 1 to nCountTable
If inDBC(aTable[y, 1], 'TABLE')
? ' ' + aTable[x, 1], ' is in ', aDBC[y, 1]
endif
Next
Next


-- AirCon --
 
Sorry, there is a mistake with the code. Try this instead:

nCountDBC = ADatabases(aDBC)
nCountTable = AUsed(aTable)
For x = 1 to nCountDBC
? aDBC[x, 1] && DBC name
?? ' (' + aDBC[x, 2] + ')' && DBC Fullname
Set database to (aDBC[x, 1])

For y = 1 to nCountTable
If inDBC(aTable[y, 1], 'TABLE')
? ' ' + aTable[y, 1], ' is in ', aDBC[x, 1]
endif
Next
Next


Regards

-- AirCon --
 
A couple ways of doing it, each has its own advantages and pitfalls:

******************
*** First Example
******************
?DBAvailable(&quot;MyDBC&quot;)
FUNCTION DBAvailable(tcDBName)
*!* Uses Error Trapping
LOCAL lcErrorHandler, llOpen
llOpen = .T.
lcErrorHandler = ON(&quot;ERROR&quot;)
ON ERROR llOpen = .F.
SET DATABASE TO (tcDBName)
ON ERROR &lcErrorHandler
RETURN llOpen
ENDFUNC


******************
*** Second Example
******************
?DBAvailable(&quot;MyDBC&quot;)
FUNCTION DBAvailable(tcDBName)
*!* Uses ADatabases() function
LOCAL llOpen
ADatabases(aryDBC)
llOpen = ASCAN(aryDBC,tcDBName, 1, ALEN(aryDBC,1), 1, 1) > 0
RETURN llOpen
ENDFUNC


...using the function that utilizes error trapping you actually have to set the database in order to find out if it exists and this may not be the desired behavior.

...using the function that utilizes ADatabases() is perhaps a bit more resource intensive given that ADatabases() returns other information that the actual DBC names and there is also those other functions needed such as ASCAN() and ALEN(). However, this is the function I would use if I had to choose between the two.

Slighthaze = NULL
craig1442@mchsi.com
&quot;Whom computers would destroy, they must first drive mad.&quot; - Anon​
 
The ADATABASES() was the command I was looking for to identify if a DBC was currently OPEN. The routines worked well. Thanks.

I still, however, need to find a way to get a list/array of the Tables/Views contained in any currently selected Open Database.

The AUSED() command only displays TABLES in USE within one of the workspaces, not what is available to USE within a Database.

And the INDBC() command will check if a particular Table or View is in the DBC, but, again, it does not give me a listing of ALL that is available within the DBC.

What I am looking for something which works similar to:
=ADIR(aryDBF, &quot;C:\MyDBFs\*.DBF&quot;)
But which works for DBC's.

Your suggestions and advice are greatly appreciated.

Thanks,
I_Forgot
 
Try something like the following...you may have to modify it to suit your needs, it is at best a very rudimentary example to help you solve your problem.

Code:
ADATABASES(aryDBC)
FOR i = 1 TO ALEN(aryDBC,1)
	SELECT objectname FROM (aryDBC(i,2)) WHERE INLIST(objecttype, &quot;Table&quot;, &quot;View&quot;)
	USE IN SELECT(aryDBC(i,1))
ENDFOR

Slighthaze = NULL
craig1442@mchsi.com
&quot;Whom computers would destroy, they must first drive mad.&quot; - Anon​
 
Thanks Slighthaze You put me on the right track to my answer.

I ended up with the following:
SELECT DISTINCT objectname AS object ;
FROM (tcDBCName) ;
WHERE !DELETED() ;
AND INLIST(objecttype, &quot;Table&quot;, &quot;View&quot;) ;
AND parentid = 1;
NOCONSOLE;
INTO ARRAY aryTables

which will return the DBC's Table/View contents in the array.

Thanks,
I_Forgot
 
IForgot,

Sorry I misunderstood your question. Another way is to use ADBObjects() functions (but I think you prefer the SELECT command :) ).

Anyway here it is:

*----------------
nCountDBC = ADatabases(aDBC)
For x = 1 to nCountDBC
? aDBC[x, 1] && DBC name
?? ' (' + aDBC[x, 2] + ')' && DBC Fullname
Set database to (aDBC[x, 1])

nCountTables = ADBObjects(aTables, 'TABLE')
? 'Tables in ' + aDBC[x,1]
For y = 1 to nCountTables
? ' ' + aTables[y]
Next

nCountViews = ADBObjects(aViews, 'VIEW')
? 'Views in ' + aDBC[x,1]
For y = 1 to nCountViews
? ' ' + aViews[y]
Next
Next
*----------------

Regards

-- AirCon --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top