Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Trying to come up with a view/CA model
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01410693
Message ID:
01410930
Vues:
43
>>>>>>How would I know these default commands? Check in run-time?
>>>>>
>>>>>You could check them in Before* methods (BeforeUpdate, BeforeInsert, BeforeDelete) Last parameter will contain the command.
>>>>
>>>>Can you please show some code I should try?
>>>
>>>Give me a minute. I just start testing it.
>>
>>See my other reply. My problem is that my ID field is NULL (because of the RIGHT JOIN). Apparently, this is not a correct approach - I need to separate between updating existing records and inserting new (that are not yet in my table).
>>
>>Let's think in this direction, please.
>
>O, BTW I was mistaken. You should remove OptsID not from UpdateNameList, but from UpdatableFieldList.
>Check the class defined in my previous reply :-)

Yes, that's I figured - here is my current class code:
DEFINE CLASS cadealeropts AS cursoradapter_


	SelectCmd = "select DealerOpts.OptsID, NVL(DealerOpts.OptionID,?getOptionID) as OptionID,  
NVL(DealerOpts.MakeID, ?getMakeID) as MakeID, Models.ModelID as ModelID, 
Models.MfgName, Models.Name as ModelName, Models.ModelNmbr as ModelNmbr,  Models.ModelYear as ModelYear, 
DealerOpts.Retail, DealerOpts.Cost, DealerOpts.Costline, DealerOpts.Type as cType, DealerOpts.StdOption from DealerOpts 
RIGHT JOIN Models ON DealerOpts.ModelID = Models.ModelID and 
DealerOpts.OptionID = ?getOptionID and DealerOpts.MakeID = ?getMakeID 
where cast(Models.ModelID as varchar(12)) $ (?getModelIDs)"

	CursorSchema = "OptsID I, OptionID I, MakeID I, ModelID I, 
MfgName C(40), ModelName C(65), ModelNmbr C(20), ModelYear C(40), 
Retail N(10, 2), Cost N(10, 2), Costline N(10, 2), cType C(12), StdOption L(1)"
	Alias = "curdealeropts"
	DataSourceType = "Native"
	InsertCmdDataSourceType = "Native"
	UpdateCmdDataSourceType = "Native"
	DeleteCmdDataSourceType = "Native"
	Flags = 0
	CompareMemo = .T.
	FetchMemo = .F.
	SendUpdates = .T.
	KeyFieldList = "OPTSID"
	Tables = "DealerOpts,Models"
	UpdatableFieldList = "OPTIONID, MAKEID, MODELID, RETAIL, COST, COSTLINE, CTYPE, STDOPTION"
	UpdateNameList = "OPTSID DealerOpts.OPTSID, OPTIONID DealerOpts.OPTIONID, 
MAKEID DealerOpts.MAKEID, MODELID DealerOpts.MODELID, RETAIL DealerOpts.RETAIL, 
COST DealerOpts.COST, COSTLINE DealerOpts.COSTLINE, CTYPE DealerOpts.Type, 
STDOPTION DealerOpts.STDOPTION"
	BreakOnError = .T.
	UseCursorSchema = .T.
	UseTransactions = .T.
	Name = "cadealeropts"


	PROCEDURE AutoOpen
		*** Setup code: DO NOT REMOVE
		if not pemstatus(This, '__VFPSetup', 5)
			This.AddProperty('__VFPSetup', 1)
			This.Init()
		endif
		*** End of Setup code: DO NOT REMOVE
	ENDPROC


	PROCEDURE Init
		*** Setup code: DO NOT REMOVE
		local llReturn
		do case
			case not pemstatus(This, '__VFPSetup', 5)
				This.AddProperty('__VFPSetup', 0)
			case This.__VFPSetup = 1
				This.__VFPSetup = 2
			case This.__VFPSetup = 2
				This.__VFPSetup = 0
				return
		endcase
		set multilocks on
		llReturn = dodefault()
		*** End of Setup code: DO NOT REMOVE
		*** Select connection code: DO NOT REMOVE

		local lcDBC
		lcDBC = 'MNA.DBC'
		if dbused(lcDBC)
			set database to (lcDBC)
		else
			open database (lcDBC)
		endif
		*** End of Select connection code: DO NOT REMOVE

		*** Setup code: DO NOT REMOVE
		if This.__VFPSetup = 1
			This.__VFPSetup = 2
		endif
		return llReturn
		*** End of Setup code: DO NOT REMOVE
	ENDPROC


	PROCEDURE BeforeUpdate
		LPARAMETERS cFldState, lForce, nUpdateType, cUpdateInsertCmd, cDeleteCmd
		IF ISNULL(EVALUATE(this.Alias +[.OPTSID]))
		           TEXT TO cUpdateInsertCmd NOSHOW TEXTMERGE PRETEXT 15
		                INSERT INTO DealerOpts (OptionID, MakeID, Retail, Cost, Costline, Type, StdOption, ModelID)
		                VALUES
		                (<<EVALUATE(this.Alias+[.OptionID])>>,
		                 <<EVALUATE(this.Alias+[.MakeID])>>,
		                 <<EVALUATE(this.Alias+[.Retail])>>,
		                 <<EVALUATE(this.Alias+[.Cost])>>,
		                 <<EVALUATE(this.Alias+[.Costline])>>,
		                 <<EVALUATE(this.Alias+[.cType])>>,
		                 <<EVALUATE(this.Alias+[.StdOption])>>,
		                 <<EVALUATE(this.Alias+[.ModelID])>>)
		           ENDTEXT
		ENDIF

		RETURN DODEFAULT(cFldState, lForce, nUpdateType, cUpdateInsertCmd, cDeleteCmd)
	ENDPROC


ENDDEFINE
*
*-- EndDefine: cadealeropts
**************************************************
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform