Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
View simple problem
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00439246
Message ID:
00439359
Views:
21
Nadya,
I don't have any code for this (as I haven't had need to do this) but it seems to me that getting the tables would be accomplished by the following:

1. Get string from first occurrence of FROM.
2. Truncate the string from the first occurence of WHERE. Now you should have a string that contains a complete list of the tables (along with join conditions, etc.)

From there you will have to check whether the string has the key word JOIN in it. If it does, you have to parse out the first word after JOIN to get the table name. Once you have the joined tables, you have to parse the table string that occurs directly after the FROM. You need to see if a "," exists for multiple tables.

While I like this idea (and I may implement some day for other reasons), Dan came up with a much easier to implement suggestion. You still need a wrapper but the wrapper is on the front and back end of this. Use the AUSED() function to build an array before opening the view and after opening the view. You can parse the array to get the difference and that will be the tables the view uses. Store that information somewhere and use it when closing the view.

>>>Hi everybody,
>>>
>>>In my code (currently it's a program, lately I may make it to be a form's method) I open a view by use vAllStatConfigs in 0 nodata alias WorkConfig. Then I assign view parameter and requery(). In Data Session now there are 4 tables open: 3 tables, on which view is based and the view itself. My question is: how can I close these tables automatically? When I issue use in WorkConfig, all three underlying tables remain opened...
>>>
>>>Thanks in advance.
>>
>>Without writing a CloseView function, you can't. The function could parse the return value of Cursorgetprop("SQL",myView) to find the FROM clause and get the tables. Then it could issue a USE for the view as well as the tables.
>>
>>I recommend using the SQL property and not the Tables property because it is not inclusive. Tables only holds references to updateable tables and the view could include any number of no-updateable ones.
>>
>>Other than that, you need to remember to close them when you close the form. Are they causing a problem for you or are you just trying to clean up after yourself? Because the tables will close when the datasession they are opened in goes away.
>
>Hi Larry,
>
>I can not find a way to parse this SQL and retrieve table names. Could you please help me, if you have this code already written?
>
>SELECT Statconfigs.*, Statfields.*, Statfuncs.funcid, Statfuncs.funcname, Statfuncs.funcgroup, Statfuncs.funcdef FROM stats!statconfigs INNER JOIN stats!statfields LEFT OUTER JOIN stats!statfuncs ON Statfields.f_functionid = Statfuncs.funcid ON Statconfigs.configid = Statfields.configid WHERE UPPER(Statconfigs.configname) = UPPER(?lcConfigName) ORDER BY Statconfigs.configname, Statfields.fieldorder
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform