Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem with view of free table
Message
De
30/05/2002 08:56:02
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
29/05/2002 17:58:06
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00662770
Message ID:
00662931
Vues:
13
Thanks for your kindness David,
There are a multiple number of ways to approach it. Possibly listing a trick last :)
-One might be set path but you'd never be sure if another path is also set to a table with same name. It'd be tedious to check.
-You could make the view store path too. However it posses the problem you'd have troubles changing that on fly. But if you want to know how to do it, wait it's also same way on the following.
-You could create a new 'temp' database and view on the fly, drop view and remove database when done. This one really quite easy and no noticable performance loss. Basically looks like :

oApp.TempDBC = sys(2015)
create database (oApp.TempDBC)
create SQL view myView as select ... from (FullPathHere) ....
*Set view properties
*Possibly this would be a class creating the view
do form FormUsingTheView
*Form might drop the view and dbc in destroy

This one is somewhat tedious but works and was my key to modifying remote view conection servers in previous VFP versions. Or at least do not think of this one because when I first suggested a thing similar to this in newsgroups I got a reply similar to "Oh good you didn't want her to tie her shoes while pouring coffee with her right toe, ...." :) At least I remember I liked the idiom :)

-There are more in between maybe but enough I think to say the last one for now.
Use parameterized view :) This is not documented AFAIK but parameter also works in path :)
create sql view "v_ordrfile" as ;
   select .... ;
       from (?m.lcFreeTable) ;
   ....
Now how would you that.
1) First create a your view with view designer providing the path when designer asks as usual. Set your update criterias etc. We're using designer here for it writes many code for us.
2) Close designer and DBC.
do home()+'tools\gendbc\gendbc'
and point to your DBC get programmatic version of creating DBC and its tables. Your DBC should be open now, if not set database to your DBC.
3) Modify generated DBC. Locate code that creates your view (should be FUNCTION MakeView_v_ordrfile).
You'd see very near to top of function :
CREATE SQL VIEW "v_ordrfile" ; 
   AS select ... from YourFreeTableName ....

*Change to
m.lcFreeTable = "c:\myPath is here\myTableName.dbf"
DROP VIEW "v_ordrfile"
CREATE SQL VIEW "v_ordrfile" ; 
   AS select ... from (?m.lcFreeTable) ....

* Or do this to make it unopenable by view designer and not screwed
* This works with current versions - no guarantee for Toledo
* 'force' clause added
CREATE SQL VIEW "v_ordrfile" ; 
   AS select ... from force (?m.lcFreeTable) ....
BTW before I forget (?m.lcFreeTable) might be different depending on your needs. Say your table name is always 'MyTable.dbf' and you only want to change path, this is legal too :
m.lcPath = getdir() && or addbs(fullpath(SomePath))
(?m.lcPath+"MyTable")

4) Select the function body code, right click and execute. If you want save the modified code for future reference. You're done.

Test :
Close all
Clear all
open data yourDBC
m.lcFreeTable = < setthisone >
use v_ordrfile
*If you want check Tables, SQL etc props with dbgetprop()
browse
*etc tests
use
m.lcFreeTable = < setthisone2newpath >
use v_ordrfile
*check again

Cetin





>Cetin,
>
>Hi. How are you? I posted a thread to 'ALL',but I am sending you a direct message here as well, in the hope that you can help me. I don't mean to impose, in the event that you are very busy - so do not feel obligated to reply. In the past, you have been very helpful to me, and also, I saw some other threads where it was obvious that your knowledge in this area was excellent.
>
>Anyway my problem is as follows:
>
>
>I created a view, v_ordrfile, based upon a free table, ordrfile. I used the 'other' button in the view editor dialog box to specify the table and path. BTW, the ordrfile table is not in the same folder as my dbc.
>
>Immediately after I created the view, I issued the command 'use v_ordrfile' from the command window. The view opened up. The I did some other operations (not sure what). Then I attempted the same command, 'use v_ordrfile'. However, this time, a dialog box came up, with a list of tables in the dbc, and an 'other' button. I chose the other button, and it let me choose my free table again. Thereafter, when I issued 'use v_ordrfile', I did not get the dialog box again.
>
>It seems as if VFP was confused (or at least I am confused!) about what the path is to the free table. What property of dbgetprop()/setprop(), or cursorgetprop()/setprop() ?? can be queried/set regarding the path.
>
>?dbgetprop('v_ordrfile','view','tables') returns 'ordrfile' with no path.
>
>?dbgetprop('v_ordrfile','view','sql') returns a sql statement that has no path specified in the from clause, it is just 'from ordrfile'.
>
>?cursorgetprop('sourcename','v_ordrfile') returns 'v_ordrfile'
>
>I would think based upon the vfp help, that sourcename would have the full path to the table, but it doesn't.
>
>The vfp help for cursorgetprop says:
>
>Database C The name of the database in which the table or view is contained. If a table is a free table, contains the empty string.
>Read-Only.
>
>SourceName C Contains the long name for a SQL view or a table in a database, or the file path and table name for a free table.
>Read-Only.
>
>I am building this view in a test environment. I need to be able to change the path to the free table at runtime.
>
>TIA
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform