Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
View with left join
Message
De
21/02/2002 18:30:33
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00623185
Message ID:
00623486
Vues:
10
>Mark,
>
>>Yeah, I am familiar with View Designer limits (bugs?). My table structures (really for testing only) are here:
>>Table1
>>Id - Integer
>>Desc – C (10)
>>
>>Table2
>>Id - Integer
>>Desc – C (10)
>>
>>Table3
>>Id - Integer
>>Desc – C (10)
>>
>>Data:
>>Table1
>>1 House
>>Table2
>>1 Red
>>Table3
>>1 Pool
>>
>>What I want is when there is data in Table3 then changes are going to that record(s), if there is no data then a new record(s) is appended into table3.
>
>Does Table 3 depend on one of the other 2, i.e. is it a child table? I don't think you can make a view smart enough to insert a parent record and then a child.
>
>If you just want table 3 to be updateable after your view is instantiated, just include table 3 in your DBSETPROPS() statements when you create your view. Make table 3 the Updateable table and use it's key field as the key view update fields. Be warned, multi-table updateable joins can be hard to get setup, even if you are only wanting to write back to one table. It becomes especially difficult if the tables have foreign keys to each other. If the tables are linked just to add supplementary data to a main data table, you should be able to have the main table be updateable.
>
>For example, the following parameterized view creation (with subsequent DBSETPROP() calls) gets data from two tables but only updates the child table:
>
>
>	CREATE VIEW (lcViewName) AS ;
>		SELECT subagent.*, agent.agentID, agent.agentnum, agent.name ;
>		FROM pcagent!subagent, pcagent!agent ;
>		WHERE subagent.masterID == ?vpAgentID ;
>		AND subagent.subID == agent.agentID
>	* Set properties for this view
>	DBSETPROP(lcViewName, 'View', 'SendUpdates', .T.)
>	DBSETPROP(lcViewName, 'View', 'Tables', 'SUBAGENT')
>	* Set properties for the fields in the view (for updating the SUBAGENT table)
>	DBSETPROP(lcViewName + '.subagentID', 'Field', 'KeyField', .T.)
>	DBSETPROP(lcViewName + '.subagentID', 'Field', 'Updatable', .T.)
>	DBSETPROP(lcViewName + '.subagentID', 'Field', 'UpdateName', 'SUBAGENT.subagentID')
>	DBSETPROP(lcViewName + '.subagentID', 'Field', 'DataType', "C(15)")
>	DBSETPROP(lcViewName + '.masterID', 'Field', 'KeyField', .F.)
>	DBSETPROP(lcViewName + '.masterID', 'Field', 'Updatable', .T.)
>	DBSETPROP(lcViewName + '.masterID', 'Field', 'UpdateName', 'SUBAGENT.masterID')
>	DBSETPROP(lcViewName + '.masterID', 'Field', 'DataType', "C(15)")
>	DBSETPROP(lcViewName + '.subID', 'Field', 'KeyField', .F.)
>	DBSETPROP(lcViewName + '.subID', 'Field', 'Updatable', .T.)
>	DBSETPROP(lcViewName + '.subID', 'Field', 'UpdateName', 'SUBAGENT.subID')
>	DBSETPROP(lcViewName + '.subID', 'Field', 'DataType', "C(15)")
>	DBSETPROP(lcViewName + '.sdate', 'Field', 'KeyField', .F.)
>	DBSETPROP(lcViewName + '.sdate', 'Field', 'Updatable', .T.)
>	DBSETPROP(lcViewName + '.sdate', 'Field', 'UpdateName', 'SUBAGENT.sdate')
>	DBSETPROP(lcViewName + '.sdate', 'Field', 'DataType', "D")
>	DBSETPROP(lcViewName + '.edate', 'Field', 'KeyField', .F.)
>	DBSETPROP(lcViewName + '.edate', 'Field', 'Updatable', .T.)
>	DBSETPROP(lcViewName + '.edate', 'Field', 'UpdateName', 'SUBAGENT.edate')
>	DBSETPROP(lcViewName + '.edate', 'Field', 'DataType', "D")
>
>
>The SUBAGENT table is the updateable one even though data was also brought in from the parent AGENT table. If a record is added to the SUBAGENT table, you would have to fill in the masterID field (key that points back to parent) with ann appropriate parent key otherwise you would be making an orphan. I don't know how to make the view automatically create a parent, though maybe some DBC triggers could help? Such things usually got complicated enough for me that I end up opening two views, one for parent and one for child and I manually add records where needed...
>
>Anyway, hope this helps...views can be trying, but once you have a framework going they can be sort of nice -- even intuitive!
>
>JoeK

This is not what I am asking. My question is a LEFT JOIN and updates.

Mark
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform