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:
01410925
Vues:
47
This message has been marked as a message which has helped to the initial question of the thread.
>>>>>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.

No, the problem is that you have RECORD in the CA and it execute UPDATE not INSERT:
That works for me (w/o very hard testing):
CLEAR
CLOSE DATABASES ALL
SET ASSERTS ON

getOptionID = 1
getMakeID   = 22
getModelIDs = [_1_2_3]
oCa = CREATEOBJECT([cadealeropts])
IF oCa.CursorFill()
   BROWSE NORMAL
   IF NOT TABLEUPDATE(1, .t., oCa.Alias)
      AERROR(aaaa)
      CLEAR
      DISPLAY MEMORY LIKE aaaa
   ENDIF

ELSE
   AERROR(aaaa)
   CLEAR
   DISPLAY MEMORY LIKE aaaa
ENDIF




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"
       Flags              = 0
       CompareMemo        = .T.
       FetchMemo          = .F.
       SendUpdates        = .T.
       KeyFieldList       = "OPTSID"
       Tables             = "DealerOpts"
       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 Init
        set multilocks on
        llReturn = dodefault()
    ENDPROC
    
    PROCEDURE BeforeUpdate(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, cType, 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
    ENDPROC
ENDDEFINE
Just changed BeforeUpdate event.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform