Not having done a lot of 4D programming before Active4D, I don't have a lot of experience with 4D's record locking mechanism. I've been using Active4D's unlockAndLoad library method exclusively (as apposed to none as I started out!), but I'm not sure how to use it in a UpdateOrCreateFoo($bar) type method.

The method would create a new record or update an existing record in table [foo] based on info in $bar.

I'm not sure if unlockAndLoad handles new records. For instance would the below work?


query([foo];[foo]id = $bar{"id"})
if(records in selection([foo]) # 1)
        create record([foo])   // trigger assign id
end if
if (a4d.utils.unlockAndLoad(->[foo]))
        [foo]ccc := $bar{"ccc"}
        ...
        save and unload record
else
        handle error
end if

Not being sure that it would, I added a save record in the create block and that does work.

But now I want to call several UpdateOrCreate type methods to create a set of records and wrap them in a transaction. I understand that in a transaction, real records are not created (or have temp record numbers) until the transaction is committed. Would unlockAndLoad in the called methods handle this? (with or without the save record in create?)

start transaction
$err := ""

if ($err = "")
        $err += updateOrCreateFoo1($bar)
end if
if ($err = "")
        $err += updateOrCreateFoo2($bar)
end if

if ($err = "")
        validate transaction
else
        cancel transaction
        handle error
end if

I guess it boils down to one question:

Does utils.unlockAndLoad handle new records?

If it doesn't, what is the preferred 4D technique.


Steve Alex
AIDT
_______________________________________________
Active4D-dev mailing list
[email protected]
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/

Reply via email to